def importMetadata(self, metadata, overwrite=False): """Imports data from a VideoMetadata object.""" def _allow_change(self, tag, overwrite): if overwrite: return True if self[tag] is None: return True if self[tag] == '': return True if tag in self._defaults: if self[tag] == self._defaults[tag]: return True return False # only work on existing entries if self._wheredat is None: return # pull direct matches for tag in ('title', 'subtitle', 'description', 'chanid', 'starttime', 'recgroup', 'playgroup', 'seriesid', 'programid', 'storagegroup'): if metadata[tag] and _allow_change(self, tag, overwrite): self[tag] = metadata[tag] # pull renamed matches for tagf, tagt in (('userrating', 'stars'), ('filename', 'basename'), ('startts', 'progstart'), ('endts', 'progend'), ('recstartts', 'starttime'), ('recendts', 'endtime')): if metadata[tagf] and _allow_change(self, tagt, overwrite): self[tagt] = metadata[tagf] # pull cast trans = {'Author': 'writer'} for cast in metadata.people: self.cast.append( unicode(cast.name), unicode(trans.get(cast.job, cast.job.lower().replace(' ', '_')))) # pull images exists = { 'coverart': False, 'fanart': False, 'banner': False, 'screenshot': False } be = FileOps(self.hostname, db=self._db) for image in metadata.images: if exists[image.type]: continue group = Video._getGroup(self.hostname, image.type, self._db) if not be.fileExists(image.filename, group): be.downloadTo(image.url, group, image.filename) exists[image.type] = True self.update()
def importMetadata(self, metadata, overwrite=False): """Imports data from a VideoMetadata object.""" def _allow_change(self, tag, overwrite): if overwrite: return True if self[tag] is None: return True if self[tag] == '': return True if tag in self._defaults: if self[tag] == self._defaults[tag]: return True return False # only work on existing entries if self._wheredat is None: return # pull direct matches for tag in ('title', 'subtitle', 'description', 'chanid', 'starttime', 'recgroup', 'playgroup', 'seriesid', 'programid', 'storagegroup'): if metadata[tag] and _allow_change(self, tag, overwrite): self[tag] = metadata[tag] # pull renamed matches for tagf,tagt in (('userrating','stars'), ('filename', 'basename'), ('startts','progstart'),('endts','progend'), ('recstartts','starttime'),('recendts','endtime')): if metadata[tagf] and _allow_change(self, tagt, overwrite): self[tagt] = metadata[tagf] # pull cast trans = {'Author':'writer'} for cast in metadata.people: self.cast.append(unicode(cast.name), unicode(trans.get(cast.job, cast.job.lower().replace(' ','_')))) # pull images exists = {'coverart':False, 'fanart':False, 'banner':False, 'screenshot':False} be = FileOps(self.hostname, db=self._db) for image in metadata.images: if exists[image.type]: continue group = Video._getGroup(self.hostname, image.type, self._db) if not be.fileExists(image.filename, group): be.downloadTo(image.url, group, image.filename) exists[image.type] = True self.update()
def importMetadata(self, metadata, overwrite=False): """Imports data from a VideoMetadata object.""" def _allow_change(self, tag, overwrite): if overwrite: return True if self[tag] is None: return True if self[tag] == '': return True if tag in self._defaults: if self[tag] == self._defaults[tag]: return True return False # only operate on existing entries if self._wheredat is None: return # pull direct tags for tag in ('title', 'subtitle', 'tagline', 'season', 'episode', 'inetref', 'homepage', 'trailer', 'userrating', 'year'): if metadata[tag] and _allow_change(self, tag, overwrite): self[tag] = metadata[tag] # pull tags needing renaming for tagf,tagt in (('description','plot'), ('runtime','length')): if metadata[tagf] and _allow_change(self, tagt, overwrite): self[tagt] = metadata[tagf] # pull director try: if _allow_change(self, 'director', overwrite): self.director = [person.name for person in metadata.people \ if person.job=='Director'].pop(0) except IndexError: pass # pull actors for actor in [person for person in metadata.people \ if person.job=='Actor']: self.cast.add(unicode(actor.name)) # pull genres for category in metadata.categories: self.genre.add(unicode(category)) # pull images (SG content only) if bool(self.host): # only perform image grabs if 'host' is set, denoting SG use t1 = ['coverart','fanart','banner','screenshot'] t2 = ['coverfile','fanart','banner','screenshot'] mdtype = dict(zip(t1,t2)) exists = dict(zip(t1,[False,False,False,False])) be = FileOps(self.host, db=self._db) for image in metadata.images: if exists[image.type]: continue if not _allow_change(self, mdtype[image.type], overwrite): continue self[mdtype[image.type]] = image.filename group = self._getGroup(self.host, image.type, self._db) if not be.fileExists(image.filename, group): be.downloadTo(image.url, group, image.filename) exists[image.type] = True self.processed = True self.update()
def importMetadata(self, metadata, overwrite=False): """Imports data from a VideoMetadata object.""" def _allow_change(self, tag, overwrite): if overwrite: return True if self[tag] is None: return True if self[tag] == "": return True if tag in self._defaults: if self[tag] == self._defaults[tag]: return True return False # only work on existing entries if self._wheredat is None: return # pull direct matches for tag in ( "title", "subtitle", "description", "chanid", "starttime", "recgroup", "playgroup", "seriesid", "programid", "storagegroup", ): if metadata[tag] and _allow_change(self, tag, overwrite): self[tag] = metadata[tag] # pull renamed matches for tagf, tagt in ( ("userrating", "stars"), ("filename", "basename"), ("startts", "progstart"), ("endts", "progend"), ("recstartts", "starttime"), ("recendts", "endtime"), ): if metadata[tagf] and _allow_change(self, tagt, overwrite): self[tagt] = metadata[tagf] # pull cast trans = {"Author": "writer"} for cast in metadata.people: self.cast.append(unicode(cast.name), unicode(trans.get(cast.job, cast.job.lower().replace(" ", "_")))) # pull images exists = {"coverart": False, "fanart": False, "banner": False, "screenshot": False} be = FileOps(self.hostname, db=self._db) for image in metadata.images: if exists[image.type]: continue group = Video._getGroup(self.hostname, image.type, self._db) if not be.fileExists(image.filename, group): be.downloadTo(image.url, group, image.filename) exists[image.type] = True self.update()
def importMetadata(self, metadata, overwrite=False): """Imports data from a VideoMetadata object.""" def _allow_change(self, tag, overwrite): if overwrite: return True if self[tag] is None: return True if self[tag] == '': return True if tag in self._defaults: if self[tag] == self._defaults[tag]: return True return False # only operate on existing entries if self._wheredat is None: return # pull direct tags for tag in ('title', 'subtitle', 'tagline', 'season', 'episode', 'inetref', 'homepage', 'trailer', 'userrating', 'year'): if metadata[tag] and _allow_change(self, tag, overwrite): self[tag] = metadata[tag] # pull tags needing renaming for tagf, tagt in (('description', 'plot'), ('runtime', 'length')): if metadata[tagf] and _allow_change(self, tagt, overwrite): self[tagt] = metadata[tagf] # pull director try: if _allow_change(self, 'director', overwrite): self.director = [person.name for person in metadata.people \ if person.job=='Director'].pop(0) except IndexError: pass # pull actors for actor in [person for person in metadata.people \ if person.job=='Actor']: self.cast.add(unicode(actor.name)) # pull genres for category in metadata.categories: self.genre.add(unicode(category)) # pull images (SG content only) if bool(self.host): # only perform image grabs if 'host' is set, denoting SG use t1 = ['coverart', 'fanart', 'banner', 'screenshot'] t2 = ['coverfile', 'fanart', 'banner', 'screenshot'] mdtype = dict(zip(t1, t2)) exists = dict(zip(t1, [False, False, False, False])) be = FileOps(self.host, db=self._db) for image in metadata.images: if exists[image.type]: continue if not _allow_change(self, mdtype[image.type], overwrite): continue self[mdtype[image.type]] = image.filename group = self._getGroup(self.host, image.type, self._db) if not be.fileExists(image.filename, group): be.downloadTo(image.url, group, image.filename) exists[image.type] = True self.processed = True self.update()
def downloadFrom(self, url): if self.parent is None: raise RuntimeError("Artwork.downloadFrom must be called from "+\ "object, not class.") be = FileOps(self.hostname, db=self.parent._db) be.downloadTo(url, self.imagetype, self)