1 # -*- coding: utf-8 -*-
3 __revision__ = '$Id: $'
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 # You may use and distribute this software under the terms of the
22 # GNU General Public License, version 2 or later
24 from plugins.imp import ImportPlugin as IP
28 from xml.dom import minidom, Node
29 from lxml import etree
31 from shutil import rmtree
32 from tempfile import mkdtemp
35 log = logging.getLogger("Griffith")
38 See lib/plugins/imp/__init__.py for workflow how importer invokes methods from importer plugins
40 class ImportPlugin(IP):
41 description = 'Kodi/XBMC MovieDB importer'
42 author = 'Elan Ruusamäe'
43 email = 'glen@pld-linux.org'
45 file_filters = 'videodb.xml'
53 # used by get_movie_details method
54 # griffith field => kodi field
55 # griffith field is actual SQL column in 'movies' table
58 'o_title': 'originaltitle',
60 'runtime': 'runtime', # may need int cast
63 'director': 'director',
66 # while the trailer field exists, it is not useful for griffith
67 # as it's something like: "plugin://plugin.video.youtube/?action=play_video&videoid=..."
68 # however youtube urls can be probably fixed.
73 if not IP.initialize(self):
78 def set_source(self, name):
79 IP.set_source(self, name)
81 self.fileversion = self.read_fileversion()
82 if self.fileversion == None:
83 gutils.error(_('The format of the file is not supported.'))
88 """clear plugin state before next source file"""
92 self.fileversion = None
97 """close all resources"""
100 def read_fileversion(self):
103 self.xml = etree.parse(self.filename)
104 version = self.xml.xpath('/videodb/version')[0].text
107 log.info('Found file version %s' % version)
110 def count_movies(self):
111 """Returns number of movies in file which is about to be imported"""
113 log.error('No XML object')
119 count = int(self.xml.xpath('count(/videodb/movie)'))
123 log.info('%s movies for import' % count)
126 def get_movie_details(self):
127 """Returns dictionary with movie details"""
129 log.error('XML not opened')
133 self.items = self.xml.xpath('/videodb/movie')
136 # don't bother for empty db (shouldn't happen really)
137 if not self.items or len(self.items) < 1:
141 if self.itemindex >= len(self.items):
144 item = self.items[self.itemindex]
148 for k,v in self.field_map.items():
149 details[k] = item.findtext(v)
151 # if playcount set, means it's seen
152 details['seen'] = int(item.find('playcount').text) > 0
154 # genre can be multiple items, join by comma
155 details['genre'] = ', '.join(n.text for n in item.findall('genre'))
157 # increment for next iteration
158 self.itemindex = self.itemindex + 1