From aa9f4de5d914cc0a1e928436eedefdb67d521ba6 Mon Sep 17 00:00:00 2001 From: zchira Date: Thu, 12 Nov 2015 22:42:28 +0100 Subject: [PATCH 1/2] added some comments to code. Fixed 'previous page' listitem --- plugin.video.n1exyu/addon.py | 2 +- plugin.video.n1exyu/addon.xml | 2 +- plugin.video.n1exyu/resources/helper.py | 32 ++++++++++++++----------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/plugin.video.n1exyu/addon.py b/plugin.video.n1exyu/addon.py index 697e854..1a18406 100644 --- a/plugin.video.n1exyu/addon.py +++ b/plugin.video.n1exyu/addon.py @@ -87,7 +87,7 @@ def FOLDER(folder_name, pagetoken = ''): return for item in items: - if item.title == helper.NEXT_PAGE or item.title == helper.PREV_PAGE: + if item.title == helper.NEXT_PAGE: add_next_prev_folder(folder_name, item.title, item.yt_id, iconUrl, show_fanart) else: add_show_item(item, fanart = show_fanart) diff --git a/plugin.video.n1exyu/addon.xml b/plugin.video.n1exyu/addon.xml index 289f5b4..7a850db 100644 --- a/plugin.video.n1exyu/addon.xml +++ b/plugin.video.n1exyu/addon.xml @@ -1,4 +1,4 @@ - + diff --git a/plugin.video.n1exyu/resources/helper.py b/plugin.video.n1exyu/resources/helper.py index df0eb2c..e9f9cf5 100644 --- a/plugin.video.n1exyu/resources/helper.py +++ b/plugin.video.n1exyu/resources/helper.py @@ -4,35 +4,39 @@ from ytHelper import vids_by_playlist NEXT_PAGE = "Next Page" -PREV_PAGE = "Previous Page" class Article(object): + """ Class that represent one article/episode/listItem """ + """ Title of article """ title = "" + """ Url/path to thumbnail """ thumb = "" + """ youtube video id """ yt_id = "" + """ youtube video description """ description = "" class ShowInfo(object): + """ Class that represents one tv show """ + + """ Web page that needs to be scraped for episodes content. + Not used anymore (youtube api is used instead """ webPage = '' + """ tv show title """ title = '' + """ fanart image url. Used for background """ fanartUrl = '' + """ ison url """ iconUrl = '' + """ youtube playlist id """ yt_playlist_id = ''; def get_show_data_yt(yt_playlist_id, nextpage = False): + """ Get data from youtube playlist. Returns the list of the Article objects """ yt_response = vids_by_playlist(yt_playlist_id, nextpage) toRet = [] - - try: - prevPageToken = yt_response["prevPageToken"] - prevPage = Article() - prevPage.title = PREV_PAGE - prevPage.yt_id = prevPageToken - toRet.append(prevPage) - except: - pass - + for i in yt_response["items"]: item = Article() try: @@ -53,12 +57,10 @@ def get_show_data_yt(yt_playlist_id, nextpage = False): except: pass - - return toRet def get_show_data(show_web_page): - + """ Scrap data from web_page. Returns the list of the Article objets """ webpage = urllib2.urlopen(show_web_page) soup = BeautifulSoup(webpage, "html.parser") media_div = soup.find('div', class_="medium-media") @@ -90,6 +92,7 @@ def get_show_data(show_web_page): def find_youtube_id(url): + """ Find and return youtube url on the web page """ webpage = urllib2.urlopen(url) soup = BeautifulSoup(webpage, "html.parser") iframe = soup.find_all('iframe', class_="video-player") @@ -104,6 +107,7 @@ def video_id(yt_url): - http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu - http://www.youtube.com/embed/SA2iWivDJiE - http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US + Return youtube video id or None """ query = urlparse(yt_url) if query.hostname == 'youtu.be': From ce32e56bfb110307fd1d57e5a5a7083e6d4a5dd4 Mon Sep 17 00:00:00 2001 From: zchira Date: Sat, 21 Nov 2015 19:00:09 +0100 Subject: [PATCH 2/2] added show 'crvena linija'. some refactor... --- plugin.video.n1exyu/addon.py | 73 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/plugin.video.n1exyu/addon.py b/plugin.video.n1exyu/addon.py index 1a18406..38bbee1 100644 --- a/plugin.video.n1exyu/addon.py +++ b/plugin.video.n1exyu/addon.py @@ -23,6 +23,10 @@ iconImage = my_addon.getAddonInfo('icon') fanart = my_addon.getAddonInfo('fanart') +LIVE_SERBIAN_URL = "http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1srb&stream=1mb&b=6&player=m3u8&u=n1info&p=n1Sh4redSecre7iNf0" +LIVE_CROATIAN_URL = "http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1hr&stream=1mb&b=6&player=m3u8&u=n1info&p=n1Sh4redSecre7iNf0" +LIVE_BOSNIAN_URL = "http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1bih&stream=1mb&b=6&player=m3u8&u=n1info&p=n1Sh4redSecre7iNf0" + """ FUNCTIONS """ @@ -34,33 +38,26 @@ def build_url(query): def youtube_url(videoid): return YOUTUBE_PTN % (videoid) -def INDEX(): - HEADERS = urllib.urlencode({'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'}) - - url = 'http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1srb&stream=1mb&b=6&player=mpg&u=n1info&p=n1Sh4redSecre7iNf0|%s' % HEADERS - +def INDEX(): + add_live_stream(LIVE_SERBIAN_URL, u'N1 Live [Srbija]', 'Program za region Srbije') + add_live_stream(LIVE_CROATIAN_URL, 'N1 Live [Hrvatska]', 'Program za region Hrvatske') + add_live_stream(LIVE_BOSNIAN_URL, 'N1 Live [BiH]', 'Program za region BiH') - li = xbmcgui.ListItem('N1 Live [Serbia]', iconImage=iconImage) - li.setProperty('isplayable', 'true') - li.setProperty('fanart_image', fanart) - xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li) + add_show_folder(PRESSING_SHOW) + add_show_folder(DNEVNIK_19_SHOW) + add_show_folder(CRVENA_LINIJA_SHOW) - url = 'http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1hr&stream=1mb&b=6&player=m3u8&u=n1info&p=n1Sh4redSecre7iNf0|%s' % HEADERS - li = xbmcgui.ListItem('N1 Live [Croatia]', iconImage=iconImage) - li.setProperty('isplayable', 'true') - li.setProperty('fanart_image', fanart) - xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li) + xbmcplugin.endOfDirectory(addon_handle) - url = 'http://best.str.n1info.com:8080/stream?sp=n1info&channel=n1bih&stream=1mb&b=6&player=m3u8&u=n1info&p=n1Sh4redSecre7iNf0|%s' % HEADERS - li = xbmcgui.ListItem('N1 Live [BiH]', iconImage=iconImage) +def add_live_stream(url, title, plot): + HEADERS = urllib.urlencode({'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'}) + url = url + '|%s' % HEADERS + li = xbmcgui.ListItem(title, iconImage=iconImage) li.setProperty('isplayable', 'true') li.setProperty('fanart_image', fanart) + infoLabels = { 'plot' : plot} + li.setInfo( type="video", infoLabels=infoLabels) xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li) - - add_show_folder(PRESSING_SHOW) - add_show_folder(DNEVNIK_19_SHOW) - - xbmcplugin.endOfDirectory(addon_handle) def FOLDER(folder_name, pagetoken = ''): @@ -71,17 +68,22 @@ def FOLDER(folder_name, pagetoken = ''): items = None show_fanart = fanart iconUrl = iconImage - + + show = None + if folder_name == PRESSING_SHOW.title: - #items = helper.get_show_data(PRESSING_SHOW.webPage) - items = helper.get_show_data_yt(PRESSING_SHOW.yt_playlist_id, pagetoken) - iconUrl = PRESSING_SHOW.iconUrl - show_fanart = PRESSING_SHOW.fanartUrl + show = PRESSING_SHOW elif folder_name == DNEVNIK_19_SHOW.title: - #items = helper.get_show_data_yt(DNEVNIK_19_SHOW.webPage) - items = helper.get_show_data_yt(DNEVNIK_19_SHOW.yt_playlist_id, pagetoken) - iconUrl = DNEVNIK_19_SHOW.iconUrl - show_fanart = DNEVNIK_19_SHOW.fanartUrl + show = DNEVNIK_19_SHOW + elif folder_name == CRVENA_LINIJA_SHOW.title: + show = CRVENA_LINIJA_SHOW + + if show != None: + #items = = helper.get_show_data(show.webPage) + items = helper.get_show_data_yt(show.yt_playlist_id, pagetoken) + iconUrl = show.iconUrl + show_fanart = show.fanartUrl + if items == None: INDEX() return @@ -100,6 +102,8 @@ def add_show_item(item, fanart): li = xbmcgui.ListItem(item.title, iconImage=item.thumb) li.setProperty('isplayable', 'true') li.setProperty('fanart_image', fanart) + #infoLabels = {'plot' : item.description} + #li.setInfo( type="video", infoLabels=infoLabels) <-- causes exception xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=False) def add_show_folder(show, pagetoken = ''): @@ -134,6 +138,15 @@ def add_next_prev_folder(showname, title, pagetoken = '', iconUrl = iconImage, f DNEVNIK_19_SHOW.iconUrl = iconImage DNEVNIK_19_SHOW.yt_playlist_id = "PLtkTKfgc4b4VA7ytBRgVS1tHpQ7cC_VoT" +CRVENA_LINIJA_SHOW = ShowInfo() +CRVENA_LINIJA_SHOW.webPage = 'http://rs.n1info.com/a104633/TV-Emisije/Crvena-linija/Crvena-linija.html' +CRVENA_LINIJA_SHOW.title = "Crvena Linija" +CRVENA_LINIJA_SHOW.fanartUrl = 'http://static.rs.n1info.com/Picture/46806/jpeg/Crvena-Linija-mali-poster-tv-emisija.jpg' +CRVENA_LINIJA_SHOW.iconUrl = iconImage +CRVENA_LINIJA_SHOW.yt_playlist_id = "PLtkTKfgc4b4WnU64YTYTsbCrTnyYhrJcD" + + + if (mode) is None: INDEX()