From ebddc11cff6fa722b025f1ca228d05b0d47fa368 Mon Sep 17 00:00:00 2001 From: Martijn Kaijser Date: Sun, 28 Feb 2016 20:02:47 +0100 Subject: [plugin.video.spurs-tv] 2.7.0 --- plugin.video.spurs-tv/resources/__init__.py | 0 .../resources/language/English/strings.xml | 19 +++++++ plugin.video.spurs-tv/resources/lib/__init__.py | 0 plugin.video.spurs-tv/resources/lib/utils.py | 9 ++++ plugin.video.spurs-tv/resources/lib/youtube.py | 60 ++++++++++++++++++++++ plugin.video.spurs-tv/resources/settings.xml | 12 +++++ 6 files changed, 100 insertions(+) create mode 100644 plugin.video.spurs-tv/resources/__init__.py create mode 100644 plugin.video.spurs-tv/resources/language/English/strings.xml create mode 100644 plugin.video.spurs-tv/resources/lib/__init__.py create mode 100644 plugin.video.spurs-tv/resources/lib/utils.py create mode 100644 plugin.video.spurs-tv/resources/lib/youtube.py create mode 100644 plugin.video.spurs-tv/resources/settings.xml (limited to 'plugin.video.spurs-tv/resources') diff --git a/plugin.video.spurs-tv/resources/__init__.py b/plugin.video.spurs-tv/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugin.video.spurs-tv/resources/language/English/strings.xml b/plugin.video.spurs-tv/resources/language/English/strings.xml new file mode 100644 index 0000000..f18052d --- /dev/null +++ b/plugin.video.spurs-tv/resources/language/English/strings.xml @@ -0,0 +1,19 @@ + + + Official Site + YouTube Channel + Latest + Search + Next Page + Previous Page + All + Popular + Playlists + + Advanced + Debug + Official Site + Maximum video resolution + YouTube + Settings + diff --git a/plugin.video.spurs-tv/resources/lib/__init__.py b/plugin.video.spurs-tv/resources/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugin.video.spurs-tv/resources/lib/utils.py b/plugin.video.spurs-tv/resources/lib/utils.py new file mode 100644 index 0000000..9742a96 --- /dev/null +++ b/plugin.video.spurs-tv/resources/lib/utils.py @@ -0,0 +1,9 @@ +import time +from datetime import date + +def date_from_str(date_str, date_format): + return date(*(time.strptime(date_str, date_format)[0:3])) + +def add_item_info(item, title, item_date): + item['info'] = {'title': title, + 'date': item_date.strftime("%d.%m.%Y")} diff --git a/plugin.video.spurs-tv/resources/lib/youtube.py b/plugin.video.spurs-tv/resources/lib/youtube.py new file mode 100644 index 0000000..2b222a6 --- /dev/null +++ b/plugin.video.spurs-tv/resources/lib/youtube.py @@ -0,0 +1,60 @@ +import os +import json +import requests +from urlparse import urljoin, urlunparse + +import utils + +SCHEME = "https" +HOST = "www.googleapis.com" +PATH = "/youtube/v3/" + +CHANNEL_ID = "UCEg25rdRZXg32iwai6N6l0w" +API_KEY = "AIzaSyAyfLT-xP3vrQLwejc22hYe5m0RoZXX2vA" + +QS_FMT = "part=snippet&key={0}&{{0}}Id={{1}}&maxResults={{2}}&q={{3}}&order={{4}}&type=video".format(API_KEY) + + +def _get_items(resource, key="channel", id=CHANNEL_ID, max_results=50, order='date', query=""): + qs = QS_FMT.format(key, id, max_results, query, order) + url = urlunparse((SCHEME, HOST, os.path.join(PATH, resource), None, qs, None)) + response = json.loads(requests.get(url).text) + + for item in response['items']: + snippet = item['snippet'] + thumbnail = snippet['thumbnails']['high']['url'] + title = snippet['title'] + published_at = utils.date_from_str(snippet['publishedAt'].split('T')[0], "%Y-%m-%d") + + try: + id = item['id']['videoId'] # search result + except TypeError: + try: + id = snippet['resourceId']['videoId'] # playlist video + except KeyError: + id = item['id'] # playlist + + yield id, title, thumbnail, published_at + +def get_playlists(): + return _get_items("playlists") + +def get_playlist_items(playlist_id): + return _get_items("playlistItems", "playlist", playlist_id) + +def get_popular(): + return _get_items("search", max_results=14, order="viewCount") + +def get_latest(): + return _get_items("search", max_results=14) + +def get_search_results(query): + return _get_items("search", query=query) + + +if __name__ == "__main__": + for playlist_id, title, thumbnail in get_playlists(): + print + print title + for item_id, title, thumbnail in get_playlist_items(playlist_id): + print '\t', title diff --git a/plugin.video.spurs-tv/resources/settings.xml b/plugin.video.spurs-tv/resources/settings.xml new file mode 100644 index 0000000..ad12a6d --- /dev/null +++ b/plugin.video.spurs-tv/resources/settings.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + -- cgit v1.2.3