def iter_resources(self, objs, split_path): if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'comingsoon'], u'Films prochainement au cinéma') yield Collection([u'nowshowing'], u'Films au cinéma') yield Collection([u'acshow'], u'Émissions') yield Collection([u'interview'], u'Interviews') if collection.path_level == 1: if collection.basename == u'acshow': emissions = self.browser.get_emissions(collection.basename) if emissions: for emission in emissions: yield emission elif collection.basename == u'interview': videos = self.browser.get_categories_videos( collection.basename) if videos: for video in videos: yield video else: videos = self.browser.get_categories_movies( collection.basename) if videos: for video in videos: yield video if collection.path_level == 2: videos = self.browser.get_categories_videos(':'.join( collection.split_path)) if videos: for video in videos: yield video
def iter_resources(self, objs, split_path): if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'arte-latest'], u'Latest Arte videos') for site in SITE.values: yield Collection([site.get('id')], site.get('label')) if collection.path_level == 1: if collection.split_path == [u'arte-latest']: for video in self.browser.latest_videos(): yield video else: for site in SITE.values: if collection.split_path[0] == site.get( 'id') and collection.path_level in site.keys(): for item in getattr( self.browser, site.get(collection.path_level))(): yield item if collection.path_level >= 2: for site in SITE.values: if collection.split_path[0] == site.get( 'id') and collection.path_level in site.keys(): for item in getattr(self.browser, site.get(collection.path_level))( collection.split_path): yield item
def iter_resources(self, objs, split_path): with self.browser: if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'arte-latest'], u'Latest Arte videos') yield Collection([u'arte-live'], u'Arte Web Live videos') yield Collection([u'arte-program'], u'Arte Programs') if collection.path_level == 1: if collection.split_path == [u'arte-latest']: yield from self.browser.latest_videos() if collection.split_path == [u'arte-live']: yield from self.browser.get_arte_live_categories() if collection.split_path == [u'arte-program']: for item in self.browser.get_arte_programs(): lang = self.TRANSLATION[self.config['lang'].get()] if lang == 'D': title = 'titleDE' elif lang == 'F': title = 'titleFR' else: title = 'name' name = item['clusterId'] if title in item.keys(): name = item[title] yield Collection([u'arte-program', item['clusterId']], u'%s' % name) if collection.path_level == 2: if collection.split_path[0] == u'arte-live': yield from self.browser.live_videos(collection.basename) if collection.split_path[0] == u'arte-program': yield from self.browser.program_videos(collection.split_path[1])
def iter_resources_root(self, objs): return [ Collection(['hot'], 'Hot threads'), Collection(['new'], 'New threads'), Collection(['rising'], 'Rising threads'), Collection(['controversial'], 'Controversial threads'), Collection(['top'], 'Top threads'), ]
def validate_collection(self, objs, collection): if collection.path_level == 0: return if Issue in objs and collection.path_level == 1: for project in self.iter_projects(): if collection.basename == project.id: return Collection([project.id], project.name) # if the project is not found by ID, try again by name for project in self.iter_projects(): if collection.basename == project.name: return Collection([project.id], project.name) raise CollectionNotFound(collection.split_path)
def iter_resources(self, objs, split_path): collection = self.get_collection(objs, split_path) if collection.path_level == 0: if self.config['username'].get(): yield Collection([u'me'], u'me') yield Collection([u'profils'], u'profils') yield Collection([u'trendy'], u'trendy') yield Collection([u'hashtags'], u'hashtags') yield Collection([u'search'], u'search') if collection.path_level == 1: if collection.split_path[0] == u'me': for el in self.browser.get_tweets_from_profil(self.browser.get_me()): yield el if collection.split_path[0] == u'profils': profils = self.config['profils_subscribe'].get() if profils: for profil in profils.split(','): yield Collection([profil], profil) if collection.split_path[0] == u'hashtags': hashtags = self.config['hashtags_subscribe'].get() if hashtags: for hashtag in hashtags.split(','): yield Collection([hashtag], hashtag) if collection.split_path[0] == u'search': searchs = self.config['search_subscribe'].get() if searchs: for search in searchs.split(','): yield Collection([search], search) if collection.split_path[0] == u'trendy': for obj in self.browser.get_trendy_subjects(): yield Collection([obj.id], obj.id) if collection.path_level == 2: if collection.split_path[0] == u'profils': for el in self.browser.get_tweets_from_profil(collection.split_path[1]): yield el if collection.split_path[0] == u'trendy': if collection.split_path[1].startswith('#'): for el in self.browser.get_tweets_from_hashtag(collection.split_path[1]): yield el else: for el in self.browser.get_tweets_from_search(collection.split_path[1]): yield el if collection.split_path[0] == u'hashtags': for el in self.browser.get_tweets_from_hashtag(collection.split_path[1]): yield el if collection.split_path[0] == u'search': for el in self.browser.get_tweets_from_search(collection.split_path[1]): yield el
def iter_category(self): subs = list() for el in self.document.xpath('//ul/li[@data-role="list-divider"]'): if el.text not in subs: yield Collection([el.text], unicode(el.text)) subs.append(el.text)
def get_arte_cinema_categories(self, cat=[]): menu = self.videos_list.go(site=SITE.CINEMA.get('id'), lang=self.lang.get('site'), cat='').get_arte_cinema_menu() menuSplit = map(lambda x: x.split("/")[2:], menu) result = {} for record in menuSplit: here = result for item in record[:-1]: if item not in here: here[item] = {} here = here[item] if "end" not in here: here["end"] = [] here["end"].append(record[-1]) cat = cat if not cat else cat[1:] if not cat and "end" in result: del result["end"] for el in cat: result = result.get(el) if "end" in result.keys(): return self.page.iter_arte_cinema_categories(cat='/'.join(cat)) else: categories = [] for item in result.keys(): categories.append( Collection([SITE.CINEMA.get('id'), unicode(item)], unicode(item))) return categories
def iter_resources(self, objs, split_path): collection = self.get_collection(objs, split_path) if BaseVideo in objs: if collection.path_level == 0: return [Collection([site.get('id')], site.get('label')) for site in SITE.values] elif len(split_path) == 1: site = get_site_enum_by_id(split_path[0]) subsite = site.get('enum', None) if site == SITE.PROGRAM: return self.browser.get_arte_programs(split_path) elif site == SITE.GUIDE: return self.browser.get_arte_guide_days(split_path) elif site == SITE.CREATIVE: return self.browser.get_arte_creative_videos() elif subsite: return self.browser.get_arte_generic_subsites(split_path, subsite) elif collection.path_level > 1: site = get_site_enum_by_id(split_path[0]) if site == SITE.GUIDE: return self.browser.get_arte_guide_videos(split_path) else: subsite = site.get('enum', {}) if subsite: subsite = dict(subsite.items) return self.browser.get_arte_navigation(split_path, subsite.get('COLLECTION', {}).get('id', r''), subsite.get('PLAYLIST', {}).get('id', r''), subsite.get('MAGAZINE', {}).get('id', r''))
def create_collection_from_playlists_result(self, playlists, split_path): items = list() for playlist in playlists: path = copy.deepcopy(split_path) path.append(u'%s' % playlist['PlaylistID']) items.append(Collection(path, u'%s' % (playlist['Name']))) return items
def iter_resources(self): items = [] for el in self.document.xpath('//ul[@class="filter-liste"]/li'): _id = el.attrib['data-target'].replace('video_box_tab_', '') text = self.parser.select(el, 'a/span', 1, method='xpath').text item = Collection([u'arte-live', u'%s' % _id], u'%s' % (text)) items.append(item) return items
def get_channels(self): """ Extract all possible channels (paths) from the page """ channels = list() for elem in self.doc[2].getchildren(): for e in elem.getchildren(): if e.tag == "NOM": fid, name = self._clean_name(e.text) channels.append(Collection([fid], name)) elif e.tag == "SELECTIONS": for select in e: sub_fid, subname = self._clean_name(select[1].text) sub = Collection([fid, sub_fid], subname) sub._link_id = select[0].text channels.append(sub) return channels
def iter_courses(self): for c in self.doc.xpath('//article[@class="course"]'): title = c.xpath('.//h3[@class="course-title"]/a')[0].text.strip() link = c.xpath('.//a[contains(@class,"enter-course")]')[0] url = self.browser.absurl(link.get('href')) match = self.browser.course.match(url) courseid = match.group('course').replace('/', '-') yield Collection([courseid], title)
def iter_resources(self): for metadata in self.doc['items']: if metadata['type'] == 'c': collection = Collection([metadata['oid']], metadata['title']) yield collection if metadata['type'] == 'v': video = create_video(metadata) yield video
def iter_resources(self, objs, split_path): if Project in objs or Issue in objs: self._restrict_level(split_path, 1) if len(split_path) == 0: return [Collection([project.id], project.name) for project in self.iter_projects()] elif len(split_path) == 1: query = Query() query.project = unicode(split_path[0]) return self.iter_issues(query)
def create_collection_from_albums_result(self, albums, split_path): items = list() for album in albums: path = copy.deepcopy(split_path) path.append(u'%s' % album['AlbumID']) items.append( Collection( path, u'%s - %s' % (album['AlbumName'], album['ArtistName']))) return items
def iter_resources(self, objs, split_path): if BaseVideo in objs: if len(split_path) == 0: # Add fake Collection yield Collection(['latest'], u'Latest') if len(split_path) == 1 and split_path[0] == 'latest': for video in self.browser.get_latest_videos(): yield video else: for content in self.browser.get_channel_videos(split_path): yield content
def iter_resources(self, objs, split_path): self._fetch_radio_list() if Radio in objs: for network in self.config['networks'].get().split(): if split_path == [network]: for radio in self.RADIOS[network]: yield self.get_radio(radio+"."+network) return for network in self.config['networks'].get().split(): yield Collection([network], self.NETWORKS[network]['desc'])
def iter_resources(self, split_path): if 'channels' in self.doc: for metadata in self.doc['channels']: collection = Collection(split_path + [metadata['oid']], metadata['title']) yield collection if 'videos' in self.doc: for metadata in self.doc['videos']: video = create_video(metadata) yield video
def iter_resources(self, objs, split_path): with self.browser: if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'theme'], u'Par theme') yield Collection([u'type'], u'Par type') yield Collection([u'latest'], u'Latest NolifeTV videos') if collection.path_level == 1: if split_path[0] == 'latest': for vid in self.browser.get_latest(): yield vid else: for cat in self.browser.iter_category(split_path[0]): yield cat if collection.path_level == 2: for cat in self.browser.iter_family(split_path[0], split_path[1]): yield cat if collection.path_level == 3: for cat in self.browser.iter_video(split_path[2]): yield cat
def iter_resources(self, objs, split_path): with self.browser: if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'latest'], u'Latest Arte videos') yield Collection([u'live'], u'Arte Web Live videos') if collection.path_level == 1: if collection.split_path == [u'latest']: for video in self.browser.latest_videos(): yield video if collection.split_path == [u'live']: for categorie in self.browser.get_arte_live_categories( ): yield categorie if collection.path_level == 2: if collection.split_path[0] == u'live': for video in self.browser.live_videos( ArteLiveCollection.id2url( collection.basename, self.browser.lang)): yield video
def iter_resources(self, objs, split_path): if Radio in objs: if split_path == [u'francebleu']: for _id in sorted(self._RADIOS.iterkeys()): if _id.startswith('fb'): yield self.get_radio(_id) elif len(split_path) == 0: for _id in sorted(self._RADIOS.iterkeys()): if not _id.startswith('fb'): yield self.get_radio(_id) yield Collection([u'francebleu'], u'France Bleu') else: raise CollectionNotFound(split_path)
def get_emissions(self, basename): params = [ ('partner', self.PARTNER_KEY), ('format', 'json'), ('filter', 'acshow'), ] result = self.__do_request('termlist', params) if result is None: return for emission in result['feed']['term']: yield Collection( [basename, unicode(emission['nameShort'])], unicode(emission['$']))
def iter_resources(self, objs, split_path): if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'vimeo-categories'], u'Vimeo categories') yield Collection([u'vimeo-channels'], u'Vimeo channels') if collection.path_level == 1: if collection.split_path == [u'vimeo-categories']: for category in self.browser.get_categories(): yield category if collection.split_path == [u'vimeo-channels']: for channel in self.browser.get_channels(): yield channel if collection.path_level == 2: if collection.split_path[0] == u'vimeo-channels': for video in self.browser.get_channel_videos(collection.split_path[1]): yield video if collection.split_path[0] == u'vimeo-categories': for video in self.browser.get_category_videos(collection.split_path[1]): yield video
def iter_resources(self, objs, split_path): if BaseVideo in objs: collection = self.get_collection(objs, split_path) if collection.path_level == 0: yield Collection([u'videos'], u'Vidéos') for category in self.browser.get_categories(): if category.path_level == 1: yield category elif collection.path_level > 0 and split_path[-1] == u'videos': for v in self.browser.iter_videos("/".join( collection.split_path[:-1])): yield v elif collection.path_level == 1: yield Collection(collection.split_path + [u'videos'], u'Vidéos') for category in self.browser.get_subcategories( collection.split_path[0]): yield category elif collection.path_level == 2: if split_path[-1] == u'replay-videos': for v in self.browser.iter_videos("/".join( collection.split_path)): yield v else: for category in self.browser.get_emissions( collection.split_path): yield category elif collection.path_level == 3: for v in self.browser.iter_videos("/".join( [collection.split_path[0], collection.split_path[-1]])): yield v
def iter_family(self, sub): for el in self.document.xpath('//ul/li[@data-role="list-divider"]'): if el.text != sub: continue while True: el = el.getnext() if el is None or el.get('data-role'): break h1 = el.find('.//h1') id = h1.getparent().attrib['href'] m = re.search(r'famille-(\d+)', id) if m and m.group(1): yield Collection([m.group(1)], unicode(h1.text))
def get_feeds(self, label): for category in self.doc: if category.get('label') == label: feeds = category.get('subscriptions') for feed in feeds: yield Collection([label, feed.get('title')])
def get_categories(self): for category in self.doc: name = u'%s' % category.get('label') yield Collection([name], name)
def get_logged_categories(self): user_categories = list(self.preferences.go().get_categories()) user_categories.append(Collection([u'global.saved'], u'Saved')) return user_categories
def get_categories(self): for category, value in self.doc.items(): if value in [u"shown", u"hidden"]: yield Collection([u'%s' % category], u'%s' % category.replace('global.', ''))