Skip to content

Commit

Permalink
Merge pull request #1 from zchira/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
zchira committed Nov 21, 2015
2 parents b132036 + ce32e56 commit 71b21bc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 46 deletions.
75 changes: 44 additions & 31 deletions plugin.video.n1exyu/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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 = ''):
Expand All @@ -71,23 +68,28 @@ 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

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)
Expand All @@ -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 = ''):
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion plugin.video.n1exyu/addon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<addon id="plugin.video.n1exyu" name="N1 Info" provider-name="zchira" version="0.5">
<addon id="plugin.video.n1exyu" name="N1 Info" provider-name="zchira" version="0.6">
<requires>
<import addon="xbmc.python" version="2.1.0" />
<import addon="script.module.beautifulsoup4" version="4.3.1"/>
Expand Down
32 changes: 18 additions & 14 deletions plugin.video.n1exyu/resources/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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&amp;hl=en_US
Return youtube video id or None
"""
query = urlparse(yt_url)
if query.hostname == 'youtu.be':
Expand Down

0 comments on commit 71b21bc

Please sign in to comment.