def __getitem__(self, key): """ returns the specific attribute as string or an empty string """ #_debug_("__getitem__(self=%s, key=%s)" % (self.filename, key), 2) if key == "geometry": if self['width'] and self['height']: return config.IMAGE_GEOMETRY_FORMAT % (self['width'], self['height']) return '' if key == "date": try: t = str(Item.__getitem__(self, key)) if t and t != '': return time.strftime(config.IMAGE_DATETIME_FORMAT, time.strptime(str(t), '%Y:%m:%d %H:%M:%S')) else: # last resort, try timestamp t = Item.__getitem__(self, 'timestamp') return datetime.datetime.fromtimestamp(t) except: pass logger.log( 9, "__getitem__(self=%s, key=%s, res=%r)", self.filename, key, Item.__getitem__(self, key)) return Item.__getitem__(self, key)
def __getitem__(self, key): """ return the specific attribute """ if key == 'type': if self.media and hasattr(self.media, 'label'): return _('Directory on disc [%s]') % self.media.label return _('Directory') if key == 'num_items': display_type = self.display_type or 'all' if self.display_type == 'tv': display_type = 'video' return self['num_%s_items' % display_type] + self['num_dir_items'] if key == 'num_play_items': display_type = self.display_type if self.display_type == 'tv': display_type = 'video' return self['num_%s_items' % display_type] if key in ('freespace', 'totalspace'): if self.media: return None space = getattr(util, key)(self.dir) / 1000000 if space > 1000: space = '%s,%s' % (space / 1000, space % 1000) return space return Item.__getitem__(self, key)
def __getitem__(self, key): """ return the specific attribute as string or an empty string """ if key == 'length' and self.length: # maybe the length was wrong if self.length < self.elapsed: self.length = self.elapsed return '%d:%02d' % (int(self.length / 60), int(self.length % 60)) if key == 'elapsed': return '%d:%02d' % (int(self.elapsed / 60), int(self.elapsed % 60)) res = Item.__getitem__(self, key) # workaround for kaa r2818 and newer: 'date' is now named 'userdate' if res == '' and key == 'date': res = Item.__getitem__(self, 'userdate') return res
def __getitem__(self, key): """ return the specific attribute as string or an empty string """ if key == 'length' and self.length: # maybe the length was wrong if self.length < self.elapsed: self.length = self.elapsed return '%d:%02d' % (int(self.length / 60), int(self.length % 60)) if key == 'elapsed': return '%d:%02d' % (int(self.elapsed / 60), int(self.elapsed % 60)) res = Item.__getitem__(self, key) # workaround for kaa r2818 and newer: 'date' is now named 'userdate' if res == '' and key == 'date': res = Item.__getitem__(self, 'userdate') return res
def __getitem__(self, key): #print "__getitem__(self=%s, key=%s)" % (self.filename, key) """ return the specific attribute as string or an empty string """ if key == "geometry": if self['width'] and self['height']: return '%sx%s' % (self['width'], self['height']) return '' if key == "date": try: t = str(Item.__getitem__(self, key)) if t: return time.strftime(config.TV_DATETIMEFORMAT, time.strptime(t, '%Y:%m:%d %H:%M:%S')) except: pass return Item.__getitem__(self, key)
def __getitem__(self, key): """ returns the specific attribute as string or an empty string """ #_debug_("__getitem__(self=%s, key=%s)" % (self.filename, key), 2) if key == "geometry": if self['width'] and self['height']: return '%sx%s' % (self['width'], self['height']) return '' if key == "date": try: t = str(Item.__getitem__(self, key)) if t: return time.strftime(config.TV_DATETIME_FORMAT, time.strptime(t, '%Y:%m:%d %H:%M:%S')) except: pass logger.log( 9, "__getitem__(self=%s, key=%s, res=%r)", self.filename, key, Item.__getitem__(self, key)) return Item.__getitem__(self, key)
def __getitem__(self, key): """ return the specific attribute as string or an empty string """ if key == 'length' and self.length: # maybe the length was wrong if self.length < self.elapsed: self.length = self.elapsed return '%d:%02d' % (int(self.length / 60), int(self.length % 60)) if key == 'elapsed': return '%d:%02d' % (int(self.elapsed / 60), int(self.elapsed % 60)) return Item.__getitem__(self, key)
def __getitem__(self, key): """ Returns the number of episodes when """ if key == 'tagline': return unicode('%d ' % len(self.items)) + _('episodes') if key == 'content': content = u'' for i in range(0, len(self.items)): content += self.items[i].name if i < (len(self.items) - 1): content += u', ' return content return Item.__getitem__(self,key)
class VideoItem(Item): def __init__(self, url, parent, info=None, parse=True): self.autovars = [('deinterlace', 0)] Item.__init__(self, parent) self.type = 'video' self.set_url(url, info=parse) if info: self.info.set_variables(info) self.variants = [] # if this item has variants self.subitems = [] # more than one file/track to play self.current_subitem = None self.media_id = '' self.subtitle_file = {} # text subtitles self.audio_file = {} # audio dubbing self.mplayer_options = '' self.tv_show = False self.video_width = 0 self.video_height = 0 self.selected_subtitle = None self.selected_audio = None self.elapsed = 0 self.possible_player = [] self.player = None self.player_rating = 0 # find image for tv show and build new title if config.VIDEO_SHOW_REGEXP_MATCH(self.name) and not self.network_play and \ config.VIDEO_SHOW_DATA_DIR: show_name = config.VIDEO_SHOW_REGEXP_SPLIT(self.name) if show_name[0] and show_name[1] and show_name[2] and show_name[3]: self.name = show_name[0] + u' ' + show_name[1] + u'x' + show_name[2] +\ u' - ' + show_name[3] image = util.getimage((config.VIDEO_SHOW_DATA_DIR + \ show_name[0].lower())) if self.filename and not image: image = util.getimage(os.path.dirname(self.filename) + '/' + \ show_name[0].lower()) if image: self.image = image from video import tv_show_informations if tv_show_informations.has_key(show_name[0].lower()): tvinfo = tv_show_informations[show_name[0].lower()] self.info.set_variables(tvinfo[1]) if not self.image: self.image = tvinfo[0] self.skin_fxd = tvinfo[3] self.mplayer_options = tvinfo[2] self.tv_show = True self.show_name = show_name self.tv_show_name = show_name[0] self.tv_show_ep = show_name[3] # extra infos in discset_informations if parent and parent.media: fid = parent.media.id + \ self.filename[len(os.path.join(parent.media.mountdir,'')):] from video import discset_informations if discset_informations.has_key(fid): self.mplayer_options = discset_informations[fid] def __str__(self): s = '\nvideo:videoitem:VideoItem:Info:s:' s += ' name=%r' % self.name s += ' filename=%r' % self.filename s += ' dir(self)=%r' % dir(self) return s def __repr__(self): s = '\nvideo:videoitem:VideoItem:Info:r:' s += ' name=%r' % self.name s += ' filename=%r' % self.filename #s += ' dir(self)=%r' % dir(self) return s def set_url(self, url, info=True): """ Sets a new url to the item. Always use this function and not set 'url' directly because this functions also changes other attributes, like filename, mode and network_play """ Item.set_url(self, url, info) if url.startswith('dvd://') or url.startswith('vcd://'): self.network_play = False self.mimetype = self.url[:self.url.find('://')].lower() if self.url.find('/VIDEO_TS/') > 0: # dvd on harddisc self.filename = self.url[5:self.url.rfind('/VIDEO_TS/')] self.info = util.mediainfo.get(self.filename) self.files = FileInformation() self.name = self.info['title:filename'] if not self.name: self.name = util.getname(self.filename) self.files.append(self.filename) elif self.url.rfind('.iso') + 4 == self.url.rfind('/'): # iso self.filename = self.url[5:self.url.rfind('/')] else: self.filename = '' elif url.endswith('.iso') and self.info['mime'] == 'video/dvd': self.mimetype = 'dvd' self.mode = 'dvd' self.url = 'dvd' + self.url[4:] + '/' if not self.image or (self.parent and self.image == self.parent.image): image = vfs.getoverlay(self.filename + '.raw') if os.path.exists(image): self.image = image self.files.image = image if config.VIDEO_INTERLACING and self.info['interlaced'] \ and not self['deinterlace']: # force deinterlacing self['deinterlace'] = 1 else: self['deinterlace'] = 0 def id(self): """ Return a unique id of the item. This id should be the same when the item is rebuild later with the same informations """ ret = self.url if self.subitems: for s in self.subitems: ret += s.id() if self.variants: for v in self.variants: ret += v.id() return ret def __getitem__(self, key): """ return the specific attribute """ if key == 'geometry' and self.info['width'] and self.info['height']: return '%sx%s' % (self.info['width'], self.info['height']) if key == 'aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: aspect = util.misc.human_aspect_ratio( self.info['width'], self.info['height']) if aspect: return aspect if key == 'runtime': total = 0 length = 0 if self.info['runtime']: length = self.info['runtime'] # Assuming that runtime is always a string # Assume that a time 1:40 is hours:minutes # Not sure when a '/' is used p = re.compile('([0-9]+)[:/]*([0-9]*)') m = p.match(length) if m: length = int(m.group(1)) if m.group(2): length *= 60 + int(m.group(2)) else: length = 0 total = '%s min' % str(int(length)) if length == 0: if self.subitems: for s in self.subitems: if s.info['length']: length = s.info['length'] if not length and hasattr(s, 'length'): length = s.length if not length: continue try: total += length except ValueError, TypeError: pass total = '%s min' % str(int(total) / 60) else: if self.info['length']: total = self.info['length'] elif hasattr(self, 'length'): total = self.length if total != 'None': total = '%s min' % str(int(total) / 60) else: total = '' return total return Item.__getitem__(self, key)
def __getitem__(self, key): """ Get the item's attribute. @returns: the specific attribute """ if not self.info: return '' if key == 'geometry' and self.info['width'] and self.info['height']: return '%sx%s' % (self.info['width'], self.info['height']) if key == 'aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: aspect = util.misc.human_aspect_ratio( self.info['width'], self.info['height']) if aspect: return aspect if key == 'mplayer_aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: ratio = float(self.info['width']) / self.info['height'] aspect = "%f" % ratio if aspect: return aspect if key == 'rating': if self.info['rating']: return self.info['rating'] else: return '' if key == 'runtime': if self.info['runtime']: if self.info['runtime'] != 'None': return self.info['runtime'] total = 0 if self.subitems: for s in self.subitems: length = 0 if s.info['length']: length = s.info['length'] if not length and hasattr(s, 'length'): length = s.length if not length: continue try: total += length except TypeError: logger.debug('Invalid length: %r', length) total = '%s min' % str(int(total) / 60) else: if self.info['length']: total = self.info['length'] elif hasattr(self, 'length'): total = self.length try: total = '%s min' % str(int(total) / 60) except ValueError: try: runtime = self.info['runtime'] except: total = '' return total return Item.__getitem__(self, key)
def __getitem__(self, key): """ Get the item's attribute. @returns: the specific attribute """ if key == 'title': if hasattr(self, 'title') and self.title: return self.title elif hasattr(self, 'name') and self.name: return self.name else: return '' if key == 'display_type': display_type = Item.__getitem__(self, key) if display_type and display_type == 'tv': display_type = 'video' return display_type if not self.info: return '' if key == 'geometry' and self.info['width'] and self.info['height']: return '%sx%s' % (self.info['width'], self.info['height']) if key == 'aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: aspect = util.misc.human_aspect_ratio(self.info['width'], self.info['height']) if aspect: return aspect if key == 'mplayer_aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: ratio = float(self.info['width']) / self.info['height'] aspect = "%f" % ratio if aspect: return aspect if key == 'rating': if self.info['rating']: return self.info['rating'] else: return '' if key == 'runtime': if self.info['runtime']: if self.info['runtime'] != 'None': return self.info['runtime'] total = 0 if self.subitems: for s in self.subitems: length = 0 if s.info['length']: length = s.info['length'] if not length and hasattr(s, 'length'): length = s.length if not length: continue try: total += length except TypeError: logger.debug('Invalid length: %r', length) total = '%s min' % str(int(total) / 60) else: if self.info['length']: total = self.info['length'] elif hasattr(self, 'length'): total = self.length try: total = '%s min' % str(int(total) / 60) except ValueError: try: runtime = self.info['runtime'] except: total = '' return total if key == 'mpaa_rating': try: if self.info['mpaa']: mpaa = self.info['mpaa'] rating_match = re.search(r"Rated (?P<rating>[a-zA-Z0-9-]+)", mpaa) if rating_match: rating = rating_match.group('rating') else: rating_match = re.search(r"(?P<rating>[a-zA-Z0-9-]+)", mpaa) if rating_match: rating = rating_match.group('rating') if rating in config.IMDB_MPAA_RATINGS: return rating.lower() except: pass return '' return Item.__getitem__(self, key)
def __getitem__(self, key): """ Get the item's attribute. @returns: the specific attribute """ if key == 'title': if hasattr(self, 'title') and self.title: return self.title elif hasattr(self, 'name') and self.name: return self.name else: return '' if key == 'display_type': display_type = Item.__getitem__(self, key) if display_type and display_type == 'tv': display_type = 'video' return display_type if not self.info: return '' if key == 'geometry' and self.info['width'] and self.info['height']: return '%sx%s' % (self.info['width'], self.info['height']) if key == 'aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: aspect = util.misc.human_aspect_ratio( self.info['width'], self.info['height']) if aspect: return aspect if key == 'mplayer_aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: ratio = float(self.info['width']) / self.info['height'] aspect = "%f" % ratio if aspect: return aspect if key == 'rating': if self.info['rating']: return self.info['rating'] else: return '' if key == 'runtime': if self.info['runtime']: if self.info['runtime'] != 'None': return self.info['runtime'] total = 0 if self.subitems: for s in self.subitems: length = 0 if s.info['length']: length = s.info['length'] if not length and hasattr(s, 'length'): length = s.length if not length: continue try: total += length except TypeError: logger.debug('Invalid length: %r', length) total = '%s min' % str(int(total) / 60) else: if self.info['length']: total = self.info['length'] elif hasattr(self, 'length'): total = self.length try: total = '%s min' % str(int(total) / 60) except ValueError: try: runtime = self.info['runtime'] except: total = '' return total if key == 'mpaa_rating': try: if self.info['mpaa']: mpaa = self.info['mpaa'] rating_match = re.search( r"Rated (?P<rating>[a-zA-Z0-9-]+)", mpaa) if rating_match: rating = rating_match.group('rating') else: rating_match = re.search(r"(?P<rating>[a-zA-Z0-9-]+)", mpaa) if rating_match: rating = rating_match.group('rating') if rating in config.IMDB_MPAA_RATINGS: return rating.lower() except: pass return '' return Item.__getitem__(self, key)
def __getitem__(self, key): """ Get the item's attribute. @returns: the specific attribute """ if not self.info: return '' if key == 'geometry' and self.info['width'] and self.info['height']: return '%sx%s' % (self.info['width'], self.info['height']) if key == 'aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: aspect = util.misc.human_aspect_ratio(self.info['width'], self.info['height']) if aspect: return aspect if key == 'mplayer_aspect': aspect = None if self.info['aspect']: aspect = str(self.info['aspect']) aspect[:aspect.find(' ')].replace('/', ':') else: if self.info['width'] and self.info['height']: ratio = float(self.info['width']) / self.info['height'] aspect = "%f" % ratio if aspect: return aspect if key == 'rating': if self.info['rating']: return self.info['rating'] else: return '' if key == 'runtime': if self.info['runtime']: if self.info['runtime'] != 'None': return self.info['runtime'] total = 0 if self.subitems: for s in self.subitems: length = 0 if s.info['length']: length = s.info['length'] if not length and hasattr(s, 'length'): length = s.length if not length: continue try: total += length except TypeError: logger.debug('Invalid length: %r', length) total = '%s min' % str(int(total) / 60) else: if self.info['length']: total = self.info['length'] elif hasattr(self, 'length'): total = self.length try: total = '%s min' % str(int(total) / 60) except ValueError: try: runtime = self.info['runtime'] except: total = '' return total return Item.__getitem__(self, key)