def ListGenres(): """List programmes based on alphabetical order. Only creates the corresponding directories for each character. """ genres = [] html = OpenURL("http://www.bbc.co.uk/radio/programmes/genres") mains = html.split('<li class="category br-keyline highlight-box--list">') for main in mains: current_main_match = re.search(r'<a.+?class="beta box-link".+?href="(.+?)">(.+?)</a>', main) if current_main_match: genres.append((current_main_match.group(1), current_main_match.group(2), True)) current_sub_match = re.findall(r'<a.+?class="box-link".+?href="(.+?)">(.+?)</a>', main) for sub_match_url, sub_match_name in current_sub_match: genres.append((sub_match_url, current_main_match.group(2) + " - " + sub_match_name, False)) for url, name, group in genres: new_url = "http://www.bbc.co.uk%s/player/episodes" % url if group: AddMenuEntry("[B]%s[/B]" % name, new_url, 136, "", "", "") else: AddMenuEntry("%s" % name, new_url, 136, "", "", "") # BUG: this should sort by original order but it doesn't (see http://trac.kodi.tv/ticket/10252) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
def ListGenres(): """List programmes based on alphabetical order. Only creates the corresponding directories for each character. """ genres = [] html = OpenURL('http://www.bbc.co.uk/radio/programmes/genres') mains = html.split('<div class="category__box island--vertical">') for main in mains: current_main_match = re.search( r'<a.+?class="gel-double-pica-bold".+?href="(.+?)">(.+?)</a>', main) if current_main_match: genres.append((current_main_match.group(1), current_main_match.group(2), True)) current_sub_match = re.findall( r'<a.+?class="gel-long-primer-bold".+?href="(.+?)">(.+?)</a>', main) for sub_match_url, sub_match_name in current_sub_match: genres.append((sub_match_url, current_main_match.group(2) + ' - ' + sub_match_name, False)) for url, name, group in genres: new_url = 'http://www.bbc.co.uk%s' % url if group: AddMenuEntry("[B]%s[/B]" % name, new_url, 137, '', '', '') else: AddMenuEntry("%s" % name, new_url, 137, '', '', '') #BUG: this should sort by original order but it doesn't (see http://trac.kodi.tv/ticket/10252) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
def ListFollowing(logged_in): if(CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('https://www.bbc.co.uk/radio/favourites/programmes') programmes = html.split('<div class="favourites follow ') for programme in programmes: if not programme.startswith('media'): continue series_id = '' series_name = '' series_id_match = re.search(r'<a aria-label="(.*?)" class="follows__image-link" href="http://www.bbc.co.uk/programmes/(.*?)">',programme) if series_id_match: series_name = series_id_match.group(1) series_id = series_id_match.group(2) episode_name = '' episode_id = '' episode_id_match = re.search(r'<a aria-label="(.*?)" class="size-e clr-white" href="http://www.bbc.co.uk/programmes/(.*?)#play"',programme) if episode_id_match: episode_name = episode_id_match.group(1) episode_id = episode_id_match.group(2) episode_image = '' series_image = '' series_image_match = re.search(r'<img class="media__image" src="(.*?)"',programme) if series_image_match: series_image = "https:%s" % series_image_match.group(1) episode_image = series_image station = '' station_match = re.search(r'<a href="(.*?)" class="clr-light-grey">\s*(.*?)\s*</a>',programme, flags=(re.DOTALL | re.MULTILINE)) if station_match: station = station_match.group(2).strip() description = '' if series_id: series_title = "%s - %s" % (station, series_name) AddMenuEntry(series_title, series_id, 131, series_image, description, '') if episode_id: if series_name: episode_title = "%s - %s - %s" % (station, series_name, episode_name) else: episode_title = "%s - %s" % (station, episode_name) episode_url = "http://www.bbc.co.uk/programmes/%s" % episode_id # xbmc.log(episode_url) CheckAutoplay(episode_title, episode_url, episode_image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def ListFollowing(logged_in): if(CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('https://www.bbc.co.uk/radio/favourites/programmes') programmes = html.split('<div class="favourites follow ') for programme in programmes: if not programme.startswith('media'): continue series_id = '' series_name = '' series_id_match = re.search(r'<a aria-label="(.*?)" class="follows__image-link" href="http://www.bbc.co.uk/programmes/(.*?)">',programme) if series_id_match: series_name = series_id_match.group(1) series_id = series_id_match.group(2) episode_name = '' episode_id = '' episode_id_match = re.search(r'<a aria-label="(.*?)" class="size-e clr-white" href="http://www.bbc.co.uk/programmes/(.*?)#play"',programme) if episode_id_match: episode_name = episode_id_match.group(1) episode_id = episode_id_match.group(2) episode_image = '' series_image = '' series_image_match = re.search(r'<img class="media__image" src="(.*?)"',programme) if series_image_match: series_image = "https:%s" % series_image_match.group(1) episode_image = series_image station = '' station_match = re.search(r'<a href="(.*?)" class="clr-light-grey">\s*(.*?)\s*</a>',programme, flags=(re.DOTALL | re.MULTILINE)) if station_match: station = station_match.group(2).strip() description = '' if series_id: series_title = "[B]%s - %s[/B]" % (station, series_name) AddMenuEntry(series_title, series_id, 131, series_image, description, '') if episode_id: if series_name: episode_title = "[B]%s[/B] - %s - %s" % (station, series_name, episode_name) else: episode_title = "[B]%s[/B] - %s" % (station, episode_name) episode_url = "http://www.bbc.co.uk/programmes/%s" % episode_id # xbmc.log(episode_url) CheckAutoplay(episode_title, episode_url, episode_image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def ListListenList(logged_in): if (CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('http://www.bbc.co.uk/radio/favourites') programmes = html.split('<div class="favourites box-link favourite ') for programme in programmes: if not programme.startswith('media'): continue data_available_match = re.search(r'data-is-available="(.*?)"', programme) if ((not data_available_match) or (data_available_match.group(1) == '')): continue series_id = '' series_name = '' series_id_match = re.search( r'<a href="/programmes/(.*?)" class="media__meta-row size-f clr-light-grey text--single-line">\s*(.*?)\s*</a>', programme) if series_id_match: series_name = series_id_match.group(2) series_id = series_id_match.group(1) episode_name = '' episode_id = '' episode_id_match = re.search( r'<a aria-label="(.*?) Duration: (.*?)" class="favourites__brand-link(.*?)" href="/programmes/(.*?)#play">', programme) if episode_id_match: episode_name = episode_id_match.group(1) episode_id = episode_id_match.group(4) episode_image = '' episode_image_match = re.search( r'<img alt="" class="favourites__brand-image media__image " src="(.*?)"', programme) if episode_image_match: episode_image = "http:%s" % episode_image_match.group(1) series_image = '' series_image_match = re.search( r'<img class="media__image avatar-image--small" src="(.*?)">', programme) if series_image_match: series_image = "http:%s" % series_image_match.group(1) series_image = re.sub(r'96x96', '640x360', series_image) station = '' station_match = re.search( r'<span class="favourites__network-name.*?<a href="(.*?)" class="clr-light-grey">\s+?(.*?)\s+?<', programme, flags=(re.DOTALL | re.MULTILINE)) if station_match: station = station_match.group(2).strip() description = '' description_match = re.search( r'<p class="favourites__description media__meta-row size-f clr-white.*?">\s+?(.*?)\s+?</p>', programme, flags=(re.DOTALL | re.MULTILINE)) if description_match: description = description_match.group(1).strip() if series_id: series_title = "[B]%s - %s[/B]" % (station, series_name) AddMenuEntry(series_title, series_id, 131, series_image, description, '') if episode_id: if series_name: episode_title = "[B]%s[/B] - %s - %s" % (station, series_name, episode_name) episode_url = "http://www.bbc.co.uk/programmes/%s" % episode_id else: episode_title = "[B]%s[/B] - %s" % (station, episode_name) episode_url = "http://www.bbc.co.uk/radio/play/%s" % episode_id # xbmc.log(episode_url) CheckAutoplay(episode_title, episode_url, episode_image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def GetCategoryPage(page_url, just_episodes=False): pDialog = xbmcgui.DialogProgressBG() pDialog.create(translation(30319)) html = OpenURL(page_url) total_pages = 1 current_page = 1 page_range = list(range(1)) paginate = re.search(r'pgn__list', html) next_page = 1 if paginate: if int(ADDON.getSetting('radio_paginate_episodes')) == 0: current_page_match = re.search(r'page=(\d*)', page_url) if current_page_match: current_page = int(current_page_match.group(1)) main_base_url = re.search(r'(.+?)\?.+?', page_url).group(1) else: main_base_url = page_url page_range = list(range(current_page, current_page + 1)) next_page_match = re.search( r'pgn__page--next.*?href="(.*?page=)(.*?)"', html) if next_page_match: page_base_url = main_base_url + next_page_match.group(1) next_page = int(next_page_match.group(2)) else: next_page = current_page page_range = list(range(current_page, current_page + 1)) else: pages = re.findall(r'<li class="pgn__page.*?</li>', html, flags=(re.DOTALL | re.MULTILINE)) if pages: last = pages[-2] last_page = re.search(r'href=".*?page=(.*?)"', last) page_base_url = page_url + '?page=' total_pages = int(last_page.group(1)) page_range = list(range(1, total_pages + 1)) for page in page_range: if page > current_page: page_url = page_base_url + str(page) html = OpenURL(page_url) list_item_num = 1 programmes = html.split('<div class="programme-item') for programme in programmes: series_id = '' series_id_match = re.search( r'<a class="category-episodes" href="/programmes/(.+?)/episodes"', programme) if series_id_match: series_id = series_id_match.group(1) programme_id = '' programme_id_match = re.search(r'href="/programmes/(.+?)"', programme) if programme_id_match: programme_id = programme_id_match.group(1) name = '' name_match = re.search( r'<span class="programme-item-title.+?>(.+?)</span>', programme) if name_match: name = name_match.group(1) subtitle = '' subtitle_match = re.search( r'<p class="programme-item-subtitle.+?>(.+?)</p>', programme) if subtitle_match: subtitle = subtitle_match.group(1) image = '' image_match = re.search(r'class="media__image" src="(.+?)"', programme) if image_match: image = 'http://' + image_match.group(1) synopsis = '' synopsis_match = re.search( r'<p class="programme-item-synopsis.+?>(.+?)</p>', programme) if synopsis_match: synopsis = synopsis_match.group(1) station = '' station_match = re.search( r'class="programme-item-network.+?>\s*(.+?)\s*</a>', programme) if station_match: station = station_match.group(1).strip() series_title = "[B]%s - %s[/B]" % (station, name) title = "[B]%s[/B] - %s %s" % (station, name, subtitle) if series_id: AddMenuEntry(series_title, series_id, 131, image, synopsis, '') elif programme_id: #TODO maybe they are not always mutually exclusive url = "http://www.bbc.co.uk/radio/play/%s" % programme_id CheckAutoplay(title, url, image, ' ', '') percent = int(100 * (page + list_item_num / len(programmes)) / total_pages) pDialog.update(percent, translation(30319), name) list_item_num += 1 percent = int(100 * page / total_pages) pDialog.update(percent, translation(30319)) if int(ADDON.getSetting('radio_paginate_episodes')) == 0: if current_page < next_page: page_url = page_base_url + str(next_page) AddMenuEntry(" [COLOR ffffa500]%s >>[/COLOR]" % translation(30320), page_url, 137, '', '', '') #BUG: this should sort by original order but it doesn't (see http://trac.kodi.tv/ticket/10252) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) pDialog.close()
def GetAtoZPage(page_url, just_episodes=False): """ Generic Radio page scraper. """ pDialog = xbmcgui.DialogProgressBG() pDialog.create(translation(30319)) html = OpenURL(page_url) total_pages = 1 current_page = 1 page_range = list(range(1)) paginate = re.search(r'<ol.+?class="pagination.*?</ol>', html) next_page = 1 if paginate: if int(ADDON.getSetting('radio_paginate_episodes')) == 0: current_page_match = re.search(r'page=(\d*)', page_url) if current_page_match: current_page = int(current_page_match.group(1)) page_range = list(range(current_page, current_page + 1)) next_page_match = re.search( r'<li class="pagination__next"><a href="(.*?page=)(.*?)">', paginate.group(0)) if next_page_match: page_base_url = next_page_match.group(1) next_page = int(next_page_match.group(2)) else: next_page = current_page page_range = list(range(current_page, current_page + 1)) else: pages = re.findall(r'<li.+?class="pagination__page.*?</li>', paginate.group(0)) if pages: last = pages[-1] last_page = re.search(r'<a.+?href="(.*?=)(.*?)"', last) page_base_url = last_page.group(1) total_pages = int(last_page.group(2)) page_range = list(range(1, total_pages + 1)) for page in page_range: if page > current_page: page_url = 'http://www.bbc.co.uk' + page_base_url + str(page) html = OpenURL(page_url) masthead_title = '' masthead_title_match = re.search( r'<div.+?id="programmes-main-content".*?<span property="name">(.+?)</span>', html) if masthead_title_match: masthead_title = masthead_title_match.group(1) else: alternative_masthead_title_match = re.search( r'<div class="br-masthead__title">.*?<a href="[^"]+">([^<]+?)</a>', html, re.M | re.S) if alternative_masthead_title_match: masthead_title = alternative_masthead_title_match.group(1) list_item_num = 1 programmes = html.split('<li class="grid one-whole">') for programme in programmes: if not re.search(r'programme--radio', programme): continue series_id = '' series_id_match = re.search( r'data-lazylink-inc="/programmes/(.+?)/episodes/player.inc"', programme) if series_id_match: series_id = series_id_match.group(1) programme_id = '' programme_id_match = re.search(r'data-pid="(.+?)"', programme) if programme_id_match: programme_id = programme_id_match.group(1) name = '' name_match = re.search(r'<span property="name">(.+?)</span>', programme) if name_match: name = name_match.group(1) else: alternative_name_match = re.search( r'<meta property="name" content="([^"]+?)"', programme) if alternative_name_match: name = alternative_name_match.group(1) image = '' image_match = re.search( r'<meta property="image" content="(.+?)" />', programme) if image_match: image = image_match.group(1) synopsis = '' synopsis_match = re.search( r'<span property="description">(.+?)<\/span>', programme) if synopsis_match: synopsis = synopsis_match.group(1) station = '' station_match = re.search( r'<p class="programme__service.+?<strong>(.+?)<\/strong>.*?<\/p>', programme) if station_match: station = station_match.group(1).strip() series_title = "[B]%s - %s[/B]" % (station, name) if just_episodes: title = "[B]%s[/B] - %s" % (masthead_title, name) else: title = "[B]%s[/B] - %s" % (station, name) if series_id: AddMenuEntry(series_title, series_id, 131, image, synopsis, '') elif programme_id: #TODO maybe they are not always mutually exclusive url = "http://www.bbc.co.uk/radio/play/%s" % programme_id CheckAutoplay(title, url, image, ' ', '') percent = int(100 * (page + list_item_num / len(programmes)) / total_pages) pDialog.update(percent, translation(30319), name) list_item_num += 1 percent = int(100 * page / total_pages) pDialog.update(percent, translation(30319)) if int(ADDON.getSetting('radio_paginate_episodes')) == 0: if current_page < next_page: page_url = 'http://www.bbc.co.uk' + page_base_url + str(next_page) AddMenuEntry(" [COLOR ffffa500]%s >>[/COLOR]" % translation(30320), page_url, 138, '', '', '') #BUG: this should sort by original order but it doesn't (see http://trac.kodi.tv/ticket/10252) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) pDialog.close()
def ListListenList(logged_in): if CheckLogin(logged_in) == False: CreateBaseDirectory("audio") return """Scrapes all episodes of the favourites page.""" html = OpenURL("http://www.bbc.co.uk/radio/favourites/episodesandclips") programmes = html.split('<div class="favourites box-link favourite ') for programme in programmes: if not programme.startswith("media"): continue data_available_match = re.search(r'data-is-available="(.*?)"', programme) if (not data_available_match) or (data_available_match.group(1) == ""): continue series_id = "" series_name = "" series_id_match = re.search( r'<a href="http://www.bbc.co.uk/programmes/(.*?)" class="media__meta-row size-f clr-light-grey text--single-line">\s*(.*?)\s*</a>', programme, ) if series_id_match: series_name = series_id_match.group(2) series_id = series_id_match.group(1) episode_name = "" episode_id = "" episode_id_match = re.search( r'<a aria-label="(.*?) Duration: (.*?)" class="favourites__brand-link(.*?)" href="http://www.bbc.co.uk/programmes/(.*?)#play">', programme, ) if episode_id_match: episode_name = episode_id_match.group(1) episode_id = episode_id_match.group(4) episode_image = "" episode_image_match = re.search( r'<img alt="" class="favourites__brand-image media__image " src="(.*?)"', programme ) if episode_image_match: episode_image = "http:%s" % episode_image_match.group(1) series_image = "" series_image_match = re.search(r'<img class="media__image avatar-image--small" src="(.*?)">', programme) if series_image_match: series_image = "http:%s" % series_image_match.group(1) series_image = re.sub(r"96x96", "640x360", series_image) station = "" station_match = re.search( r'<span class="favourites__network-name.*?<a href="(.*?)" class="clr-light-grey">\s+?(.*?)\s+?<', programme, flags=(re.DOTALL | re.MULTILINE), ) if station_match: station = station_match.group(2).strip() description = "" description_match = re.search( r'<p class="favourites__description media__meta-row size-f clr-white.*?">\s+?(.*?)\s+?</p>', programme, flags=(re.DOTALL | re.MULTILINE), ) if description_match: description = description_match.group(1).strip() if series_id: series_title = "[B]%s - %s[/B]" % (station, series_name) AddMenuEntry(series_title, series_id, 131, series_image, description, "") if episode_id: if series_name: episode_title = "[B]%s[/B] - %s - %s" % (station, series_name, episode_name) else: episode_title = "[B]%s[/B] - %s" % (station, episode_name) episode_url = "http://www.bbc.co.uk/programmes/%s" % episode_id # xbmc.log(episode_url) CheckAutoplay(episode_title, episode_url, episode_image, " ", "") xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def GetPage(page_url, just_episodes=False): """ Generic Radio page scraper. """ pDialog = xbmcgui.DialogProgressBG() pDialog.create(translation(30319)) html = OpenURL(page_url) total_pages = 1 current_page = 1 page_range = range(1) paginate = re.search(r'<ol.+?class="pagination.*?</ol>', html) next_page = 1 if paginate: if int(ADDON.getSetting("radio_paginate_episodes")) == 0: current_page_match = re.search(r"page=(\d*)", page_url) if current_page_match: current_page = int(current_page_match.group(1)) page_range = range(current_page, current_page + 1) next_page_match = re.search(r'<li class="pagination__next"><a href="(.*?page=)(.*?)">', paginate.group(0)) if next_page_match: page_base_url = next_page_match.group(1) next_page = int(next_page_match.group(2)) else: next_page = current_page page_range = range(current_page, current_page + 1) else: pages = re.findall(r'<li.+?class="pagination__page.*?</li>', paginate.group(0)) if pages: last = pages[-1] last_page = re.search(r'<a.+?href="(.*?=)(.*?)"', last) page_base_url = last_page.group(1) total_pages = int(last_page.group(2)) page_range = range(1, total_pages + 1) for page in page_range: if page > current_page: page_url = "http://www.bbc.co.uk" + page_base_url + str(page) html = OpenURL(page_url) masthead_title = "" masthead_title_match = re.search( r'<div.+?id="programmes-main-content".*?<span property="name">(.+?)</span>', html ) if masthead_title_match: masthead_title = masthead_title_match.group(1) list_item_num = 1 programmes = html.split('<div class="programme ') for programme in programmes: if not programme.startswith("programme--radio"): continue if "available" not in programme: # TODO find a more robust test continue series_id = "" series_id_match = re.search( r'<a class="iplayer-text js-lazylink__link" href="/programmes/(.+?)/episodes/player"', programme ) if series_id_match: series_id = series_id_match.group(1) programme_id = "" programme_id_match = re.search(r'data-pid="(.+?)"', programme) if programme_id_match: programme_id = programme_id_match.group(1) name = "" name_match = re.search(r'<span property="name">(.+?)</span>', programme) if name_match: name = name_match.group(1) subtitle = "" subtitle_match = re.search( r'<span class="programme__subtitle.+?property="name">(.*?)</span>(.*?property="name">(.*?)</span>)?', programme, ) if subtitle_match: series = subtitle_match.group(1) episode = subtitle_match.group(3) if episode: subtitle = "(%s, %s)" % (series, episode) else: if series.strip(): subtitle = "(%s)" % series image = "" image_match = re.search(r'<meta property="image" content="(.+?)" />', programme) if image_match: image = image_match.group(1) synopsis = "" synopsis_match = re.search(r'<span property="description">(.+?)</span>', programme) if synopsis_match: synopsis = synopsis_match.group(1) station = "" station_match = re.search(r'<p class="programme__service.+?<strong>(.+?)</strong>.*?</p>', programme) if station_match: station = station_match.group(1).strip() series_title = "[B]%s - %s[/B]" % (station, name) if just_episodes: title = "[B]%s[/B] - %s" % (masthead_title, name) else: title = "[B]%s[/B] - %s %s" % (station, name, subtitle) if series_id: AddMenuEntry(series_title, series_id, 131, image, synopsis, "") elif programme_id: # TODO maybe they are not always mutually exclusive url = "http://www.bbc.co.uk/programmes/%s" % programme_id CheckAutoplay(title, url, image, " ", "") percent = int(100 * (page + list_item_num / len(programmes)) / total_pages) pDialog.update(percent, translation(30319), name) list_item_num += 1 percent = int(100 * page / total_pages) pDialog.update(percent, translation(30319)) if int(ADDON.getSetting("radio_paginate_episodes")) == 0: if current_page < next_page: page_url = "http://www.bbc.co.uk" + page_base_url + str(next_page) AddMenuEntry(" [COLOR ffffa500]%s >>[/COLOR]" % translation(30320), page_url, 136, "", "", "") # BUG: this should sort by original order but it doesn't (see http://trac.kodi.tv/ticket/10252) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) pDialog.close()
def ListFavourites(logged_in): if(CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('http://www.bbc.co.uk/radio/favourites') programmes = html.split('<div class="favourites favourite ') for programme in programmes: if not programme.startswith('media'): continue series_name = '' series_id = '' series_id_match = re.search(r'<a aria-label="(.*?)" class="favourites__brand-image-link" href="/programmes/(.*?)">',programme) if series_id_match: series_name = series_id_match.group(1) series_id = series_id_match.group(2) episode_name = '' episode_id = '' episode_id_match = re.search(r'<a aria-label="(.*?) Duration: (.*?)" class="favourites__brand-link(.*?)" href="/programmes/(.*?)#play">',programme) if episode_id_match: episode_name = episode_id_match.group(1) episode_id = episode_id_match.group(4) episode_image = '' episode_image_match = re.search(r'<img class="favourites__brand-image media__image " src="(.*?)"',programme) if episode_image_match: episode_image = "http:%s" % episode_image_match.group(1) series_image = '' series_image_match = re.search(r'<img class="media__image avatar-image--small" src="(.*?)">',programme) if series_image_match: series_image = "http:%s" % series_image_match.group(1) series_image = re.sub(r'96x96','640x360',series_image) station = '' station_match = re.search(r'<span class="favourites__network-name.*?<a href="(.*?)" class="clr-light-grey">\s+?(.*?)\s+?<',programme, flags=(re.DOTALL | re.MULTILINE)) if station_match: station = station_match.group(2).strip() description = '' description_match = re.search(r'<p class="favourites__description media__meta-row size-f clr-white">\s+?(.*?)\s+?</p>',programme, flags=(re.DOTALL | re.MULTILINE)) if description_match: description = description_match.group(1).strip() if series_id: series_title = "[B]%s - %s[/B]" % (station, series_name) AddMenuEntry(series_title, series_id, 131, series_image, description, '') if episode_id: if series_name: episode_title = "[B]%s[/B] - %s - %s" % (station, series_name, episode_name) else: episode_title = "[B]%s[/B] - %s" % (station, episode_name) episode_url = "http://www.bbc.co.uk/programmes/%s" % episode_id xbmc.log(episode_url) CheckAutoplay(episode_title, episode_url, episode_image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def ListFavourites(logged_in): if(CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('http://www.bbc.co.uk/radio/favourites') programmes = html.split('<li class="my-item" data-appid="radio" ') for programme in programmes: if not programme.startswith('data-type="tlec"'): continue series_id = '' series_id_match = re.search(r'data-id="(.*?)"', programme) if series_id_match: series = series_id_match.group(1) programme_id = '' programme_id_match = re.search(r'<a href="http://www.bbc.co.uk/programmes/(.*?)"', programme) if programme_id_match: programme_id = programme_id_match.group(1) name = '' name_match = re.search(r'<span class="my-episode-brand" itemprop="name">(.*?)</span>', programme) if name_match: name = name_match.group(1) episode = '' episode_match = re.search(r'<span class="my-episode" itemprop="name">(.*?)</span>', programme) if episode_match: episode = "(%s)" % episode_match.group(1) image = '' image_match = re.search(r'itemprop="image" src="(.*?)"', programme) if image_match: image = image_match.group(1) synopsis = '' synopsis_match = re.search(r'<span class="my-item-info">(.*?)</span>', programme) if synopsis_match: synopsis = synopsis_match.group(1) station = '' station_match = re.search(r'<span class="my-episode-broadcaster" itemprop="name">(.*?)\.</span>', programme) if station_match: station = station_match.group(1).strip() title = "[B]%s - %s[/B]" % (station, name) episode_title = "[B]%s[/B] - %s %s" % (station, name, episode) if series: AddMenuEntry(title, series, 131, image, synopsis, '') if programme_id: url = "http://www.bbc.co.uk/programmes/%s" % programme_id CheckAutoplay(episode_title, url, image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
def ListFavourites(logged_in): if (CheckLogin(logged_in) == False): CreateBaseDirectory('audio') return """Scrapes all episodes of the favourites page.""" html = OpenURL('http://www.bbc.co.uk/radio/favourites') programmes = html.split('<li class="my-item" data-appid="radio" ') for programme in programmes: if not programme.startswith('data-type="tlec"'): continue series_id = '' series_id_match = re.search(r'data-id="(.*?)"', programme) if series_id_match: series = series_id_match.group(1) programme_id = '' programme_id_match = re.search( r'<a href="http://www.bbc.co.uk/programmes/(.*?)"', programme) if programme_id_match: programme_id = programme_id_match.group(1) name = '' name_match = re.search( r'<span class="my-episode-brand" itemprop="name">(.*?)</span>', programme) if name_match: name = name_match.group(1) episode = '' episode_match = re.search( r'<span class="my-episode" itemprop="name">(.*?)</span>', programme) if episode_match: episode = "(%s)" % episode_match.group(1) image = '' image_match = re.search(r'itemprop="image" src="(.*?)"', programme) if image_match: image = image_match.group(1) synopsis = '' synopsis_match = re.search(r'<span class="my-item-info">(.*?)</span>', programme) if synopsis_match: synopsis = synopsis_match.group(1) station = '' station_match = re.search( r'<span class="my-episode-broadcaster" itemprop="name">(.*?)\.</span>', programme) if station_match: station = station_match.group(1).strip() title = "[B]%s - %s[/B]" % (station, name) episode_title = "[B]%s[/B] - %s %s" % (station, name, episode) if series: AddMenuEntry(title, series, 131, image, synopsis, '') if programme_id: url = "http://www.bbc.co.uk/programmes/%s" % programme_id CheckAutoplay(episode_title, url, image, ' ', '') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)