diff options
author | Tzafrir Cohen <tzafrir@cohens.org.il> | 2017-11-13 00:40:57 +0200 |
---|---|---|
committer | Tzafrir Cohen <tzafrir@cohens.org.il> | 2017-11-13 00:54:03 +0200 |
commit | 1de87c44e3bbfe671d03e67403c56c67dbcbb00f (patch) | |
tree | a3965a7446d96b76f7c8532c9489e4af2a07df94 | |
parent | e7a19d8f637e2c211ebca4400d6552f25924a88d (diff) |
Basic support for shows from YouTube
-rw-r--r-- | addon.py | 42 |
1 files changed, 35 insertions, 7 deletions
@@ -34,6 +34,7 @@ class Page: self.mode = self.args.get('mode', None) def build_url(self, query): + #query['addon_handle'] = self.addon_handle return self.base_url + '?' + urllib.urlencode(query) def add_directory_item(self, **kwargs): @@ -78,10 +79,9 @@ def get_show_title(base_url, path): return title - def tvshows_menu(page): - base_url = 'http://www.kan.org.il' - tvshows_url = base_url + '/video/programs.aspx' + """ Display a menu of all the TV shows """ + tvshows_url = KAN_URL + '/video/programs.aspx' main_page = read_url(tvshows_url) parsed = BeautifulSoup(main_page, "html.parser") anchors = parsed.find_all('a', @@ -90,11 +90,39 @@ def tvshows_menu(page): for a in anchors: path = a.get('href') show_id = re.sub('.*=', '', path) - trace("Checking link to " + path) - title = get_show_title(base_url, path) + #trace("Checking link to " + path) + title = get_show_title(KAN_URL, path) url = page.build_url({'mode': 'show', 'id': show_id}) + trace("Item: URL: {}, title: {}.".format(url, title.encode('utf8'))) + li = xbmcgui.ListItem(title) + page.add_directory_item(url=url, listitem=li, isFolder=True, + totalItems=len(anchors)) + page.end_directory() + + +def show_menu(page): + """ Display a menu of items in a specific show """ + show_id = page.args['id'][0] + show_url = KAN_URL + '/Program/?catId=' + show_id + trace("URL for show {}: {}".format(show_id, show_url)) + + show_page = read_url(show_url) + parsed = BeautifulSoup(show_page, "html.parser") + items = parsed.find_all('li', + class_="program_list_item w-clearfix") + trace("got items: " + str(len(items))) + for item in items: + titles = item.find_all('h2') + title = titles[0].string + iframe = item.find_all('iframe')[0] + youtube_url = iframe['src'] + #trace("Youtube URL: {}.".format(youtube_url)) + youtube_id = re.sub('.*/embed/([0-9A-Za-z]+)(\?.*)?', r'\1', youtube_url) + trace("Add link for ID {} ({}).".format(youtube_id, title.encode('utf-8'))) + url = 'plugin://plugin.video.youtube/play/?video_id={}'.format(youtube_id) li = xbmcgui.ListItem(title) - page.add_directory_item(url=url, listitem=li) + li.setProperty('IsPlayable','true') + page.add_directory_item(url=url, listitem=li, totalItems=len(items)) page.end_directory() @@ -121,7 +149,7 @@ def main(): elif mode == 'shows': tvshows_menu(page) elif mode == 'show': - pass + show_menu(page) elif mode == 'placeholder': name = page.args['name'][0] page.placeholder_folder(name) |