summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir@cohens.org.il>2017-10-31 23:31:41 +0200
committerTzafrir Cohen <tzafrir@cohens.org.il>2017-10-31 23:50:00 +0200
commit349c9f2067e0456f57743dc21162460289306fb7 (patch)
treea397db0f76b89163e58363c9f5bc07bca2ce2617
parent5194acf7bb0c144adee2928b21540f9840d974f0 (diff)
Get some items from kan's tv shows page
-rw-r--r--addon.py43
1 files changed, 38 insertions, 5 deletions
diff --git a/addon.py b/addon.py
index 404d1ad..56a7dca 100644
--- a/addon.py
+++ b/addon.py
@@ -1,20 +1,53 @@
# -*- coding: UTF-8 -*-
""" Kan Video plugin """
+from bs4 import BeautifulSoup
import sys
import urllib
+import urllib2
import urlparse
import xbmcgui
import xbmcplugin
+KAN_URL = 'http://www.kan.org.il'
+USER_AGENT = 'Kodi' # I'm optimistic
+
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])
+mode = args.get('mode', None)
+
def build_url(query):
return base_url + '?' + urllib.urlencode(query)
-mode = args.get('mode', None)
+
+def read_url(url):
+ req = urllib2.Request(url)
+ req.add_header('User-Agent', USER_AGENT)
+ response = urllib2.urlopen(req, timeout=100)
+ return response.read()
+
+
+def placeholder_folder(foldername):
+ url = 'http://localhost/some_video.mkv'
+ li = xbmcgui.ListItem(foldername + 'Not Implemented',
+ iconImage='DefaultVideo.png')
+ xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
+ xbmcplugin.endOfDirectory(addon_handle)
+
+
+def tvshows_menu():
+ tvshows_url = 'http://www.kan.org.il/video/programs.aspx'
+ main_page = read_url(tvshows_url)
+ parsed = BeautifulSoup(main_page)
+ anchors = parsed.find_all('a',
+ class_="program_category_link w-inline-block")
+ for a in anchors:
+ path = a.href
+ li = xbmcgui.ListItem(foldername + 'Show' + path)
+ xbmcplugin.addDirectoryItem(handle=addon_handle, listitem=li)
+ xbmcplugin.endOfDirectory(addon_handle)
if mode is None:
@@ -37,7 +70,7 @@ if mode is None:
elif mode[0] == 'folder':
foldername = args['foldername'][0]
- url = 'http://localhost/some_video.mkv'
- li = xbmcgui.ListItem(foldername + ' Video', iconImage='DefaultVideo.png')
- xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
- xbmcplugin.endOfDirectory(addon_handle)
+ if foldername == 'tv-shows':
+ tvshows_menu()
+ else:
+ placeholder_folder(foldername)