summaryrefslogtreecommitdiff
path: root/plugin.video.spurs-tv/resources/lib
diff options
context:
space:
mode:
authorLS80 <github@lee-smith.me.uk>2017-01-09 07:30:10 +0000
committerLS80 <github@lee-smith.me.uk>2017-01-09 07:32:33 +0000
commitc92a14c7455630ec841e070052baf97647f9d930 (patch)
tree271e48c5f325f2ec3bef9bb8ccb02ab24824d4f9 /plugin.video.spurs-tv/resources/lib
parentf5e966f91c77dde6516858a6e2f03899b7578f77 (diff)
[plugin.video.spurs-tv] 2.13.0
Diffstat (limited to 'plugin.video.spurs-tv/resources/lib')
-rw-r--r--plugin.video.spurs-tv/resources/lib/new_stadium.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugin.video.spurs-tv/resources/lib/new_stadium.py b/plugin.video.spurs-tv/resources/lib/new_stadium.py
new file mode 100644
index 0000000..32b4ded
--- /dev/null
+++ b/plugin.video.spurs-tv/resources/lib/new_stadium.py
@@ -0,0 +1,41 @@
+'''
+ This module contains functions for scraping video links from
+ http://new-stadium.tottenhamhotspur.com
+'''
+
+from urlparse import urljoin
+import json
+import re
+from collections import namedtuple
+
+from bs4 import BeautifulSoup as BS
+import requests
+
+URL_ROOT = "http://new-stadium.tottenhamhotspur.com/"
+
+RE_EMBED = re.compile(r'kWidget\.embed\((.*)\)')
+
+Video = namedtuple('Video', ['title', 'entry_id'])
+
+
+def get_soup(path):
+ '''Return a BeautifulSoup tree for the provided new stadium path'''
+ response = requests.get(urljoin(URL_ROOT, path))
+ return BS(response.text, 'html.parser')
+
+
+def get_cams():
+ '''Generator for live stadium cameras'''
+ soup = get_soup("interact")
+ div = soup.find('div', {'data-player-id': 'player2'})
+ for tab in json.loads(div['data-tabs']):
+ yield Video(title=tab['title'], entry_id=tab['entryId'])
+
+
+def get_video_gallery():
+ '''Generator for the new stadium video gallery videos'''
+ soup = get_soup("video-gallery")
+ for video in soup('div', 'video-new'):
+ video_vars = json.loads(RE_EMBED.search(video.find(text=RE_EMBED)).group(1))
+ yield Video(title=video.find_next_sibling('p').get_text().strip(),
+ entry_id=video_vars['entry_id'])