def _browse(self): """ Browse the shows from nrk/super """ categories = _console_select(NRK.categories(), ['title'], encoding=self.encoding) what_programs = [('Popular ' + categories[0].name, NRK.popular_programs), ('Recommended ' + categories[0].name, NRK.recommended_programs), ('Recent ' + categories[0].name, NRK.recent_programs) ] x = _console_select(what_programs, [0]) # this does not report S01E01 as it would require a extra apicall media_element = _console_select(x[0][1](categories[0].id), ['full_title'], encoding=self.encoding) # type_list should be a media object print('Found %s media elements' % len(media_element)) dl_all = False for m_e in media_element: if self.subs is True: m_e.subtitle() if dl_all is True: m_e.download() continue print(c_out('%s\n' % m_e.name)) print(c_out('%s\n' % m_e.description)) a = compat_input('Do you wish to download this? y/n/c/all\n') if a == 'y': m_e.download() elif a == 'all': m_e.download() dl_all = True elif a == 'c': break if self.downloads(): aa = compat_input('Download que is %s do you wish to download everything now? y/n\n' % len(self.downloads())) d = self.downloads() if aa == 'y': d.start() else: d.clear() return d else: return []
def _browse(self): """ Browse the shows from nrk/super """ categories = _console_select(NRK.categories(), ['title']) what_programs = [('Popular ' + categories[0].name, NRK.popular_programs), ('Recommended ' + categories[0].name, NRK.recommended_programs), ('Recent ' + categories[0].name, NRK.recent_programs) ] x = _console_select(what_programs, [0]) # this does not report S01E01 as it would require a extra apicall media_element = _console_select(x[0][1](categories[0].id), ['full_title']) # type_list should be a media object print('Found %s media elements' % len(media_element)) dl_all = False for m_e in media_element: if self.subs is True: m_e.subtitle() if dl_all is True: m_e.download() continue print(c_out('%s\n' % m_e.name)) print(c_out('%s\n' % m_e.description)) a = compat_input('Do you wish to download this? y/n/c/all\n') if a == 'y': m_e.download() elif a == 'all': m_e.download() dl_all = True elif a == 'c': break if self.downloads(): aa = compat_input('Download que is %s do you wish to download everything now? y/n\n' % len(self.downloads())) d = self.downloads() if aa == 'y': d.start() else: d.clear() return d else: return []
def expires_at(self, date=None, category=None, media_type=None): new = None if date is None: date = datetime.now().date() else: old, new = parse_datestring(date) if new is None: date = old.date() expires_soon = [] all_programs = self.site_rip() for media in all_programs: if media.type == 'serie' and media_type is None or media_type == 'serie': for ep in media.episodes(): if category and category != ep.category.name: continue if new: # We need to check ep is available because # it still be available_to but we cant download it.. if old <= ep.available_to <= new and ep.available: expires_soon.append(ep) elif ep.available_to.date() == date and ep.available: expires_soon.append(ep) else: if category and category != media.category.name: continue if media_type and media_type != media.type: continue if new: if old <= media.available_to <= new and media.available: expires_soon.append(media) elif media.available_to.date() == date and media.available: expires_soon.append(media) if expires_soon: print('%s expires today' % len(expires_soon)) eps = _console_select(expires_soon, ['full_title']) [m.download(os.path.join(self.save_path, str(date))) for m in eps] ip = compat_input('Download que is %s do you wish to download everything now? y/n\n' % len(self.downloads())) if ip == 'y': self.downloads().start()
def _console(self, q): """ Used by CLI """ to_download = [] all_stuff = [] response = self.search(q, raw=True) if response['hits'] is None: logging.info('Didnt find anything') return else: # use reverse since 0 is the closest match and i dont want to scoll for i, hit in reversed(list(enumerate(response['hits']))): if 'category' in hit['hit']: category = " [%s]" % c_out(hit['hit']['category']['title']) else: category = "" print('{0:>3}: {1}{2}'.format(i, c_out(hit['hit']['title']), category)) if self.include_description: if 'description' in hit['hit']: description = c_out(hit['hit']['description'][:110]).replace("\r"," ").replace("\n", " ") print(' {0}'.format(description)) # If there are more then one result, the user should pick a show if len(response['hits']) > 1: grab = compat_input('\nSelect a number or use slice notation\n') # Check if was slice.. if any(s in grab for s in (':', '::', '-')): grab = slice(*map(lambda x: int(x.strip()) if x.strip() else None, grab.split(':'))) search_res = response['hits'][grab] else: search_res = response['hits'][int(grab)] else: search_res = response['hits'][0] # check for a simgle item if isinstance(search_res, dict): search_res = [search_res] for sr in search_res: if sr['type'] == 'serie': # do some search object stuff.. id = sr['hit']['seriesId'] show = _fetch('series/%s' % id) # print(show['title']) # if we select a show, we should be able to choose all eps. if 'programs' in show: # Fix me, try to search for kash an it returns the wrong title. all_stuff = [Episode(e, name=show['title'], seasonIds=show['seasonIds']) for e in show['programs'] if e['isAvailable']] # Allow selection of episodes if self.include_description: description_arg = 'description' else: description_arg = None all_eps = _console_select(all_stuff, ['full_title'], encoding=ENCODING, description_arg=description_arg) if not isinstance(all_eps, list): all_eps = [all_eps] to_download += all_eps elif sr['type'] in ['program', 'episode']: to_download.append(_build(sr['hit'])) if to_download: for d in to_download: d.download() if self.subs is True: d.subtitle() if self.downloads(): self.downloads().start() return self.downloads() else: print('Nothing to download')
def _console(self, q): """ Used by CLI """ to_download = [] all_stuff = [] response = self.search(q, raw=True) if response['hits'] is None: logging.info('Didnt find anything') return else: # use reverse since 0 is the closest match and i dont want to scoll for i, hit in reversed(list(enumerate(response['hits']))): print('{0:>3}: {1}'.format(i, c_out(hit['hit']['title']))) # If there are more then one result, the user should pick a show if len(response['hits']) > 1: grab = compat_input('\nSelect a number or use slice notation\n') # Check if was slice.. if any(s in grab for s in (':', '::', '-')): grab = slice(*map(lambda x: int(x.strip()) if x.strip() else None, grab.split(':'))) search_res = response['hits'][grab] else: search_res = response['hits'][int(grab)] else: search_res = response['hits'][0] # check for a simgle item if isinstance(search_res, dict): search_res = [search_res] for sr in search_res: if sr['type'] == 'serie': # do some search object stuff.. id = sr['hit']['seriesId'] show = _fetch('series/%s' % id) print(show['title']) # if we select a show, we should be able to choose all eps. if 'programs' in show: # Fix me, try to search for kash an it returns the wrong title. all_stuff = [Episode(e, name=show['title'], seasonIds=show['seasonIds']) for e in show['programs'] if e['isAvailable']] # Allow selection of episodes all_eps = _console_select(all_stuff, ['full_title']) if not isinstance(all_eps, list): all_eps = [all_eps] to_download += all_eps elif sr['type'] in ['program', 'episode']: to_download.append(_build(sr['hit'])) if to_download: for d in to_download: d.download() if self.subs is True: d.subtitle() if self.downloads(): self.downloads().start() return self.downloads() else: print('Nothing to download')