def parseTitle(self, filename, label=False): """ Parse the title Return tuple of title, season and episode (if exist) """ logger.debug('parseTitle(filename=%r, label=%r)', filename, label) # Special name rule for the encoding server m = re.compile('DVD \[([^]]*).*') res = m.search(filename) if res: name = res.group(1) else: name = filename # is this a series with season and episode number? # if so we will remember season and episode but will take it off from name season = '' episode = '' if config.VIDEO_SHOW_REGEXP_MATCH(name): show_name = config.VIDEO_SHOW_REGEXP_SPLIT(name) if show_name[0] and show_name[1] and show_name[2]: name = show_name[0] season = show_name[1] episode = show_name[2] logger.debug('name=%s season=%s episode=%s', name, season, episode) if label: for r in config.IMDB_REMOVE_FROM_LABEL: try: name = re.sub(r, '', name) except Exception, exc: logger.warning('Exception', exc_info=True)
def parse_name(self, name): # find image for tv show and build new name if config.VIDEO_SHOW_REGEXP_MATCH(name) and not self.network_play: show_name = config.VIDEO_SHOW_REGEXP_SPLIT(name) if show_name[0] and show_name[1] and show_name[2]: ep = config.IMDB_SEASON_EPISODE_FORMAT % (int( show_name[1]), int(show_name[2])) name = '%s %s %s' % (show_name[0], ep, show_name[3]) if config.VIDEO_SHOW_DATA_DIR: image = util.getimage( (config.VIDEO_SHOW_DATA_DIR + show_name[0].lower())) if self.filename and not image: image = util.getimage( os.path.join(os.path.dirname(self.filename), show_name[0].lower())) if image: self.image = image from video import tv_show_information if tv_show_information.has_key(show_name[0].lower()): tvinfo = tv_show_information[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.subtitle = '%s - Season %s' % (show_name[0], show_name[1]) self.tv_show_name = show_name[0] self.tv_show_season = show_name[1] self.tv_show_episode = show_name[2] self.tv_show_title = show_name[3] if not hasattr(self, 'subtitle') or not self.subtitle: self.subtitle = self.parent['title'] self.title = name return self.format_name(name)
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]
class Identify_Thread(threading.Thread): """ Thread to watch the rom drives for changes """ def identify(self, media, force_rebuild=False): """ Try to find out as much as possible about the disc in the rom drive: title, image, play options, ... """ cds = media.get_drive_status() #media.log_drive_status(cds) # Same as last time? If so we're done if media.drive_status == cds: #_debug_('status not changed for drive %r' % (media.devicename)) return logger.debug('drive_status changed %s -> %s', media.drive_status, cds) media.drive_status = cds media.id = '' media.label = '' media.type = 'empty_cdrom' media.item = None media.videoitem = None media.cached = False # Is there a disc information? if media.drive_status == CDS_NO_INFO: logger.debug('cannot get the drive status for drive %r', media.devicename) return # Is there a disc present? if media.drive_status != CDS_DISC_OK: logger.debug('disc not ready for drive %r', media.devicename) return # try to set the speed try: fd = os.open(media.devicename, os.O_RDONLY | os.O_NONBLOCK) try: if media.can_select_speed and config.ROM_SPEED: try: ioctl(fd, CDROM_SELECT_SPEED, config.ROM_SPEED) except Exception, e: logger.debug('setting rom speed for %r failed: %s', media.devicename, e) finally: #_debug_('closing %r drive %r' % (fd, media.devicename)) try: os.close(fd) except Exception, e: logger.debug('closing %r failed: %s', media.devicename, e) except Exception, e: logger.debug('opening %r failed: %s', media.devicename, e) return # if there is a disc, the tray can't be open media.tray_open = False disc_info = util.mediainfo.disc_info(media, force_rebuild) if not disc_info: logger.debug('no disc information for drive %r', media.devicename) return info = disc_info.discinfo if not info: logger.debug('no info for drive %r', media.devicename) return if info['mime'] == 'audio/cd': media.id = disc_id = info['id'] media.item = AudioDiskItem(disc_id, parent=None, devicename=media.devicename, display_type='audio') media.type = 'audio' media.item.media = media if info['title']: media.item.name = info['title'] media.item.info = disc_info logger.debug('playing audio in drive %r', media.devicename) return image = title = movie_info = more_info = fxd_file = None media.id = info['id'] media.label = info['label'] media.type = 'cdrom' label = info['label'] # is the id in the database? if media.id in video.fxd_database['id']: movie_info = video.fxd_database['id'][media.id] if movie_info: title = movie_info.name else: # no? Maybe we can find a label regexp match for (re_label, movie_info_t) in video.fxd_database['label']: if re_label.match(media.label): movie_info = movie_info_t if movie_info_t.name: title = movie_info.name m = re_label.match(media.label).groups() re_count = 1 # found, now change the title with the regexp. E.g.: # label is "bla_2", the label regexp "bla_[0-9]" and the title # is "Something \1", the \1 will be replaced with the first item # in the regexp group, here 2. The title is now "Something 2" for g in m: title = string.replace(title, '\\%s' % re_count, g) re_count += 1 break if movie_info: image = movie_info.image # DVD/VCD/SVCD: if info['mime'] in ('video/vcd', 'video/dvd'): if not title: title = media.label.replace('_', ' ').lstrip().rstrip() title = '%s [%s]' % (info['mime'][6:].upper(), title) if movie_info: media.item = copy.copy(movie_info) else: media.item = VideoItem('', None) media.item.image = util.getimage( os.path.join(config.OVERLAY_DIR, 'disc-set', media.id)) variables = media.item.info.variables media.item.info = disc_info media.item.info.set_variables(variables) media.item.name = title media.item.url = info['mime'][6:] + '://' media.item.media = media media.type = info['mime'][6:] media.item.info.mmdata = info logger.debug('playing video in drive %r', media.devicename) return # Disc is data of some sort. Mount it to get the file info util.mount(media.mountdir, force=True) try: if os.path.isdir(os.path.join(media.mountdir, 'VIDEO_TS')) or \ os.path.isdir(os.path.join(media.mountdir, 'video_ts')): if force_rebuild: logger.debug('Double check without success') else: logger.debug('Undetected DVD, checking again') media.drive_status = CDS_NO_DISC return self.identify(media, True) # Check for movies/audio/images on the disc num_video = disc_info['disc_num_video'] num_audio = disc_info['disc_num_audio'] num_image = disc_info['disc_num_image'] video_files = util.match_files(media.mountdir, config.VIDEO_SUFFIX) logger.debug('video_files=%r', video_files) media.item = DirItem(media.mountdir, None, create_metainfo=False) media.item.info = disc_info finally: util.umount(media.mountdir) # if there is a video file on the root dir of the disc, we guess # it's a video disc. There may also be audio files and images, but # they only belong to the movie if video_files: media.type = 'video' # try to find out if it is a series cd if not title: show_name = "" the_same = 1 volumes = '' start_ep = 0 end_ep = 0 video_files.sort(lambda l, o: cmp(l.upper(), o.upper())) for movie in video_files: if config.VIDEO_SHOW_REGEXP_MATCH(movie): show = config.VIDEO_SHOW_REGEXP_SPLIT( os.path.basename(movie)) if show_name and show_name != show[0]: the_same = 0 if not show_name: show_name = show[0] if volumes: volumes += ', ' current_ep = int(show[1]) * 100 + int(show[2]) if end_ep and current_ep == end_ep + 1: end_ep = current_ep elif not end_ep: end_ep = current_ep else: end_ep = -1 if not start_ep: start_ep = end_ep volumes += show[1] + "x" + show[2] if show_name and the_same and config.VIDEO_SHOW_DATA_DIR: if end_ep > 0: volumes = '%dx%02d - %dx%02d' % ( start_ep / 100, start_ep % 100, end_ep / 100, end_ep % 100) k = config.VIDEO_SHOW_DATA_DIR + show_name if os.path.isfile((k + ".png").lower()): image = (k + ".png").lower() elif os.path.isfile((k + ".jpg").lower()): image = (k + ".jpg").lower() title = show_name + ' (' + volumes + ')' if video.tv_show_information.has_key(show_name.lower()): tvinfo = video.tv_show_information[show_name.lower()] more_info = tvinfo[1] if not image: image = tvinfo[0] if not fxd_file: fxd_file = tvinfo[3] elif (not show_name) and len(video_files) == 1: movie = video_files[0] title = os.path.splitext(os.path.basename(movie))[0] # nothing found, give up: return the label if not title: title = label # If there are no videos and only audio files (and maybe images) # it is an audio disc (autostart will auto play everything) elif not num_video and num_audio: media.type = 'audio' title = '%s [%s]' % (media.drivename, label) # Only images? OK than, make it an image disc elif not num_video and not num_audio and num_image: media.type = 'image' title = '%s [%s]' % (media.drivename, label) # Mixed media? elif num_video or num_audio or num_image: media.type = None title = '%s [%s]' % (media.drivename, label) # Strange, no useable files else: media.type = None title = '%s [%s]' % (media.drivename, label) # set the info we have now if title: media.item.name = title if image: media.item.image = image if more_info: media.item.info.set_variables(more_info) if fxd_file and not media.item.fxd_file: media.item.set_fxd_file(fxd_file) # One video in the root dir. This sounds like a disc with one # movie on it. Save the information about it and autostart will # play this. if len(video_files) == 1 and media.item['num_dir_items'] == 0: util.mount(media.mountdir) try: if movie_info: media.videoitem = copy.deepcopy(movie_info) else: media.videoitem = VideoItem(video_files[0], None) finally: util.umount(media.mountdir) media.videoitem.media = media media.videoitem.media_id = media.id # set the info we have if title: media.videoitem.name = title if image: media.videoitem.image = image if more_info: media.videoitem.set_variables(more_info) if fxd_file: media.videoitem.fxd_file = fxd_file media.item.media = media
def __init__(self, url, parent, info=None, parse=True): """ Create an instance of a VideoItem @param url: the pysudo URL for the VideoItem @param parent: the parent of the VideoItem @param info: controls if additional information is found @type info: boolean @param parse: controls if the url is parsed @type parse: boolean """ self.autovars = [] Item.__init__(self, parent) self.type = 'video' self.variants = [] self.subitems = [] self.current_subitem = None self.media_id = '' self.subtitle_file = {} self.audio_file = {} 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_players = [] self.player = None self.player_rating = 0 # set the url (this influences the list of possible players!) self.set_url(url, info=parse) if info: self.info.set_variables(info) # deinterlacing and related things video_deinterlace = config.VIDEO_DEINTERLACE != None and config.VIDEO_DEINTERLACE or False self['deinterlace'] = video_deinterlace video_use_xvmc = config.VIDEO_USE_XVMC != None and config.VIDEO_USE_XVMC or False self['xvmc'] = video_use_xvmc video_field_dominance = config.VIDEO_FIELD_DOMINANCE != None and config.VIDEO_FIELD_DOMINANCE or False self['field-dominance'] = video_field_dominance # 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.join(os.path.dirname(self.filename), show_name[0].lower())) if image: self.image = image from video import tv_show_information if tv_show_information.has_key(show_name[0].lower()): tvinfo = tv_show_information[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 info in discset_information if parent and parent.media: fid = String( parent.media.id ) + self.filename[len(os.path.join(parent.media.mountdir, '')):] from video import discset_information if discset_information.has_key(fid): self.mplayer_options = discset_information[fid] if config.VIDEO_DEINTERLACE and self.info['interlaced']: # force deinterlacing self['deinterlace'] = True else: self['deinterlace'] = False
def identify(self, media, force_rebuild=False): """ magic! Try to find out as much as possible about the disc in the rom drive: title, image, play options, ... """ # Check drive status (tray pos, disc ready) try: CDSL_CURRENT = ((int)(~0 >> 1)) fd = os.open(media.devicename, os.O_RDONLY | os.O_NONBLOCK) if os.uname()[0] == 'FreeBSD': try: data = array.array('c', '\000' * 4096) (address, length) = data.buffer_info() buf = pack('BBHP', CD_MSF_FORMAT, 0, length, address) s = ioctl(fd, CDIOREADTOCENTRYS, buf) s = CDS_DISC_OK except: s = CDS_NO_DISC else: s = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) except: # maybe we need to close the fd if ioctl fails, maybe # open fails and there is no fd try: os.close(fd) except: pass media.drive_status = None return # Same as last time? If so we're done if s == media.drive_status: os.close(fd) return media.drive_status = s media.id = '' media.label = '' media.type = 'empty_cdrom' media.item = None media.videoitem = None media.cached = False # Is there a disc present? if s != CDS_DISC_OK: os.close(fd) return # if there is a disc, the tray can't be open media.tray_open = False disc_info = util.mediainfo.disc_info(media, force_rebuild) if not disc_info: # bad disc, e.g. blank disc. os.close(fd) return data = disc_info.mmdata # try to set the speed if config.ROM_SPEED and data and not data['mime'] == 'video/dvd': try: ioctl(fd, CDROM_SELECT_SPEED, config.ROM_SPEED) except: pass if data and data['mime'] == 'audio/cd': os.close(fd) disc_id = data['id'] media.item = AudioDiskItem(disc_id, parent=None, devicename=media.devicename, display_type='audio') media.type = media.item.type media.item.media = media if data['title']: media.item.name = data['title'] media.item.info = disc_info return os.close(fd) image = title = movie_info = more_info = fxd_file = None media.id = data['id'] media.label = data['label'] media.type = 'cdrom' label = data['label'] # is the id in the database? if media.id in video.fxd_database['id']: movie_info = video.fxd_database['id'][media.id] if movie_info: title = movie_info.name # no? Maybe we can find a label regexp match else: for (re_label, movie_info_t) in video.fxd_database['label']: if re_label.match(media.label): movie_info = movie_info_t if movie_info_t.name: title = movie_info.name m = re_label.match(media.label).groups() re_count = 1 # found, now change the title with the regexp. E.g.: # label is "bla_2", the label regexp "bla_[0-9]" and the title # is "Something \1", the \1 will be replaced with the first item # in the regexp group, here 2. The title is now "Something 2" for g in m: title = string.replace(title, '\\%s' % re_count, g) re_count += 1 break if movie_info: image = movie_info.image # DVD/VCD/SVCD: # There is data from mmpython for these three types if data['mime'] in ('video/vcd', 'video/dvd'): if not title: title = media.label.replace('_', ' ').lstrip().rstrip() title = '%s [%s]' % (data['mime'][6:].upper(), title) if movie_info: media.item = copy.copy(movie_info) else: media.item = VideoItem('', None) media.item.image = util.getimage( os.path.join(config.OVERLAY_DIR, 'disc-set', media.id)) variables = media.item.info.variables media.item.info = disc_info media.item.info.set_variables(variables) media.item.name = title media.item.set_url(data['mime'][6:] + '://') media.item.media = media media.type = data['mime'][6:] media.item.info.mmdata = data return # Disc is data of some sort. Mount it to get the file info util.mount(media.mountdir, force=True) if os.path.isdir(os.path.join(media.mountdir, 'VIDEO_TS')) or \ os.path.isdir(os.path.join(media.mountdir, 'video_ts')): if force_rebuild: _debug_('Double check without success') else: _debug_('Undetected DVD, checking again') media.drive_status = CDS_NO_DISC util.umount(media.mountdir) return self.identify(media, True) # Check for movies/audio/images on the disc num_video = disc_info['disc_num_video'] num_audio = disc_info['disc_num_audio'] num_image = disc_info['disc_num_image'] video_files = util.match_files(media.mountdir, config.VIDEO_SUFFIX) _debug_('identifymedia: mplayer = "%s"' % video_files, level=2) media.item = DirItem(media.mountdir, None, create_metainfo=False) media.item.info = disc_info util.umount(media.mountdir) # if there is a video file on the root dir of the disc, we guess # it's a video disc. There may also be audio files and images, but # they only belong to the movie if video_files: media.type = 'video' # try to find out if it is a series cd if not title: show_name = "" the_same = 1 volumes = '' start_ep = 0 end_ep = 0 video_files.sort(lambda l, o: cmp(l.upper(), o.upper())) for movie in video_files: if config.VIDEO_SHOW_REGEXP_MATCH(movie): show = config.VIDEO_SHOW_REGEXP_SPLIT( os.path.basename(movie)) if show_name and show_name != show[0]: the_same = 0 if not show_name: show_name = show[0] if volumes: volumes += ', ' current_ep = int(show[1]) * 100 + int(show[2]) if end_ep and current_ep == end_ep + 1: end_ep = current_ep elif not end_ep: end_ep = current_ep else: end_ep = -1 if not start_ep: start_ep = end_ep volumes += show[1] + "x" + show[2] if show_name and the_same and config.VIDEO_SHOW_DATA_DIR: if end_ep > 0: volumes = '%dx%02d - %dx%02d' % ( start_ep / 100, start_ep % 100, end_ep / 100, end_ep % 100) k = config.VIDEO_SHOW_DATA_DIR + show_name if os.path.isfile((k + ".png").lower()): image = (k + ".png").lower() elif os.path.isfile((k + ".jpg").lower()): image = (k + ".jpg").lower() title = show_name + ' (' + volumes + ')' if video.tv_show_informations.has_key(show_name.lower()): tvinfo = video.tv_show_informations[show_name.lower()] more_info = tvinfo[1] if not image: image = tvinfo[0] if not fxd_file: fxd_file = tvinfo[3] elif (not show_name) and len(video_files) == 1: movie = video_files[0] title = os.path.splitext(os.path.basename(movie))[0] # nothing found, give up: return the label if not title: title = label # If there are no videos and only audio files (and maybe images) # it is an audio disc (autostart will auto play everything) elif not num_video and num_audio: media.type = 'audio' title = '%s [%s]' % (media.drivename, label) # Only images? OK than, make it an image disc elif not num_video and not num_audio and num_image: media.type = 'image' title = '%s [%s]' % (media.drivename, label) # Mixed media? elif num_video or num_audio or num_image: media.type = None title = '%s [%s]' % (media.drivename, label) # Strange, no useable files else: media.type = None title = '%s [%s]' % (media.drivename, label) # set the infos we have now if title: media.item.name = title if image: media.item.image = image if more_info: media.item.info.set_variables(more_info) if fxd_file and not media.item.fxd_file: media.item.set_fxd_file(fxd_file) # One video in the root dir. This sounds like a disc with one # movie on it. Save the information about it and autostart will # play this. if len(video_files) == 1 and media.item['num_dir_items'] == 0: util.mount(media.mountdir) if movie_info: media.videoitem = copy.deepcopy(movie_info) else: media.videoitem = VideoItem(video_files[0], None) util.umount(media.mountdir) media.videoitem.media = media media.videoitem.media_id = media.id # set the infos we have if title: media.videoitem.name = title if image: media.videoitem.image = image if more_info: media.videoitem.set_variables(more_info) if fxd_file: media.videoitem.fxd_file = fxd_file media.item.media = media return