# -*- coding: utf-8 -*- """ Plugin for TvMaze Copyright (C) 2018, TonyH This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ------------------------------------------------------------- Version: 2018-08-19 - TV Calendar added. See example below 2018-05-14 Latest version to include with a Jen Release Usage Examples: All Networks country/all ------------------------------------------------------------- TV CALENDAR usage TV Calendar calendar ------------------------------------------------------------- Unites States Networks country/United States/1 For other countries, replace United States with the country name you prefer. List of Countries: Afghanistan Albania Argentina Armenia Australia Austria Azerbaijan Belarus Belgium Bosnia and Herzegovina Brazil Bulgaria Canada Chile China Colombia Croatia Cyprus Czech Republic Denmark Estonia Finland France French Polynesia Georgia Germany Greece Hong Kong Hungary Iceland India Indonesia Iran, Islamic Republic of Iraq Ireland Israel Italy Japan Kazakhstan Korea, Democratic People's Republic of Korea, Republic of Latvia Lebanon Lithuania Malaysia Maldives Mexico Moldova, Republic of Netherlands New Zealand Norway Pakistan Peru Philippines Poland Portugal Puerto Rico Qatar Romania Russian Federation Saudi Arabia Serbia Singapore Slovenia South Africa Spain Sweden Switzerland Taiwan, Province of China Thailand Turkey Ukraine United Arab Emirates United Kingdom United States Venezuela, Bolivarian Republic of ------------------------------------------------------------- ABC Network shows network/3/1 Change the number 3 to the id of the network you want. I cant find a list of all networks with thier id's so for other networks please refer to the website, https://www.tvmaze.com/networks find the network your looking for, click it and the id will be in the url. Example: https://www.tvmaze.com/networks/4/fox where 4 is the show id. So the tag for Fox would be: Fox Network shows network/4/1 ------------------------------------------------------------- Web Channels web_channel/1 -------------------------------------------------------------- """ import requests,re,os,xbmc,xbmcaddon,datetime import base64,pickle,koding,time,sqlite3 import __builtin__ from koding import route from ..plugin import Plugin from resources.lib.util.context import get_context_items from resources.lib.util.xml import JenItem, JenList, display_list, display_data, clean_url from unidecode import unidecode CACHE_TIME = 86400 # change to wanted cache time in seconds TMDB_api_key = __builtin__.tmdb_api_key addon_fanart = xbmcaddon.Addon().getAddonInfo('fanart') addon_icon = xbmcaddon.Addon().getAddonInfo('icon') User_Agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36' addon_id = xbmcaddon.Addon().getAddonInfo('id') addon_data_folder = xbmc.translatePath('special://home/userdata/addon_data') addon_data = os.path.join(addon_data_folder, addon_id) database_loc = os.path.join(addon_data, 'database.db') class TVMAZE(Plugin): name = "tvmaze" def process_item(self, item_xml): if "" in item_xml: item = JenItem(item_xml) if "country/" in item.get("tvmaze", ""): result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "country", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "files", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "network/" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "network", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "files", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "show/" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "show", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "tvshows", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "season/" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "season", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "seasons", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': {}, "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "web_channel/" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "web_channel", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "files", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "calendar" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "calendar", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "files", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item elif "day" in item.get("tvmaze", ""): item = JenItem(item_xml) result_item = { 'label': item["title"], 'icon': item.get("thumbnail", addon_icon), 'fanart': item.get("fanart", addon_fanart), 'mode': "day_episode", 'url': item.get("tvmaze", ""), 'folder': True, 'imdb': "0", 'content': "files", 'season': "0", 'episode': "0", 'info': {}, 'year': "0", 'context': get_context_items(item), "summary": item.get("summary", None) } result_item["properties"] = { 'fanart_image': result_item["fanart"] } result_item['fanart_small'] = result_item["fanart"] return result_item @route(mode='country', args=["url"]) def get_country(url): pins = "PLugintvmazecountry"+url Items = fetch_from_db2(pins) if Items: display_data(Items) else: xml = "" if "all" in url: html = "https://www.tvmaze.com/networks" html2 = requests.get(html).content block = re.compile('(.+?)',re.DOTALL).findall(html2) match = re.compile('',re.DOTALL).findall(str(block)) for number, country in match: xml += ""\ "%s"\ "country/%s/1"\ "" % (country, country) jenlist = JenList(xml) display_list(jenlist.get_list(), jenlist.get_content_type(), pins) else: last = url.split("/")[-2] num = url.split("/")[-1] html = "https://www.tvmaze.com/networks" html2 = requests.get(html).content block = re.compile('(.+?)',re.DOTALL).findall(html2) match = re.compile('',re.DOTALL).findall(str(block)) for number, country in match: if country == last: html3 = "https://www.tvmaze.com/networks?Network%5Bcountry_enum%5D="+number+"&Network%5Bsort%5D=1&page="+num html4 = requests.get(html3).content match = re.compile('
.+?(.+?)',re.DOTALL).findall(html4) for link, image, name in match: link = link.split("/")[-2] thumb = "http:"+image xml += ""\ "%s"\ "%s"\ "network/%s/1"\ "" % (name, thumb,link) try: match2 = re.compile('