def get_video_docs(): """This function gets the Documentals video list from the main page website.""" section_sep = '<div id="docs">' entry_pattern = '<article class="illustrated">(.*?)</article>' video_entry_title = '<h2><a href="[^>]*?>(.*?)</a></h2>' video_entry_themes = ' rel="tag">(.*?)</a>' video_entry_views = '<li class="views"><span>(.*?)<span class="for-reader">(.*?)</span></span></li>' video_entry_rating = 'ratings_off\(([^,]*?)' video_entry_url = '<a href="([^"]*?)"><img width="[^"]*?" height="[^"]*?" src="([^"]*?)"' video_entry_plot = '<div class="chapeau">.*?<p>(.*?)</p>' video_entry_date = '<span class="date"><time datetime="([^T]*?)T[^"]*?">(.*?)</time>' video_entry_author = '<span class="author">(.*?)<a href="[^>]*?>(.*?)</a>' root_url = 'http://latelelibre.fr/' buffer_url = l.carga_web(root_url) video_list = [] docs_contents = buffer_url.split(section_sep)[1] or '' for video_entry in l.find_multiple(docs_contents, entry_pattern): title = l.find_first(video_entry, video_entry_title) url, thumb = l.find_first(video_entry, video_entry_url) or ('', '') views = "%s%s" % l.find_first(video_entry, video_entry_views) or ('', '') rating = l.find_first(video_entry, video_entry_rating) plot = l.find_first(video_entry, video_entry_plot) timestamp, date = l.find_first(video_entry, video_entry_date) or ('', '') author_label, author = l.find_first(video_entry, video_entry_author) or ('', '') theme_list = '' for itheme in l.find_multiple(video_entry, video_entry_themes): theme_list = '%s %s' % (theme_list, itheme) year, month, day = timestamp.split('-') or ('', '', '') l.log('Video info. title: "%s"\nviews: "%s" timestamp: "%s" date: "%s" author: "%s"' % (title, views, timestamp, date, author)) video_entry = { 'url' : url, 'title' : "%s (%s/%s/%s)" % ( get_clean_title(title), day, month, year, ), 'thumbnail' : l.sanitize_url(thumb), 'plot' : "%s\n%s\n%s %s %s %s %s" % ( get_clean_title(plot), date, theme_list, views, rating, get_clean_title(author_label), author ), 'rating' : rating, 'genre' : theme_list.strip(), 'year' : year, 'credits' : author, 'IsPlayable' : True } video_list.append(video_entry) return video_list
def get_video_docs(): """This function gets the Documentals video list from the main page website.""" section_sep = '<div id="docs">' entry_pattern = '<article class="illustrated">(.*?)</article>' video_entry_title = '<h2><a href="[^>]*?>(.*?)</a></h2>' video_entry_themes = ' rel="tag">(.*?)</a>' video_entry_views = '<li class="views"><span>(.*?)<span class="for-reader">(.*?)</span></span></li>' video_entry_rating = 'ratings_off\(([^,]*?)' video_entry_url = '<a href="([^"]*?)"><img width="[^"]*?" height="[^"]*?" src="([^"]*?)"' video_entry_plot = '<div class="chapeau">.*?<p>(.*?)</p>' video_entry_date = '<span class="date"><time datetime="([^T]*?)T[^"]*?">(.*?)</time>' video_entry_author = '<span class="author">(.*?)<a href="[^>]*?>(.*?)</a>' buffer_url = l.carga_web(root_url) video_list = [] docs_contents = buffer_url.split(section_sep)[1] or '' for video_entry in l.find_multiple(docs_contents, entry_pattern): title = l.find_first(video_entry, video_entry_title) url, thumb = l.find_first(video_entry, video_entry_url) or ('', '') views = "%s%s" % l.find_first(video_entry, video_entry_views) or ('', '') rating = l.find_first(video_entry, video_entry_rating) plot = l.find_first(video_entry, video_entry_plot) timestamp, date = l.find_first(video_entry, video_entry_date) or ('', '') author_label, author = l.find_first(video_entry, video_entry_author) or ('', '') theme_list = '' for itheme in l.find_multiple(video_entry, video_entry_themes): theme_list = '%s %s' % (theme_list, itheme) year, month, day = timestamp.split('-') or ('', '', '') l.log('Video info. title: "%s"\nviews: "%s" timestamp: "%s" date: "%s" author: "%s"' % (title, views, timestamp, date, author)) video_entry = { 'url' : url, 'title' : "%s (%s/%s/%s)" % ( l.get_clean_title(title), day, month, year, ), 'thumbnail' : sanitize_url(thumb), 'plot' : "%s\n%s\n%s %s %s %s %s" % ( l.get_clean_title(plot), date, theme_list, views, rating, l.get_clean_title(author_label), author ), 'rating' : rating, 'genre' : theme_list.strip(), 'year' : year, 'credits' : author, 'IsPlayable' : True } video_list.append(video_entry) return video_list
def main_list(params): lutil.log("eso.main_list "+repr(params)) # Loads the web page from ESO with the video list. page_url = params.get("url") reset_cache = params.get("reset_cache") genre = params.get("genre") array_index = 0 if eso_url in page_url else 1 root_url = (eso_url, space_url)[array_index] buffer_web = lutil.carga_web(page_url) # Extract video items from the html content pattern_nextpage = '<a href="([^"]*?)">Next</a>' pattern_prevpage = '<a href="([^"]*?)">Previous</a>' pattern_lastpage = '<a href="[^"]*?">([0-9]+)</a>' pattern_pagenum = '/([0-9]+)/' pattern_videos = ('</span><img src="([^"]+)" class="[^"]+" alt="([^"]+)">.*?<a href="(/public/videos/[^"]*?)">', '</span><img src="([^"]+)" class="[^"]+" alt="([^"]+)">.*?<a href="(/videos/[^"]*?)">')[array_index] lutil.set_content_list(pluginhandle, 'tvshows') lutil.set_plugin_category(pluginhandle, genre) # We must setup the previous page entry from the second page onwards. prev_page_url = lutil.find_first(buffer_web, pattern_prevpage) if prev_page_url: prev_page = lutil.find_first(prev_page_url, pattern_pagenum) lutil.log('eso.main_list Value of prev_page: %s prev_page_url: "%s%s"' % (prev_page, root_url, prev_page_url)) prev_page_url = "%s%s" % (root_url, prev_page_url.replace('&', '&').replace('"', '"')) reset_cache = "yes" lutil.addDir(action="main_list", title="<< %s (%s)" % (translation(30106), prev_page), url=prev_page_url, reset_cache=reset_cache, genre=genre) # This is to force ".." option to go back to main index instead of previous page list. updateListing = reset_cache == "yes" for thumbnail, title, video_link in lutil.find_multiple(buffer_web, pattern_videos): video_info = {} url = '%s%s' % (root_url, video_link) if not thumbnail.startswith('http'): thumbnail = '%s%s' % (root_url, thumbnail) title = title.strip().replace('"', '"').replace(''', '´').replace('&', '&') # Cleanup the title. video_info['Genre'] = genre video_info['Plot'] = title # Appends a new item to the xbmc item list lutil.addLink(action="play_video", title=title, url=url, thumbnail=thumbnail, video_info=video_info) # Here we get the next page URL to add it at the end of the current video list page. next_page_url = lutil.find_first(buffer_web, pattern_nextpage) if next_page_url: last_page = lutil.find_multiple(buffer_web, pattern_lastpage)[-1] next_page = lutil.find_first(next_page_url, pattern_pagenum) lutil.log('eso.main_list Value of next_page: %s last_page: %s next_page_url: "%s%s"' % (next_page, last_page, root_url, next_page_url)) next_page_url = "%s%s" % (root_url, next_page_url.replace('&', '&').replace('"', '"')) lutil.addDir(action="main_list", title=">> %s (%s/%s)" % (translation(30010), next_page, last_page), url=next_page_url, reset_cache=reset_cache, genre=genre) lutil.close_dir(pluginhandle, updateListing=updateListing)
def main_list(params): lutil.log("eso.main_list "+repr(params)) # Loads the web page from ESO with the video list. page_url = params.get("url") reset_cache = params.get("reset_cache") genre = params.get("genre") array_index = 0 if eso_url in page_url else 1 root_url = (eso_url, space_url)[array_index] buffer_web = lutil.carga_web(page_url) # Extract video items from the html content pattern_nextpage = '<a href="([^"]*?)">Next</a>' pattern_prevpage = '<a href="([^"]*?)">Previous</a>' pattern_lastpage = '<a href="[^"]*?">([0-9]+)</a>' pattern_pagenum = '/([0-9]+)/' pattern_videos = ('</span><img src="([^"]+)" class="[^"]+" alt="([^"]+)">.*?<a href="(/public/videos/[^"]*?)">', '</span><img src="([^"]+)" class="[^"]+" alt="([^"]+)">.*?<a href="(/videos/[^"]*?)">')[array_index] lutil.set_content_list(pluginhandle, 'tvshows') lutil.set_plugin_category(pluginhandle, genre) # We must setup the previous page entry from the second page onwards. prev_page_url = lutil.find_first(buffer_web, pattern_prevpage) if prev_page_url: prev_page = lutil.find_first(prev_page_url, pattern_pagenum) lutil.log('eso.main_list Value of prev_page: %s prev_page_url: "%s%s"' % (prev_page, root_url, prev_page_url)) prev_page_url = "%s%s" % (root_url, prev_page_url.replace('&', '&').replace('"', '"')) reset_cache = "yes" lutil.addDir(action="main_list", title="<< %s (%s)" % (translation(30106), prev_page), url=prev_page_url, reset_cache=reset_cache, genre=genre) # This is to force ".." option to go back to main index instead of previous page list. updateListing = reset_cache == "yes" for thumbnail, title, video_link in lutil.find_multiple(buffer_web, pattern_videos): video_info = {} url = '%s%s' % (root_url, video_link) if not 'http:' in thumbnail: thumbnail = '%s%s' % (root_url, thumbnail) title = title.strip().replace('"', '"').replace(''', '´').replace('&', '&') # Cleanup the title. video_info['Genre'] = genre video_info['Plot'] = title # Appends a new item to the xbmc item list lutil.addLink(action="play_video", title=title, url=url, thumbnail=thumbnail, video_info=video_info) # Here we get the next page URL to add it at the end of the current video list page. next_page_url = lutil.find_first(buffer_web, pattern_nextpage) if next_page_url: last_page = lutil.find_multiple(buffer_web, pattern_lastpage)[-1] next_page = lutil.find_first(next_page_url, pattern_pagenum) lutil.log('eso.main_list Value of next_page: %s last_page: %s next_page_url: "%s%s"' % (next_page, last_page, root_url, next_page_url)) next_page_url = "%s%s" % (root_url, next_page_url.replace('&', '&').replace('"', '"')) lutil.addDir(action="main_list", title=">> %s (%s/%s)" % (translation(30010), next_page, last_page), url=next_page_url, reset_cache=reset_cache, genre=genre) lutil.close_dir(pluginhandle, updateListing=updateListing)
def play_video(params): lutil.log("eso.play "+repr(params)) page_url = params.get("url") buffer_link = lutil.carga_web(page_url) pattern_video = '<span class="archive_dl_text"><a href="([^"]*?)"' quality_list = { 'UltraHD' : 'ultra_hd/', 'HD' : 'hd_and_apple', 'SD': 'medium_podcast' } video_list = [url for url in lutil.find_multiple(buffer_link, pattern_video) if not url.endswith(('zip','srt','pdf','mxf','wav'))] lutil.log("eso.play video list"+repr(video_list)) video_options = dict((vquality, url) for url in video_list for vquality in quality_list.keys() if quality_list[vquality] in url) lutil.log("eso.play video options"+repr(video_options)) video_url = video_options.get('%s' % ('SD', 'HD', 'UltraHD')[quality], '') or video_options.get('SD', '') or video_list[0] if len(video_list) else '' if video_url: if video_url.startswith('//'): video_url = "%s%s" % ('http:', video_url) elif video_url.startswith('/'): root_url = eso_url if eso_url in page_url else space_url video_url = "%s%s" % (root_url, video_url) try: lutil.log("eso.play: We have found this video: '%s' and let's going to play it!" % video_url) return lutil.play_resolved_url(pluginhandle = pluginhandle, url = video_url) except: lutil.log('eso.play ERROR: we cannot reproduce this video URL: "%s"' % video_url) return lutil.showWarning(translation(30012)) else: lutil.log('eso.play ERROR: we cannot play the video from this source yet: "%s"' % params.get("url")) return lutil.showWarning(translation(30011))
def main_list(params): lutil.log("tv5monde.main_list "+repr(params)) # Loads the list of videos of the selected category based on the json object retrieved from the server. buffer_json = lutil.get_json(params.get("url")) pattern_videos = '<a title="([^"]+)" href="/video/([^/]+)/[^"]+"> <img src="([^"]+)" .*?<div class="bookmark" id="book_([0-9]+)">' videolist = lutil.find_multiple(buffer_json['content'], pattern_videos) for title, day, thumbnail, videoid in videolist: video_url = 'http://www.tv5mondeplus.com/video-xml/get/%s' % videoid title = title.replace('"', '"') lutil.log('videolist: URL: "%s" Descripcion: "%s" Date: "%s" Thumbnail: "%s"' % (video_url, title, day, thumbnail)) plot = title lutil.addLink(action="play_video", title='%s (%s)' % (title, day), plot=plot, url=video_url, thumbnail=thumbnail) if buffer_json['pager'] is not None: pattern_page = 'pg=([0-9]+)' pattern_total = '<ul class="pager" total="([0-9]+)"' pattern_genre = 'sort=([0-9]+)' last_page = int(lutil.find_first(buffer_json['pager'], pattern_total)) - 1 next_page = int(lutil.find_first(params.get("url"), pattern_page)) + 1 if last_page != next_page: genre = lutil.find_first(params.get("url"), pattern_genre) next_page_url = 'http://www.tv5mondeplus.com/get/videos?pg=%s&type=genre&sort=%s&loadpg=false&order=date' % (next_page, genre) lutil.log('next_page=%s last_page=%s next_page_url="%s"' % (next_page, last_page, next_page_url)) lutil.addDir(action="main_list", title=">> %s" % translation(30010), url=next_page_url) lutil.close_dir(pluginhandle)
def index(params): lutil.log("tv5monde.index "+repr(params)) url = 'http://www.tv5mondeplus.com/videos' buffer_html = lutil.carga_web(url) list_pattern = '<div id="tri-par-genre"(.+?)</ul>' lista_genre = lutil.find_first(buffer_html, list_pattern) genre_pattern = '<li><a id="([0-9]+)" [^>]+>([^<]+)<' for genre, label in lutil.find_multiple(lista_genre, genre_pattern): genre_url = 'http://www.tv5mondeplus.com/get/videos?pg=0&type=genre&sort=%s&loadpg=false&order=date' % genre lutil.log('tv5monde.index url=["%s"] genre=["%s"]' % (genre_url, label)) lutil.addDir(action="main_list", title=label, url=genre_url) lutil.close_dir(pluginhandle)
def get_playable_dailymotion_url(video_id): """This function returns the playable URL for the Dalymotion embedded video from the video_id retrieved.""" daily_video_pattern = '"([0-9]+)":\[[^]]*?{"type":"video\\\/mp4","url":"([^"]+?)"' daily_video_qualities = ('480', '720', '380', '240') daily_url = 'http://www.dailymotion.com/embed/video/' + video_id buffer_link = l.carga_web(daily_url) video_options = dict((quality, video) for quality, video in l.find_multiple(buffer_link, daily_video_pattern)) l.log("List of video options: "+repr(video_options)) for quality_option in daily_video_qualities: if quality_option in video_options: video_url = video_options.get(quality_option).replace('\\','') return video_url return ""
def get_categories(): """This function gets the categories list from the FFA website.""" category_pattern = "'topic', '([0-9]+)'[^>]+?>([^<]+?)</a>" category_url = 'https://www.filmsforaction.org/library/?category=all+videos&topic=%s' buffer_url = l.carga_web(root_url) category_list = [] topic_list = [] for topic, category_name in l.find_multiple(buffer_url, category_pattern): if topic not in topic_list: url = category_url % topic category_list.append((url, category_name)) topic_list.append(topic) return category_list
def get_channels_menu(html_channels): """This function makes the program menu parammeters data structure for all the channel menus.""" channel_pattern = '<li class="rn."><a href="([^"]*?)" rel="nofollow"><span></span><strong>([^<]*?)</strong></a></li>' menu_level = [] for url, channel in l.find_multiple(html_channels, channel_pattern): menu_item = { 'action': 'program_list', 'title': channel, 'args': root_url + url, } menu_level.append(menu_item) return menu_level
def other_categories(params): lutil.log("esa.other_categories "+repr(params)) action = 'main_list' page_url = 'http://www.esa.int/spaceinvideos/Videos' buffer_web = lutil.carga_web(page_url) category_pattern = '<a href="(/spaceinvideos/Directorates/[^"]*?)">([^<]*?)</a>' for category_link, title in lutil.find_multiple(buffer_web, category_pattern): url = '%s%s/(sortBy)/%s' % (root_url, category_link, sort_method) title = title.replace('"', '"').replace(''', '´').replace('&', '&') # Cleanup the title. lutil.log('esa.other_categories action=["%s"] title=["%s"] url=["%s"]' % (action, title, url)) lutil.addDir(action=action, title=title, url=url, genre=title) lutil.close_dir(pluginhandle, updateListing=False)
def get_two_level_menu(html): """This function makes the two level menu parammeters data structure for all the menu sections.""" menu_pattern = '<span>(Podcasts por [gc][^<]*?)</span>(.*?)</div></div></div>' menu_entry_pat = '<li> <a href="([^"]*?)" [^>]*?>([^<]*?)</a>' menu_level = [] for menu_title, menu_body in l.find_multiple(html, menu_pattern): nested_menu = '¡'.join(['%s¿%s' % (url, get_clean_title(label)) for url, label in l.find_multiple(menu_body, menu_entry_pat)]) menu_item = { 'action' : 'menu_sec', 'title' : get_clean_title(menu_title), 'args' : nested_menu, } menu_level.append(menu_item) return menu_level
def create_index(params): lutil.log("eso.create_index "+repr(params)) action = 'main_list' # All Videos entry url = params.get("url", 'http://www.eso.org/public/videos/list/1/') + sort_url_param title = translation(30107) genre = 'All the Videos' lutil.log('eso.create_index action=["%s"] title=["All the Videos"] url=["%s"]' % (action, url)) lutil.addDir(action=action, title=title, url=url, genre=genre) array_index = 0 if eso_url in url else 1 root_url = (eso_url, space_url)[array_index] buffer_web = lutil.carga_web(url) pattern_genre= ('<a href="(/public/videos/archive/category/[^"]+)">([^<]+)</a>', '<a href="(/videos/archive/category/[^"]+)">([^<]+)</a>')[array_index] # Category list # This is a hack to avoid repeat the category list at the same time it uses the old order list. category_list = [] for genre_url, genre_title in lutil.find_multiple(buffer_web, pattern_genre): url = '%s%s%s' % (root_url, genre_url, '' if 'sort=' in genre_url else sort_url_param) title = genre_title.strip().replace('"', '"').replace(''', '´').replace('&', '&') # Cleanup the title. if title not in category_list: category_list.append(title) lutil.log('eso.create_index action=["%s"] title=["%s"] url=["%s"]' % (action, title, url)) lutil.addDir(action=action, title=title, url=url, genre=title) # Spacetelescope web site if root_url == eso_url: action = 'create_index' url = 'http://www.spacetelescope.org/videos/' title = 'Hubble Space Telescope' lutil.log('eso.create_index action=["%s"] title=["%s"] url=["%s"]' % (action, title, url)) lutil.addDir(action=action, title=title, url=url, genre=title) # Search action = 'search' url = ('http://www.eso.org/public/videos/?search=', 'http://www.spacetelescope.org/videos/?search=')[array_index] title = translation(30104) genre = 'Search' lutil.log('eso.create_index action=["%s"] title=["Search"] url=["%s"]' % (action, url)) lutil.addDir(action=action, title=title, url=url, genre=genre) lutil.close_dir(pluginhandle, updateListing=False)
def get_playable_dailymotion_url(video_id): """This function returns the playable URL for the Dalymotion embedded video from the video_id retrieved.""" quality_pattern = '"([0-9]+)":\[[^]]*?{"type":"video\\\/mp4","url":"([^"]+?)"' quality_list = ('1080', '720', '480', '380', '240', '144') daily_url = 'http://www.dailymotion.com/embed/video/' + video_id buffer_link = l.carga_web(daily_url) video_options = dict((vquality, video) for vquality, video in l.find_multiple(buffer_link, quality_pattern)) l.log("ltl.play: list of video options: "+repr(video_options)) for quality_option in quality_list[quality:]: if quality_option in video_options: video_url = video_options.get(quality_option).replace('\\','') l.log("ltl.play: We have found this Dailymotion video: '%s' and let's going to play it!" % video_url) return video_url else: return False return ""
def get_playable_vimeo_url(video_id): """This function returns the playable URL for the Vimeo embedded video from the video_id retrieved.""" video_quality_pattern = '"profile":[0-9]+,"width":([0-9]+),.*?,"url":"([^"]*?)"' quality_list = ('640', '720', '480', '320', '960', '1280', '1920') video_info_url = 'https://player.vimeo.com/video/' + video_id buffer_link = l.carga_web(video_info_url) video_options = dict((quality, video) for quality, video in l.find_multiple(buffer_link, video_quality_pattern)) if len(video_options): l.log("List of video options: "+repr(video_options)) for quality in quality_list: if quality in video_options: return video_options.get(quality) # This quality isn't normalized as it doesn't appear into the quality_list. return video_options.get(video_options.keys()[0]) return ""
def other_categories(params): lutil.log("esa.other_categories " + repr(params)) action = 'main_list' page_url = 'http://www.esa.int/spaceinvideos/Videos' buffer_web = lutil.carga_web(page_url) category_pattern = '<a href="(/spaceinvideos/Directorates/[^"]*?)">([^<]*?)</a>' for category_link, title in lutil.find_multiple(buffer_web, category_pattern): url = '%s%s/(sortBy)/%s' % (root_url, category_link, sort_method) title = title.replace('"', '"').replace(''', '´').replace( '&', '&') # Cleanup the title. lutil.log( 'esa.other_categories action=["%s"] title=["%s"] url=["%s"]' % (action, title, url)) lutil.addDir(action=action, title=title, url=url, genre=title) lutil.close_dir(pluginhandle, updateListing=False)
def get_program_list(menu_url, all_programmes_flag=False, localized=lambda x: x): """This function makes programmes list data structure for all the program sections.""" program_pattern = '<dd><a title="([^"]*?)" href="([^"]*?)">[^<]*?</a></dd>' suffix = 'zaSP=ldom'[::-1] channel_pattern = '<span class="last">([^<]*?)</span></h1>' page_num_pattern = 'pbq=([0-9]+)' page_url_pattern = 'class="%s">.*?<a name="paginaIR" href="([^"]*?)"' last_page_sep = ' class="ultimo">' base_url_pattern = '(^[^?]*?)\?' suffix_pattern = '([^/]+)/$' suffix_string = 'zaSP=ldom&se=gnal&=adeuqsuBartel&s%=xtc&1=qbp?'[::-1] if not suffix in menu_url: suffix = suffix_string % l.find_first(menu_url, suffix_pattern) menu_url = menu_url + suffix buffer_url = l.carga_web(menu_url) program_list = [] reset_cache = False canal = l.find_first(buffer_url, channel_pattern) base_url = l.find_first(menu_url, base_url_pattern) curr_page_num = l.find_first(menu_url, page_num_pattern) or '1' if curr_page_num != '1': previous_page_url = l.find_first(buffer_url, page_url_pattern % 'anterior') prev_page_num = l.find_first(previous_page_url, page_num_pattern) program_entry = { 'url': base_url + previous_page_url.replace('&', '&'), 'title': '<< %s (%s)' % (localized('Previous page'), prev_page_num), 'action': 'program_list', } program_list.append(program_entry) reset_cache = True for title, url in l.find_multiple(buffer_url, program_pattern): l.log('Program info. url: "%s" canal: "%s" title: "%s"' % (url, canal, title)) program_entry = { 'url': url, 'title': title, 'comment': "", 'genre': "", 'canal': canal, 'program': title, 'action': 'audio_list' } program_list.append(program_entry) last_page_num = l.find_first( buffer_url.split(last_page_sep)[1], page_num_pattern) if last_page_sep in buffer_url else "" if last_page_num and curr_page_num != last_page_num: next_page_url = l.find_first(buffer_url, page_url_pattern % 'siguiente') next_page_num = l.find_first(next_page_url, page_num_pattern) program_entry = { 'url': base_url + next_page_url.replace('&', '&'), 'title': '>> %s (%s/%s)' % (localized('Next page'), next_page_num, last_page_num), 'action': 'program_list', } program_list.append(program_entry) return {'program_list': program_list, 'reset_cache': reset_cache}
def get_two_level_menu(html): """This function makes the two level menu parammeters data structure for all the menu sections.""" pattern_list = ( ('catalogue', '<input name="catalog-themes\[\]" type="radio" value="([^"]*?)"[^>]*?><span>(.*?)</span>'), ('order', '<input name="catalog-sorting" type="radio" value="([^"]*?)"[^>]*?><span>(.*?)</span>'), ('emissions', '<a href="(/emissions/[^"]+?)">(.*?)</a>'), ('chroniques', '<a href="(/chroniques/[^"]+?)">(.*?)</a>'), ('series', '<a href="(/series/[^"]+?)">(.*?)</a>'), ) level_parms = {} for lparam, lpattern in pattern_list: level_parms[lparam] = '¡'.join(['%s¿%s' % (section, label) for section, label in l.find_multiple(html, lpattern)]) return level_parms
def get_videolist(url, cat_menu=""): """This function gets the video list from the FFA website and returns them in a pretty data format.""" video_entry_sep = 'content-type-video' video_url_pattern = '["\'](/watch/[^/]*?/)' video_thumb_pattern = '["\'](/img/[^"\']*?)["\']' video_title_pattern = '<a href=["\']/watch/[^/]*?/["\'][ ]*?>([^<]+?)</a>' video_plot_pattern = '<span class="content-description">([^<]*?)</span>' video_duration_pattern = '([0-9]+[ ]+[Mm]in)' video_rating_pattern = '([0-9.]+[ ]+[Ss]tars)' video_views_pattern = '([0-9,]+[ ]+[Vv]iews)' page_num_pattern = 'href=["\']/library/([0-9]+)/' page_num_url_pattern = 'href=["\'](/library/%d/[^"\']*?)["\']' page_num_cur_pattern = '/library/([0-9]+)/' buffer_url = l.carga_web(url) video_list = [] reset_cache = False current_page_num = int(l.find_first(url, page_num_cur_pattern) or '1') last_page_num = int(max(l.find_multiple(buffer_url, page_num_pattern) or ('1',), key=int)) if current_page_num != 1: prev_page_num = current_page_num - 1 previous_page_url = root_url + l.find_first(buffer_url, page_num_url_pattern % prev_page_num) video_entry = { 'url': previous_page_url, 'title': '<< %s (%d)' % (cat_menu, prev_page_num), 'IsPlayable': False } video_list.append(video_entry) reset_cache = True category = "Video" # The category is no longer included in the latest website change. for video_section in buffer_url.split(video_entry_sep)[1:]: url = l.find_first(video_section, video_url_pattern) thumb = l.find_first(video_section, video_thumb_pattern) title = l.find_first(video_section, video_title_pattern) plot = l.find_first(video_section, video_plot_pattern) duration = l.find_first(video_section, video_duration_pattern) rating = l.find_first(video_section, video_rating_pattern) views = l.find_first(video_section, video_views_pattern) l.log('Video info. url: "%s" thumb: "%s" title: "%s"' % (url, thumb, title)) l.log('Video tags. duration: "%s" rating: "%s" views: "%s"' % (duration, rating, views)) video_entry = { 'url' : root_url + url, 'title' : title.strip() or '.', 'thumbnail' : root_url + thumb, 'plot' : "%s\n%s - %s - %s" % ( plot.strip(), duration, views, rating, ), 'duration' : int(duration.split()[0]) * 60 if duration else 0, 'rating' : rating.split()[0] if rating else '', 'genre' : category, 'IsPlayable' : True } video_list.append(video_entry) if current_page_num < last_page_num: next_page_num = current_page_num + 1 next_page_url = root_url + l.find_first(buffer_url, page_num_url_pattern % next_page_num) video_entry = { 'url': next_page_url, 'title': '>> %s (%d/%d)' % (cat_menu, next_page_num, last_page_num), 'IsPlayable': False } video_list.append(video_entry) return { 'video_list': video_list, 'reset_cache': reset_cache }
def main_list(params): lutil.log("esa.main_list "+repr(params)) # Loads the web page from ESA with the video list. page_url = params.get("url") reset_cache = params.get("reset_cache") genre = params.get("genre") buffer_web = lutil.carga_web(page_url) # Extract video items from the html content pattern_currentpage = '<span class="current">([^<]*?)</span>' pattern_page_url = '^%s([^\?]+)' pattern_nextpage = '<span class="next"><a href="([^"]*?)">' pattern_prevpage = '<span class="previous"><a href="([^"]*?)">' pattern_last = '<span class="other"><a href="[^"]*?">([^<]+)</a></span>' pattern_videos = '<div class="psr_item_grid">(.*?)</div>' pattern_videolink = '<a href="([^"]*?)"' pattern_thumbnail = '<img src="([^"]*?)"' pattern_title = '<span class="line2hell">([^<]+)</span>' pattern_date = '<span class="date">([^<]*?)</span>' pattern_year = '([0-9]{4})' lutil.set_content_list(pluginhandle, 'tvshows') lutil.set_plugin_category(pluginhandle, genre) page_current = lutil.find_first(buffer_web, pattern_currentpage) or '1' page_url_pref = lutil.find_first(page_url, pattern_page_url % root_url) # We must setup the previous page entry from the second page onwards. if page_current != '1': prev_page_url = lutil.find_first(buffer_web, pattern_prevpage) lutil.log('esa.main_list Value of current_page_url: "%s"' % page_url) prev_page_pref = lutil.find_first(prev_page_url, pattern_page_url % '') prev_page_url = page_url.replace(page_url_pref, prev_page_pref) reset_cache = "yes" lutil.addDir(action="main_list", title="<< %s (%s)" % (translation(30106), (int(page_current) - 1)), url=prev_page_url, reset_cache=reset_cache, genre=genre) # This is to force ".." option to go back to main index instead of previous page list. updateListing = reset_cache == "yes" videolist = lutil.find_multiple(buffer_web, pattern_videos) for video_entry in videolist: video_info = {} video_link = lutil.find_first(video_entry, pattern_videolink) thumbnail_link = lutil.find_first(video_entry, pattern_thumbnail) title = lutil.find_first(video_entry, pattern_title) title = title.replace('"', '"').replace(''', '´').replace('&', '&') # Cleanup the title. date = lutil.find_first(video_entry, pattern_date).strip().replace(' ', '') if date: video_info['Year'] = lutil.find_first(date, pattern_year) title = '%s (%s)' % (title, date) url = '%s%s' % (root_url, video_link) thumbnail = '%s%s' % (root_url, thumbnail_link) video_info['Genre'] = genre video_info['Plot'] = title # The description only appears when we load the link. lutil.log('esa.main_list Videolist: URL: "%s" Title: "%s" Thumbnail: "%s"' % (url, title, thumbnail)) # Appends a new item to the xbmc item list lutil.addLink(action="play_video", title=title, url=url, thumbnail=thumbnail, video_info=video_info, show_fanart=show_fanart) # Here we get the next page URL to add it at the end of the current video list page. next_page_url = lutil.find_first(buffer_web, pattern_nextpage) if next_page_url: next_page_pref = lutil.find_first(next_page_url, pattern_page_url % '') last_page = lutil.find_multiple(buffer_web, pattern_last)[-1] or '' lutil.log("esa.main_list Value of last_page: %s" % last_page) lutil.log('esa.main_list Value of current_page_url: "%s"' % page_url) next_page_url = page_url.replace(page_url_pref, next_page_pref) lutil.addDir(action="main_list", title=">> %s (%s/%s)" % (translation(30010), int(page_current) + 1, last_page), url=next_page_url, reset_cache=reset_cache, genre=genre) lutil.close_dir(pluginhandle, updateListing=updateListing)
def main_list(params): lutil.log("esa.main_list " + repr(params)) # Loads the web page from ESA with the video list. page_url = params.get("url") reset_cache = params.get("reset_cache") genre = params.get("genre") buffer_web = lutil.carga_web(page_url) # Extract video items from the html content pattern_currentpage = '<span class="current">([^<]*?)</span>' pattern_page_url = '^%s([^\?]+)' pattern_nextpage = '<span class="next"><a href="([^"]*?)">' pattern_prevpage = '<span class="previous"><a href="([^"]*?)">' pattern_last = '<span class="other"><a href="[^"]*?">([^<]+)</a></span>' pattern_videos = '<div class="psr_item_grid">(.*?)</div>' pattern_videolink = '<a href="([^"]*?)"' pattern_thumbnail = '<img src="([^"]*?)"' pattern_title = '<span class="line2hell">([^<]+)</span>' pattern_date = '<span class="date">([^<]*?)</span>' pattern_year = '([0-9]{4})' lutil.set_content_list(pluginhandle, 'tvshows') lutil.set_plugin_category(pluginhandle, genre) page_current = lutil.find_first(buffer_web, pattern_currentpage) or '1' page_url_pref = lutil.find_first(page_url, pattern_page_url % root_url) # We must setup the previous page entry from the second page onwards. if page_current != '1': prev_page_url = lutil.find_first(buffer_web, pattern_prevpage) lutil.log('esa.main_list Value of current_page_url: "%s"' % page_url) prev_page_pref = lutil.find_first(prev_page_url, pattern_page_url % '') prev_page_url = page_url.replace(page_url_pref, prev_page_pref) reset_cache = "yes" lutil.addDir(action="main_list", title="<< %s (%s)" % (translation(30106), (int(page_current) - 1)), url=prev_page_url, reset_cache=reset_cache, genre=genre) # This is to force ".." option to go back to main index instead of previous page list. updateListing = reset_cache == "yes" videolist = lutil.find_multiple(buffer_web, pattern_videos) for video_entry in videolist: video_info = {} video_link = lutil.find_first(video_entry, pattern_videolink) thumbnail_link = lutil.find_first(video_entry, pattern_thumbnail) title = lutil.find_first(video_entry, pattern_title) title = title.replace('"', '"').replace(''', '´').replace( '&', '&') # Cleanup the title. date = lutil.find_first(video_entry, pattern_date).strip().replace(' ', '') if date: video_info['Year'] = lutil.find_first(date, pattern_year) title = '%s (%s)' % (title, date) url = '%s%s' % (root_url, video_link) thumbnail = '%s%s' % (root_url, thumbnail_link) video_info['Genre'] = genre video_info[ 'Plot'] = title # The description only appears when we load the link. lutil.log( 'esa.main_list Videolist: URL: "%s" Title: "%s" Thumbnail: "%s"' % (url, title, thumbnail)) # Appends a new item to the xbmc item list lutil.addLink(action="play_video", title=title, url=url, thumbnail=thumbnail, video_info=video_info, show_fanart=show_fanart) # Here we get the next page URL to add it at the end of the current video list page. next_page_url = lutil.find_first(buffer_web, pattern_nextpage) if next_page_url: next_page_pref = lutil.find_first(next_page_url, pattern_page_url % '') last_page = lutil.find_multiple(buffer_web, pattern_last)[-1] or '' lutil.log("esa.main_list Value of last_page: %s" % last_page) lutil.log('esa.main_list Value of current_page_url: "%s"' % page_url) next_page_url = page_url.replace(page_url_pref, next_page_pref) lutil.addDir(action="main_list", title=">> %s (%s/%s)" % (translation(30010), int(page_current) + 1, last_page), url=next_page_url, reset_cache=reset_cache, genre=genre) lutil.close_dir(pluginhandle, updateListing=updateListing)