def handle_item_complete(self, text, view, filterFunc=lambda i: True): text = text.lower() matches = [] for item in view: if item.get_title().lower().startswith(text) and filterFunc(item): matches.append(item.get_title()) return matches
def do_download(self, line): """download <name> -- Downloads an item by name in the feed/playlist selected.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == "downloading": print "%s is currently being downloaded" % item.get_title() elif item.is_downloaded(): print "%s is already downloaded" % item.get_title() else: item.download()
def do_download(self, line): """download <name> -- Downloads an item by name in the feed/playlist selected. """ if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == 'downloading': print '%s is currently being downloaded' % item.get_title() elif item.is_downloaded(): print '%s is already downloaded' % item.get_title() else: item.download()
def do_pause(self, line): """pause <name> -- Pauses a download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == "downloading": item.pause() else: print "%s is not being downloaded" % item.get_title()
def do_resume(self, line): """resume <name> -- Resumes a download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == "paused": item.resume() else: print "%s is not a paused download" % item.get_title()
def do_rm(self, line): """rm <name> -- Removes an item by name in the feed/playlist selected.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.is_downloaded(): item.expire() else: print "%s is not downloaded" % item.get_title()
def do_resume(self, line): """resume <name> -- Resumes a download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == 'paused': item.resume() else: print '%s is not a paused download' % item.get_title()
def do_pause(self, line): """pause <name> -- Pauses a download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() == 'downloading': item.pause() else: print '%s is not being downloaded' % item.get_title()
def do_stop(self, line): """stop <name> -- Stops download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() in ('downloading', 'paused'): item.expire() else: print '%s is not being downloaded' % item.get_title()
def do_stop(self, line): """stop <name> -- Stops download by name.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.get_state() in ("downloading", "paused"): item.expire() else: print "%s is not being downloaded" % item.get_title()
def do_play(self, line): """play <name> -- Plays an item by name in an external player.""" if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.is_downloaded(): resources.open_file(item.get_video_filename()) else: print "%s is not downloaded" % item.get_title()
def do_rm(self, line): """rm <name> -- Removes an item by name in the feed/playlist selected. """ if self.selection_type is None: print "Error: No feed/playlist selected." return item = self._find_item(line) if item is None: print "No item named %r" % line return if item.is_downloaded(): item.expire() else: print '%s is not downloaded' % item.get_title()
def printout_item_list(self, *views): totalItems = 0 for view in views: totalItems += view.count() if totalItems > 0: print "%-20s %-10s %s" % ("State", "Size", "Name") print "-" * 70 for view in views: for item in view: state = item.get_state() if state == "downloading": state += " (%0.0f%%)" % item.download_progress() print "%-20s %-10s %s" % (state, item.get_size_for_display(), item.get_title()) print else: print "No items"
def printout_item_list(self, *views): totalItems = 0 for view in views: totalItems += view.count() if totalItems > 0: print "%-20s %-10s %s" % ("State", "Size", "Name") print "-" * 70 for view in views: for item in view: state = item.get_state() if state == 'downloading': state += ' (%0.0f%%)' % item.download_progress() print "%-20s %-10s %s" % ( state, item.get_size_for_display(), item.get_title()) print else: print "No items"
def _item_info_for(self, item): if item.duration is None: duration = None else: duration = item.duration / 1000 info = dict( source_type='device', name=item.get_title(), feed_id = item.feed_id, feed_name = (item.feed_name is None and item.feed_name or self.device.name), parent_sort_key = None, feed_url = item.feed_url, state = u'saved', description = u'', release_date = item.get_release_date(), size = item.size, duration = duration, resume_time = 0, permalink = item.permalink, commentslink = item.comments_link, payment_link = item.payment_link, has_shareable_url = (item.url and not item.url.startswith('file://')), can_be_saved = False, pending_manual_dl = False, pending_auto_dl = False, expiration_date = None, item_viewed = True, downloaded = True, is_external = False, video_watched = True, video_path = item.get_filename(), thumbnail = item.get_thumbnail(), thumbnail_url = item.thumbnail_url or u'', file_format = item.file_format, license = item.license, file_url = item.url or u'', is_container_item = False, is_file_item = False, is_playable = True, children = [], file_type = item.file_type, subtitle_encoding = item.subtitle_encoding, seeding_status = None, mime_type = item.enclosure_type, artist = item.artist, date_added = item.get_creation_time(), last_played = item.get_creation_time(), download_info = None, device = item.device, remote = False, leechers = None, seeders = None, up_rate = None, down_rate = None, up_total = None, down_total = None, up_down_ratio = 0, play_count=0, skip_count=0, auto_rating=0, is_playing=item.is_playing) _add_metadata(info, item) return messages.ItemInfo(item.id, **info)
def test_democracy_now_bug(self): url = resources.url("testdata/democracy-now-unicode-bug.xml") my_feed = self.make_feed(url) self.force_feed_parser_callback(my_feed) for item in my_feed.items: u'booya' in item.get_title().lower()
def _item_info_for(item): info = { 'name': item.get_title(), 'feed_id': item.feed_id, 'feed_name': item.parent_title, 'parent_sort_key': item.get_parent_sort_key(), 'feed_url': item.get_feed_url(), 'state': item.get_state(), 'description': item.get_description(), 'release_date': item.get_release_date(), 'size': item.get_size(), 'duration': item.get_duration_value(), 'resume_time': item.resume_time, 'permalink': item.get_link(), 'commentslink': item.get_comments_link(), 'payment_link': item.get_payment_link(), 'has_shareable_url': item.has_shareable_url(), 'can_be_saved': item.show_save_button(), 'pending_manual_dl': item.is_pending_manual_download(), 'pending_auto_dl': item.is_pending_auto_download(), 'item_viewed': not item.new, 'downloaded': item.is_downloaded(), 'is_external': item.is_external(), 'video_watched': item.get_watched(), 'video_path': item.get_filename(), 'thumbnail': item.get_thumbnail(), 'thumbnail_url': item.get_thumbnail_url(), 'file_format': item.get_format(), 'license': item.get_license(), 'file_url': item.get_url(), 'is_container_item': item.is_container_item, 'is_file_item': item.is_file_item, 'is_playable': item.is_playable(), 'file_type': item.file_type, 'subtitle_encoding': item.subtitle_encoding, 'seeding_status': item.torrent_seeding_status(), 'mime_type': item.enclosure_type, 'date_added': item.get_creation_time(), 'last_played': item.get_watched_time(), 'last_watched': item.last_watched, 'downloaded_time': item.downloaded_time, 'children': [], 'expiration_date': None, 'download_info': None, 'leechers': None, 'seeders': None, 'up_rate': None, 'down_rate': None, 'up_total': None, 'down_total': None, 'up_down_ratio': 0.0, 'remote': False, 'device': None, 'source_type': 'database', 'play_count': item.play_count, 'skip_count': item.skip_count, 'auto_rating': item.get_auto_rating(), 'is_playing': item.is_playing(), } _add_metadata(info, item) if item.is_container_item: info['children'] = [DatabaseItemSource._item_info_for(i) for i in item.get_children()] if not item.keep and not item.is_external(): info['expiration_date'] = item.get_expiration_time() if item.downloader: info['download_info'] = messages.DownloadInfo(item.downloader) elif info['state'] == 'downloading': info['download_info'] = messages.PendingDownloadInfo() ## Torrent-specific stuff if item.looks_like_torrent() and item.downloader is not None: dler = item.downloader if item.is_transferring(): # gettorrentdetails only info['leechers'] = dler.leechers info['seeders'] = dler.seeders info['connections'] = dler.connections info['up_rate'] = dler.upload_rate info['down_rate'] = dler.rate # gettorrentdetailsfinished & gettorrentdetails info['up_total'] = dler.upload_size info['down_total'] = dler.current_size if info['down_total'] > 0: info['up_down_ratio'] = (float(info['up_total']) / info['down_total']) return messages.ItemInfo(item.id, **info)
def _item_info_for(item): info = { 'name': item.get_title(), 'feed_id': item.feed_id, 'feed_name': item.parent_title, 'parent_sort_key': item.get_parent_sort_key(), 'feed_url': item.get_feed_url(), 'state': item.get_state(), 'description': item.get_description(), 'release_date': item.get_release_date(), 'size': item.get_size(), 'duration': item.get_duration_value(), 'resume_time': item.resume_time, 'permalink': item.get_link(), 'commentslink': item.get_comments_link(), 'payment_link': item.get_payment_link(), 'has_shareable_url': item.has_shareable_url(), 'can_be_saved': item.show_save_button(), 'pending_manual_dl': item.is_pending_manual_download(), 'pending_auto_dl': item.is_pending_auto_download(), 'item_viewed': not item.new, 'downloaded': item.is_downloaded(), 'is_external': item.is_external(), 'video_watched': item.get_watched(), 'video_path': item.get_filename(), 'thumbnail': item.get_thumbnail(), 'thumbnail_url': item.get_thumbnail_url(), 'file_format': item.get_format(), 'license': item.get_license(), 'file_url': item.get_url(), 'is_container_item': item.is_container_item, 'is_file_item': item.is_file_item, 'is_playable': item.is_playable(), 'file_type': item.file_type, 'subtitle_encoding': item.subtitle_encoding, 'seeding_status': item.torrent_seeding_status(), 'mime_type': item.enclosure_type, 'date_added': item.get_creation_time(), 'last_played': item.get_watched_time(), 'last_watched': item.last_watched, 'downloaded_time': item.downloaded_time, 'children': [], 'expiration_date': None, 'download_info': None, 'leechers': None, 'seeders': None, 'up_rate': None, 'down_rate': None, 'up_total': None, 'down_total': None, 'up_down_ratio': 0.0, 'remote': False, 'device': None, 'source_type': 'database', 'play_count': item.play_count, 'skip_count': item.skip_count, 'auto_rating': item.get_auto_rating(), 'is_playing': item.is_playing(), } _add_metadata(info, item) if item.is_container_item: info['children'] = [ DatabaseItemSource._item_info_for(i) for i in item.get_children() ] if not item.keep and not item.is_external(): info['expiration_date'] = item.get_expiration_time() if item.downloader: info['download_info'] = messages.DownloadInfo(item.downloader) elif info['state'] == 'downloading': info['download_info'] = messages.PendingDownloadInfo() ## Torrent-specific stuff if item.looks_like_torrent() and item.downloader is not None: dler = item.downloader if item.is_transferring(): # gettorrentdetails only info['leechers'] = dler.leechers info['seeders'] = dler.seeders info['connections'] = dler.connections info['up_rate'] = dler.upload_rate info['down_rate'] = dler.rate # gettorrentdetailsfinished & gettorrentdetails info['up_total'] = dler.upload_size info['down_total'] = dler.current_size if info['down_total'] > 0: info['up_down_ratio'] = (float(info['up_total']) / info['down_total']) return messages.ItemInfo(item.id, **info)
def _item_info_for(self, item): if item.duration is None: duration = None else: duration = item.duration / 1000 info = dict(source_type='device', name=item.get_title(), feed_id=item.feed_id, feed_name=(item.feed_name is None and item.feed_name or self.device.name), parent_sort_key=None, feed_url=item.feed_url, state=u'saved', description=u'', release_date=item.get_release_date(), size=item.size, duration=duration, resume_time=0, permalink=item.permalink, commentslink=item.comments_link, payment_link=item.payment_link, has_shareable_url=(item.url and not item.url.startswith('file://')), can_be_saved=False, pending_manual_dl=False, pending_auto_dl=False, expiration_date=None, item_viewed=True, downloaded=True, is_external=False, video_watched=True, video_path=item.get_filename(), thumbnail=item.get_thumbnail(), thumbnail_url=item.thumbnail_url or u'', file_format=item.file_format, license=item.license, file_url=item.url or u'', is_container_item=False, is_file_item=False, is_playable=True, children=[], file_type=item.file_type, subtitle_encoding=item.subtitle_encoding, seeding_status=None, mime_type=item.enclosure_type, artist=item.artist, date_added=item.get_creation_time(), last_played=item.get_creation_time(), download_info=None, device=item.device, remote=False, leechers=None, seeders=None, up_rate=None, down_rate=None, up_total=None, down_total=None, up_down_ratio=0, play_count=0, skip_count=0, auto_rating=0, is_playing=item.is_playing) _add_metadata(info, item) return messages.ItemInfo(item.id, **info)
def _find_item(self, line): line = line.lower() for item in self._get_item_view(): if item.get_title().lower() == line: return item