def parse_disc_set(fxd, node): """ Callback for VideoItem <disc-set> """ item = VideoItem('', fxd.getattr(None, 'parent', None), parse=False) dirname = os.path.dirname(fxd.filename) item.name = fxd.getattr(node, 'title') item.image = fxd.childcontent(node, 'cover-img') if item.image: item.image = vfs.abspath(os.path.join(dirname, item.image)) fxd.parse_info(node, item, {'runtime': 'length'}) item.__fxd_rom_info__ = True item.__fxd_rom_label__ = [] item.__fxd_rom_id__ = [] item.__fxd_files_options__ = [] for disc in fxd.get_children(node, 'disc'): id = fxd.getattr(disc, 'media-id') if id: item.__fxd_rom_id__.append(id) label = fxd.getattr(disc, 'label-regexp') if label: item.__fxd_rom_label__.append(label) # what to do with the mplayer_options? We can't use them for # one disc, or can we? And file_ops? Also only on a per disc base. # Answer: it applies to all the files of the disc, unless there # are <file-opt> which specify to what files the # mplayer_options apply. <file-opt> is not such a good # name, though. # So I ignore that we are in a disc right now and use the 'item' item.mplayer_options = fxd.getattr(disc, 'mplayer-options') there_are_file_opts = 0 for f in fxd.get_children(disc, 'file-opt'): there_are_file_opts = 1 file_media_id = fxd.getattr(f, 'media-id') if not file_media_id: file_media_id = id mpl_opts = item.mplayer_options + ' ' + fxd.getattr( f, 'mplayer-options') opt = { 'file-id': file_media_id + fxd.gettext(f), 'mplayer-options': mpl_opts } item.__fxd_files_options__.append(opt) if there_are_file_opts: # in this case, the disc/@mplayer_options is retricted to the set # of files defined in the file-opt elements item.mplayer_options = '' if not item.files: item.files = FileInformation() item.files.fxd_file = fxd.filename if fxd.is_skin_fxd: item.skin_fxd = fxd.filename fxd.getattr(None, 'items', []).append(item)
def parse_disc_set(fxd, node): """ Callback for VideoItem <disc-set> """ item = VideoItem('', fxd.getattr(None, 'parent', None), parse=False) dirname = os.path.dirname(fxd.filename) item.name = fxd.getattr(node, 'title') item.image = fxd.childcontent(node, 'cover-img') if item.image: item.image = vfs.abspath(os.path.join(dirname, item.image)) fxd.parse_info(node, item, {'runtime': 'length'}) item.__fxd_rom_info__ = True item.__fxd_rom_label__ = [] item.__fxd_rom_id__ = [] item.__fxd_files_options__ = [] for disc in fxd.get_children(node, 'disc'): id = fxd.getattr(disc, 'media-id') if id: item.__fxd_rom_id__.append(id) label = fxd.getattr(disc, 'label-regexp') if label: item.__fxd_rom_label__.append(label) # what to do with the mplayer_options? We can't use them for # one disc, or can we? And file_ops? Also only on a per disc base. # Answer: it applies to all the files of the disc, unless there # are <file-opt> which specify to what files the # mplayer_options apply. <file-opt> is not such a good # name, though. # So I ignore that we are in a disc right now and use the 'item' item.mplayer_options = fxd.getattr(disc, 'mplayer_options') there_are_file_opts = 0 for f in fxd.get_children(disc, 'file-opt'): there_are_file_opts = 1 file_media_id = fxd.getattr(f, 'media-id') if not file_media_id: file_media_id = id mpl_opts = item.mplayer_options + ' ' + fxd.getattr(f, 'mplayer-options') opt = { 'file-id' : file_media_id + fxd.gettext(f), 'mplayer_options': mpl_opts } item.__fxd_files_options__.append(opt) if there_are_file_opts: # in this case, the disc/@mplayer_options is retricted to the set # of files defined in the file-opt elements item.mplayer_options = '' if not item.files: item.files = FileInformation() item.files.fxd_file = fxd.filename if fxd.is_skin_fxd: item.skin_fxd = fxd.filename fxd.getattr(None, 'items', []).append(item)
def get(self, parent, files): """ return a list of items based on the files """ items = [] all_files = util.find_matches(files, config.VIDEO_SUFFIX) # sort all files to make sure 1 is before 2 for auto-join all_files.sort(lambda l, o: cmp(l.upper(), o.upper())) hidden_files = [] pat = re.compile(config.VIDEO_AUTOJOIN_REGEX) for file in all_files: if parent and parent.type == 'dir' and \ hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \ parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS: util.videothumb.snapshot(file, update=False, popup=True) if file in hidden_files: files.remove(file) continue x = VideoItem(file, parent) # join video files if config.VIDEO_AUTOJOIN: mat = pat.search(file) if mat is not None: add_file = [] start = file.find(mat.group(1), mat.start()) end = start + len(mat.group(1)) stem = file[:start] tail = file[end:] next = 2 for f in all_files: next_str = '%0*d' % (end - start, next) filename = stem + next_str + tail if filename in all_files: add_file.append(filename) else: break next += 1 if len(add_file) > 0: name = stem + tail x = VideoItem(name, parent) x.files = FileInformation() x.subitems.append(VideoItem(file, x)) x.set_url(file, True) for filename in add_file: x.files.append(filename) x.subitems.append(VideoItem(filename, x)) hidden_files.append(filename) if parent and parent.media: file_id = String( parent.media.id ) + file[len(os.path.join(parent.media.mountdir, '')):] try: x.mplayer_options = discset_information[file_id] logger.debug('x.mplayer_options=%r', x.mplayer_options) except KeyError: pass items.append(x) files.remove(file) for i in copy.copy(files): if os.path.isdir(i + '/VIDEO_TS'): # DVD Image, trailing slash is important for Xine items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/', parent)) files.remove(i) return items
def get(self, parent, files): """ return a list of items based on the files """ items = [] all_files = util.find_matches(files, config.VIDEO_SUFFIX) # sort all files to make sure 1 is before 2 for auto-join all_files.sort(lambda l, o: cmp(l.upper(), o.upper())) hidden_files = [] pat = re.compile(config.VIDEO_AUTOJOIN_REGEX) for file in all_files: if parent and parent.type == 'dir' and \ hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \ parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS: util.videothumb.snapshot(file, update=False, popup=True) if file in hidden_files: files.remove(file) continue x = VideoItem(file, parent) # join video files if config.VIDEO_AUTOJOIN: mat = pat.search(file) if mat is not None: add_file = [] start = file.find(mat.group(1), mat.start()) end = start + len(mat.group(1)) stem = file[:start] tail = file[end:] next = 2 for f in all_files: next_str = '%0*d' % (end-start, next) filename = stem+next_str+tail if filename in all_files: add_file.append(filename) else: break next += 1 if len(add_file) > 0: name = stem+tail x = VideoItem(name, parent) x.files = FileInformation() x.subitems.append(VideoItem(file, x)) x.set_url(file, True) for filename in add_file: x.files.append(filename) x.subitems.append(VideoItem(filename, x)) hidden_files.append(filename) if parent and parent.media: file_id = String(parent.media.id) + file[len(os.path.join(parent.media.mountdir, '')):] try: x.mplayer_options = discset_information[file_id] logger.debug('x.mplayer_options=%r', x.mplayer_options) except KeyError: pass items.append(x) files.remove(file) for i in copy.copy(files): if os.path.isdir(i+'/VIDEO_TS'): # DVD Image, trailing slash is important for Xine items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/', parent)) files.remove(i) return items
def get(self, parent, files): """ return a list of items based on the files """ items = [] all_files = util.find_matches(files, config.VIDEO_SUFFIX) # sort all files to make sure 1 is before 2 for auto-join all_files.sort(lambda l, o: cmp(l.upper(), o.upper())) hidden_files = [] for file in all_files: if parent and parent.type == 'dir' and \ hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \ parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS: util.videothumb.snapshot(file, update=False, popup=True) if file in hidden_files: files.remove(file) continue x = VideoItem(file, parent) # join video files if config.VIDEO_AUTOJOIN and file.find('1') > 0: pos = 0 for count in range(file.count('1')): # only count single digests if file[pos+file[pos:].find('1')-1] in string.digits or \ file[pos+file[pos:].find('1')+1] in string.digits: pos += file[pos:].find('1') + 1 continue add_file = [] missing = 0 for i in range(2, 6): current = file[:pos] + file[pos:].replace( '1', str(i), 1) if current in all_files: add_file.append(current) end = i elif not missing: # one file missing, stop searching missing = i if add_file and missing > end: if len(add_file) > 3: # more than 4 files, I don't belive it break # create new name name = file[:pos] + file[pos:].replace( '1', '1-%s' % end, 1) x = VideoItem(name, parent) x.files = FileInformation() x.set_url(file, True) for f in [file] + add_file: x.files.append(f) x.subitems.append(VideoItem(f, x)) hidden_files.append(f) break else: pos += file[pos:].find('1') + 1 if parent.media: file_id = String(parent.media.id) + \ file[len(os.path.join(parent.media.mountdir, "")):] try: x.mplayer_options = discset_information[file_id] _debug_('x.mplayer_options=%r' % x.mplayer_options) except KeyError: pass items.append(x) files.remove(file) for i in copy.copy(files): if os.path.isdir(i + '/VIDEO_TS'): # DVD Image, trailing slash is important for Xine items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/', parent)) files.remove(i) return items