summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Smith <LS80@users.noreply.github.com>2017-12-01 01:42:26 +0000
committerenen92 <enen92@users.noreply.github.com>2017-12-01 01:42:26 +0000
commit7d0018f9840e28c0c5cf0a6a83a40ed1146e7993 (patch)
treec22d1656e7421206ca051a17c8f6014bec86200a
parent13a1688259deeae1e5f62acf2ed9ba757346415a (diff)
[plugin.video.btsportvideo] 0.1.0 (#1531)
-rw-r--r--plugin.video.btsportvideo/LICENSE21
-rw-r--r--plugin.video.btsportvideo/README.md9
-rw-r--r--plugin.video.btsportvideo/addon.py125
-rw-r--r--plugin.video.btsportvideo/addon.xml27
-rw-r--r--plugin.video.btsportvideo/resources/__init__.py0
-rw-r--r--plugin.video.btsportvideo/resources/fanart.jpgbin0 -> 70327 bytes
-rw-r--r--plugin.video.btsportvideo/resources/icon.pngbin0 -> 17881 bytes
-rw-r--r--plugin.video.btsportvideo/resources/language/resource.language.en_gb/strings.po33
-rw-r--r--plugin.video.btsportvideo/resources/lib/__init__.py0
-rw-r--r--plugin.video.btsportvideo/resources/lib/api.py105
10 files changed, 320 insertions, 0 deletions
diff --git a/plugin.video.btsportvideo/LICENSE b/plugin.video.btsportvideo/LICENSE
new file mode 100644
index 0000000..b5d48b2
--- /dev/null
+++ b/plugin.video.btsportvideo/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Lee Smith
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/plugin.video.btsportvideo/README.md b/plugin.video.btsportvideo/README.md
new file mode 100644
index 0000000..8a27e69
--- /dev/null
+++ b/plugin.video.btsportvideo/README.md
@@ -0,0 +1,9 @@
+BT Sport Video plugin for Kodi
+===========================================
+[![Travis CI](https://travis-ci.org/LS80/plugin.video.btsportvideo.svg?branch=master)](https://travis-ci.org/LS80/plugin.video.btsportvideo)
+
+A [Kodi](http://kodi.tv) plugin to watch videos from BT Sport at <https://sport.bt.com>.
+
+The plugin can be installed from the official Kodi addon repository.
+
+Contact: [Leopold](https://forum.kodi.tv/private.php?action=send&uid=82951) on <http://forum.kodi.tv>.
diff --git a/plugin.video.btsportvideo/addon.py b/plugin.video.btsportvideo/addon.py
new file mode 100644
index 0000000..2dd8802
--- /dev/null
+++ b/plugin.video.btsportvideo/addon.py
@@ -0,0 +1,125 @@
+###############################################################################
+#
+# MIT License
+#
+# Copyright (c) 2017 Lee Smith
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+###############################################################################
+
+import traceback
+
+from kodiswift import Plugin
+import rollbar.kodi
+
+from resources.lib import api
+
+
+PAGE_SIZE = 9
+
+plugin = Plugin(addon_id='plugin.video.btsportvideo')
+
+
+def categories():
+ yield {'label': '[B]{}[/B]'.format(plugin.get_string(30002)),
+ 'path': plugin.url_for('search')}
+ yield {'label': '[B]{}[/B]'.format(plugin.get_string(30001)),
+ 'path': plugin.url_for('show_videos_by_category_first_page', category='all')}
+ for category in api.categories():
+ yield {'label': category,
+ 'path': plugin.url_for('show_videos_by_category_first_page',
+ category=category)}
+
+
+def items(func, route, page, **kwargs):
+ videos, npages = func(page=page, page_size=PAGE_SIZE, **kwargs)
+
+ if page > 1:
+ yield {
+ 'label': u'[B]<< {} ({})[/B]'.format(plugin.get_string(30003), page - 1),
+ 'path': plugin.url_for(route, page=page - 1, **kwargs)
+ }
+ if page < npages:
+ yield {
+ 'label': u'[B]{} ({}) >> [/B]'.format(plugin.get_string(30004), page + 1),
+ 'path': plugin.url_for(route, page=page + 1, **kwargs)
+ }
+
+ for video in videos:
+ yield {
+ 'label': video.title,
+ 'thumbnail': video.thumbnail,
+ 'path': video.url,
+ 'info': {
+ 'date': video.date.strftime('%d.%m.%Y'),
+ 'duration': video.duration
+ },
+ 'is_playable': True
+ }
+
+
+def show_videos(func, route, page, update_listing, **kwargs):
+ return plugin.finish(
+ items(func, route, page, **kwargs),
+ sort_methods=['playlist_order', 'date', 'title', 'duration'],
+ update_listing=update_listing
+ )
+
+
+@plugin.cached_route('/')
+def index():
+ return list(categories())
+
+
+@plugin.route('/videos/<category>', name='show_videos_by_category_first_page',
+ options={'update_listing': False})
+@plugin.route('/videos/<category>/<page>')
+def show_videos_by_category(category, page='1', update_listing=True):
+ return show_videos(api.videos, 'show_videos_by_category', int(page),
+ update_listing, category=category)
+
+
+@plugin.route('/search/<term>', name='show_search_results_first_page',
+ options={'update_listing': False})
+@plugin.route('/search/<term>/<page>')
+def show_search_results(term, page='1', update_listing=True):
+ return show_videos(api.search_results, 'show_search_results', int(page),
+ update_listing, term=term)
+
+
+@plugin.route('/search')
+def search():
+ term = plugin.keyboard(heading=plugin.get_string(30002))
+ if term:
+ url = plugin.url_for('show_search_results_first_page', term=term)
+ plugin.redirect(url)
+
+
+if __name__ == '__main__':
+ try:
+ plugin.run()
+ except Exception as exc:
+ if rollbar.kodi.error_report_requested(exc):
+ rollbar.kodi.report_error(
+ access_token='cc56a52c62c5418ebc87f97b1aa44669',
+ version=plugin.addon.getAddonInfo('version'),
+ url=plugin.request.url
+ )
+ plugin.log.error(traceback.format_exc())
diff --git a/plugin.video.btsportvideo/addon.xml b/plugin.video.btsportvideo/addon.xml
new file mode 100644
index 0000000..03c79a0
--- /dev/null
+++ b/plugin.video.btsportvideo/addon.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<addon id="plugin.video.btsportvideo" name="BT Sport Video" version="0.1.0" provider-name="Leopold">
+ <requires>
+ <import addon="xbmc.python" version="2.25.0"/>
+ <import addon="script.module.kodiswift" version="0.0.8" optional="false"/>
+ <import addon="script.module.beautifulsoup4" version="4.3.1" optional="false"/>
+ <import addon="script.module.requests" version="2.4.3" optional="false"/>
+ <import addon="script.module.pyrollbar" version="0.13.17" optional="false"/>
+ </requires>
+ <extension point="xbmc.python.pluginsource" library="addon.py">
+ <provides>video</provides>
+ </extension>
+ <extension point="xbmc.addon.metadata">
+ <platform>all</platform>
+ <language>en</language>
+ <summary lang="en_gb">Watch videos from BT Sport</summary>
+ <description lang="en_gb">This plugin provides access to the videos from the BT Sport website</description>
+ <website>https://sport.bt.com</website>
+ <source>https://github.com/LS80/plugin.video.btsportvideo.git</source>
+ <license>MIT</license>
+ <assets>
+ <icon>resources/icon.png</icon>
+ <fanart>resources/fanart.jpg</fanart>
+ </assets>
+ <news></news>
+ </extension>
+</addon>
diff --git a/plugin.video.btsportvideo/resources/__init__.py b/plugin.video.btsportvideo/resources/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/__init__.py
diff --git a/plugin.video.btsportvideo/resources/fanart.jpg b/plugin.video.btsportvideo/resources/fanart.jpg
new file mode 100644
index 0000000..acbbbef
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/fanart.jpg
Binary files differ
diff --git a/plugin.video.btsportvideo/resources/icon.png b/plugin.video.btsportvideo/resources/icon.png
new file mode 100644
index 0000000..ea1c085
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/icon.png
Binary files differ
diff --git a/plugin.video.btsportvideo/resources/language/resource.language.en_gb/strings.po b/plugin.video.btsportvideo/resources/language/resource.language.en_gb/strings.po
new file mode 100644
index 0000000..850394c
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/language/resource.language.en_gb/strings.po
@@ -0,0 +1,33 @@
+# Kodi Media Center language file
+# Addon Name: BT Sport Video
+# Addon id: plugin.video.btsportvideo
+# Addon Provider: Leopold
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: Kodi Translation Team\n"
+"Language-Team: English (http://www.transifex.com/projects/p/xbmc-addons/language/en/)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Language: en_GB\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+msgctxt "#30001"
+msgid "All Videos"
+msgstr ""
+
+msgctxt "#30002"
+msgid "Search"
+msgstr ""
+
+msgctxt "#30003"
+msgid "Previous Page"
+msgstr ""
+
+msgctxt "#30004"
+msgid "Next Page"
+msgstr ""
diff --git a/plugin.video.btsportvideo/resources/lib/__init__.py b/plugin.video.btsportvideo/resources/lib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/lib/__init__.py
diff --git a/plugin.video.btsportvideo/resources/lib/api.py b/plugin.video.btsportvideo/resources/lib/api.py
new file mode 100644
index 0000000..72d63e4
--- /dev/null
+++ b/plugin.video.btsportvideo/resources/lib/api.py
@@ -0,0 +1,105 @@
+###############################################################################
+#
+# MIT License
+#
+# Copyright (c) 2017 Lee Smith
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+###############################################################################
+
+'''
+Module for extracting video links from the BT Sport website
+'''
+
+from urlparse import urljoin
+from datetime import datetime
+import time
+from collections import namedtuple
+import math
+
+import requests
+from bs4 import BeautifulSoup
+
+
+CATEGORIES_URL = 'http://sport.bt.com/all-videos/videos-01364228997406'
+API_URL = 'http://api-search.sport.bt.com/search/sport/select'
+
+_Video = namedtuple('Video', 'title url thumbnail date duration')
+
+
+def _video_params(page, page_size):
+ '''Returns the common params for the BT Sport API'''
+ return dict(
+ fq='AssetType:BTVideo',
+ sort='publicationdate desc',
+ wt='json',
+ start=(page - 1) * page_size,
+ rows=page_size,
+ )
+
+
+def _soup(path=''):
+ '''Returns a BeautifulSoup tree for the specified path'''
+ url = urljoin(CATEGORIES_URL, path)
+ response = requests.get(url)
+ return BeautifulSoup(response.text, 'html.parser')
+
+
+def _date_from_str(date_str, fmt='%Y-%m-%dT%H:%M:%S.%fZ'):
+ '''Returns a data object from a string.
+ datetime.strptime is avoided due to an issue with Python in Kodi'''
+ return datetime(*(time.strptime(date_str, fmt)[0:6])).date()
+
+
+def categories():
+ '''Generator for all sport categories on the website'''
+ for category in _soup().find('div', 'video-hub-nav')('a'):
+ if not category.text.startswith('All '):
+ yield category.text
+
+
+def _videos(videos_response):
+ for video in videos_response['docs']:
+ yield _Video(
+ title=video['h1title'],
+ url=video.get('hlsurl') or video.get('streamingurl'),
+ thumbnail=video['imageurl'],
+ date=_date_from_str(video['publicationdate']),
+ duration=int(video['duration'])
+ )
+
+
+def _video_results(page=1, page_size=10, **params):
+ params.update(_video_params(page, page_size))
+ videos_response = requests.get(API_URL, params=params).json()['response']
+ num_pages = int(math.ceil(float(videos_response['numFound']) / page_size))
+ return _videos(videos_response), num_pages
+
+
+def videos(category=None, page=1, page_size=10):
+ '''Returns a generator for videos in a category and the number of pages'''
+ category = None if category.lower() == 'all' else category
+ query = 'tags:("{}")'.format(category) if category else 'Publist:btsport'
+ return _video_results(page, page_size, q=query)
+
+
+def search_results(term, page=1, page_size=10):
+ '''Returns a generator for video search results and the number of pages'''
+ return _video_results(page, page_size, q='text:{}'.format(term))