def getattr(self, attr): """ wrapper for __getitem__ to return the attribute as string or an empty string if the value is 'None' """ if attr[:4] == 'len(' and attr[-1] == ')': return self.__getitem__(attr) else: r = self.__getitem__(attr) return Unicode(r)
def set_url(self, url, info=True, search_image=True): """ Set a new url to the item and adjust all attributes depending on the url. """ self.url = url # the url itself if not url: self.network_play = True # network url, like http self.filename = '' # filename if it's a file:// url self.mode = '' # the type of the url (file, http, dvd...) self.files = None # FileInformation self.mimetype = '' # extention or mode return if url.find('://') == -1: self.url = 'file://' + url self.files = FileInformation() if self.media: self.files.read_only = True self.mode = self.url[:self.url.find('://')] if self.mode == 'file': self.network_play = False self.filename = self.url[7:] self.files.append(self.filename) if search_image: image = util.getimage(self.filename[:self.filename.rfind('.')]) if image: self.image = image self.files.image = image elif self.parent and self.parent.type != 'dir': self.image = util.getimage(os.path.dirname(self.filename)+\ '/cover', self.image) if config.REMOVE_COMMERCIALS: edlBase=self.filename[:self.filename.rfind('.')] edlFile=edlBase+".edl" self.edl_file=edlFile if os.path.exists(edlFile): self.files.edl_file=edlFile else: self.files.edl_file=None self.mimetype = self.filename[self.filename.rfind('.')+1:].lower() if info: self.info = mediainfo.get(self.filename) try: if self.parent.DIRECTORY_USE_MEDIAID_TAG_NAMES: self.name = self.info['title'] or self.name except: pass if not self.name: self.name = self.info['title:filename'] if self.type == 'audio' and info: # Look for audio cover image by ID3 tags filename_array = { 'album' : self.info['album'], 'artist' : self.info['artist'] } for format_string in config.AUDIO_COVER_FORMAT_STRINGS: filemask = format_string % filename_array if format_string.startswith('/'): audiocover = util.getimage(filemask) else: audiocover = util.getimage(os.path.dirname(self.filename)+'/'+filemask) if audiocover: self.image = audiocover self.files.image = audiocover break; if not self.name: self.name = util.getname(self.filename) else: self.network_play = True self.filename = '' self.mimetype = self.type if not self.name: self.name = Unicode(self.url)
def set_url(self, url, info=True, search_image=True): """ Set a new url to the item and adjust all attributes depending on the url. WARNING: This is called whenever self.url is set, therefor it is strictly forbidden to set self.url directly in this function, (infinit recursion!). Use self.__dict__['url'] instead! """ # set the url itself if url and url.find('://') == -1: # local url self.__dict__['url'] = 'file://' + url else: # some other kind of url self.__dict__['url'] = url if self.url == None: # reset everything to default values self.network_play = True self.filename = '' self.mode = '' self.files = None self.mimetype = '' return # add additional info files self.files = FileInformation() if self.media: self.files.read_only = True # determine the mode of this item self.mode = self.url[:self.url.find('://')] if self.mode == 'file': self.network_play = False self.filename = self.url[7:] self.files.append(self.filename) self.mimetype = os.path.splitext(self.filename)[1][1:].lower() if search_image: image = util.getimage(self.filename[:self.filename.rfind('.')]) if image: self.image = image self.files.image = image elif self.parent and self.parent.type != 'dir': imagepath = os.path.dirname(self.filename) imagepath = os.path.join(imagepath, 'cover') self.image = util.getimage(imagepath, self.image) # TODO: is this the right place for this? if config.TV_RECORD_REMOVE_COMMERCIALS: edlBase = self.filename[:self.filename.rfind('.')] edlFile = edlBase + ".edl" self.edl_file = edlFile if os.path.exists(edlFile): self.files.edl_file = edlFile else: self.files.edl_file = None if info: self.info = mediainfo.get(self.filename) try: if self.parent.DIRECTORY_USE_MEDIAID_TAG_NAMES: self.name = self.info['title'] or self.name except: pass if not self.name: self.name = self.info['title:filename'] if not self.name: self.name = util.getname(self.filename) else: # some defaults for other url types self.network_play = True self.filename = '' self.mimetype = self.type if not self.name: self.name = Unicode(self.url)