def getheadlines(self, arg=None, menuw=None): """ this returns a menu with VideoItems for each headline """ headlines = [] rawheadlines = [] rawheadlines = self.getsiteheadlines() for title, link, description in rawheadlines: # create a VideoItem for each headline mi = VideoItem(link, self.parent) mi.name = title description = description.replace('\n\n', '&#xxx;').replace('\n', ' ').\ replace('&#xxx;', '\n') description = description.replace('<p>', '\n').replace('<br>', '\n') description = description.replace('<p>', '\n').replace('<br/>', '\n') description = description + '\n \n \nLink: ' + link description = util.htmlenties2txt(description) mi.plot = re.sub('<.*?>', '', description) headlines.append(mi) # create the menu if (len(headlines) == 0): headlines += [menu.MenuItem(_('No Headlines found'), menuw.back_one_menu, 0)] headlines_menu = menu.Menu(_('Headlines'), headlines) menuw.pushmenu(headlines_menu) menuw.refresh()
def __init__(self, parent, flux_name, flux_location): VideoItem.__init__(self, flux_location, parent) self.network_play = True self.parent = parent self.location = flux_location self.name = flux_name.decode('utf8') self.type = 'video' self.force_player = 'vlc'
def actions(self): """ return the default action """ actions = VideoItem.actions(self) items = actions[0:2] items.append((self.mark_to_keep, self.keep and _('Unmark to Keep') or _('Mark to Keep'))) items.append((self.mark_as_watched, self.watched and _('Unmark as Watched') or _('Mark as Watched'))) items.append(MenuItem(_('Search for more of this program'), search_for_more, (self, self.video_item.name))) items.append(MenuItem(_('Add to favorites'), add_to_favorites, (self, self.video_item.name))) items = items + actions[2:] return items
def __init__(self, parent, gip_type, index, pid, name, episode, desc, thumbnail): """ Create a new program instance. @param parent: Parent item. @param gip_type: get_iplayer type. @param index: get_iplayer index. @param pid: get_iplayter pid. @param name: Name of the program. @param epsiode: Name of the episode. @param desc: Description of the program. @param thumbnail: URL for the thumbnail. """ VideoItem.__init__(self, "http://127.0.0.1:%d/%s/%s/video.mov" % (IPLAYER_WEB_PORT, gip_type, pid), parent) self.gip_type = gip_type self.pid = pid self.index = index self.name = Unicode(name) self.info["title"] = self.name self.info["tagline"] = episode self.info["plot"] = desc self.image = thumbnail
def __init__(self, parent, gip_type, index, pid, name, episode, desc, thumbnail): """ Create a new program instance. @param parent: Parent item. @param gip_type: get_iplayer type. @param index: get_iplayer index. @param pid: get_iplayter pid. @param name: Name of the program. @param epsiode: Name of the episode. @param desc: Description of the program. @param thumbnail: URL for the thumbnail. """ VideoItem.__init__( self, 'http://127.0.0.1:%d/%s/%s/video.mov' % (IPLAYER_WEB_PORT, gip_type, pid), parent) self.gip_type = gip_type self.pid = pid self.index = index self.name = Unicode(name) self.info['title'] = self.name self.info['tagline'] = episode self.info['plot'] = desc self.image = thumbnail
def actions(self): """ return a list of actions for this item """ dq = get_download_queue() if self.gip_type == "itv": if dq.is_downloading(self.gip_type, self.pid) or dq.is_queued(self.gip_type, self.pid): return [(self.cancel_download, _("Cancel Download")), (self.show_details, _("Full description"))] else: return [(self.download, _("Download")), (self.show_details, _("Full description"))] actions = VideoItem.actions(self) if dq.is_downloading(self.gip_type, self.pid) or dq.is_queued(self.gip_type, self.pid): actions.append((self.cancel_download, _("Cancel Download"))) else: actions.append((self.download, _("Download"))) return actions
def actions(self): """ return a list of actions for this item """ dq = get_download_queue() if self.gip_type == 'itv': if dq.is_downloading(self.gip_type, self.pid) or \ dq.is_queued(self.gip_type, self.pid): return [(self.cancel_download, _('Cancel Download')), (self.show_details, _('Full description'))] else: return [(self.download, _('Download')), (self.show_details, _('Full description'))] actions = VideoItem.actions(self) if dq.is_downloading(self.gip_type, self.pid) or \ dq.is_queued(self.gip_type, self.pid): actions.append((self.cancel_download, _('Cancel Download'))) else: actions.append((self.download, _('Download'))) return actions
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 show_details(self, arg=None, menuw=None): query_get_iplayer("-i %s" % self.index, self.gip_type, self.__getiplayer_line_cb, None) VideoItem.show_details(self, arg, menuw)
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
def show_details(self, arg=None, menuw=None): query_get_iplayer('-i %s' % self.index, self.gip_type, self.__getiplayer_line_cb, None) VideoItem.show_details(self, arg, menuw)
class FCMenu(Item): def __init__(self): Item.__init__(self) self.type = 'tv' self.gui_manager = GuiManagerEmulator() def main_menu(self, arg, menuw): items = [] for module in Hosts.AVALIABLE_APIS: display_name = module.display_name items.append(menu.MenuItem(display_name, action=self.selected_source, arg=module)) menuw.pushmenu(menu.Menu('Stream', items, item_types='stream')) def selected_source(self, arg, menuw): api = arg items = [] search = api.Show.search() for show in search: items.append(menu.MenuItem(show.name, action=self.selected_show, arg=(api, show))) menuw.pushmenu(menu.Menu('stream', items, item_types='stream')) def selected_show(self, arg, menuw): api, show = arg items = [] for season in show.seasons: items.append(menu.MenuItem(show.name + ' Season ' + str(season.number), action=self.selected_season, arg=(api, show, season))) menuw.pushmenu(menu.Menu('stream', items, item_types='stream')) def selected_season(self, arg, menuw): api, show, season = arg items = [] for episode in season.episodes: items.append(menu.MenuItem(show.name + ' Season ' + str(season.number) + ' Episode ' + str(episode.number) + ' ' + str(episode.name), action=self.selected_episode, arg=(api, show, season, episode))) menuw.pushmenu(menu.Menu('stream', items, item_types='stream')) def selected_episode(self, arg, menuw): api, show, season, episode = arg items = [] for host in episode.file_hosts.iterkeys(): items.append(menu.MenuItem(host, action=self.selected_host, arg=(api, show, season, episode, host))) menuw.pushmenu(menu.Menu('stream', items, item_types='stream')) def selected_host(self, arg, menuw): api, show, season, episode, host = arg items = [] for quality in episode.file_hosts[host].iterkeys(): items.append(menu.MenuItem(quality, action=self.selected_quality, arg=(api, show, season, episode, host, quality))) menuw.pushmenu(menu.Menu('stream', items, item_types='stream')) def selected_quality(self, arg, menuw): api, show, season, episode, host, quality = arg self.video_item = None self.menuw = menuw self.file_object = episode self.selected_host = host self.selected_quality = quality config.VIDEO_SHOW_DATA_DIR = '/media/disk/video' self.file_path = os.path.join(config.VIDEO_SHOW_DATA_DIR, self.get_filename(episode)) box = PopupBox(text='Starting download... will start playing shortly') box.show() time.sleep(2) box.destroy() if os.path.exists(self.file_path): # TODO: check file completition? self.play() return url_open = UrlOpen() url = self.file_object.get_subtitle_url(quality=self.selected_quality) filename = self.file_path.replace(".mp4", ".srt") url_open(url, filename=filename) print episode.file_hosts[host][quality] self.gui_manager.background_task(self.pre_download, self.play) self.downloader = Downloaders.get(host, self.gui_manager, episode.file_hosts[host][quality]) self.downloader.process_url(None, self.file_path) def pre_download(self): """ Downloads some content to start safely the player. """ while not os.path.exists(self.file_path): time.sleep(1) if self.downloader.file_size != 0: # Waits %1 of the total download percent = self.downloader.file_size * 0.01 while self.downloader.downloaded_size < percent: time.sleep(1) else: # Waits 2MB, just an arbitrary amount while self.downloader.downloaded_size < 2 * 1024 * 1024: time.sleep(0.5) def play(self): if self.video_item: return self.video_item = VideoItem('file://' + self.file_path, None) self.video_item.play(menuw=self.menuw) def get_filename(self, file_object): """ Returns the file path of the file. """ valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) result = "<show> <season>x<episode> <name>.mp4" result = result.replace("<show>", file_object.show.name) result = result.replace("<season>", "%.2d" % \ int(file_object.season.number)) result = result.replace("<episode>", "%s" % \ str(file_object.number)) result = result.replace("<name>", file_object.name) return result
def play(self): if self.video_item: return self.video_item = VideoItem('file://' + self.file_path, None) self.video_item.play(menuw=self.menuw)
def __init__(self, name, video_item): VideoItem.__init__(self, url=video_item.url, parent=video_item.parent) self.file_ops_no_delete_info = True self.update_item(name, video_item)