Last active
August 29, 2015 14:16
-
-
Save dbiesecke/8f777a39f08a414e53b6 to your computer and use it in GitHub Desktop.
patch for plugin.video.burningseries to scrap all with XBMCMyLibary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys, time | |
import urllib,os | |
import xbmc,xbmcplugin,xbmcgui | |
import urlparse, json | |
import threading | |
from resources.lib import mal | |
from resources.lib import common | |
from resources.lib.sites import burning | |
from resources.lib.sites import genx | |
from resources.lib.sites import tavernakoma | |
from resources.lib.sites import world24 | |
from resources.lib.sites import tube | |
from resources.lib.sites import amvnews | |
from resources.lib.sites import anisearch | |
pluginhandle = int(sys.argv[1]) | |
addon = common.get_addon() | |
image = common.get_image() | |
_clear_cache = addon.getSetting('clear_cache') == 'true' | |
load_info = addon.getSetting('load_info') | |
prefer_ihosts = addon.getSetting('prefer_ihosts') == 'true' | |
viewShows = addon.getSetting('viewShows') == 'true' | |
forceView = addon.getSetting('forceView') == 'true' | |
view = addon.getSetting('view') | |
views = { 'Liste': '50', 'Grosse Liste': '51', 'Vorschaubild': '500', 'Poster': '501', | |
'Fanart': '508', 'Medieninformationen': '504', 'Medieninformationen 2': '503', 'Medieninformationen 3': '515', 'Breit': '505' } | |
if view: | |
viewId = views[view] | |
_sites = [(genx, addon.getSetting('genx')), (burning, addon.getSetting('burning')), (tube, addon.getSetting('tube')), (world24, addon.getSetting('world24')), (tavernakoma, addon.getSetting('tavernakoma')), (anisearch, addon.getSetting('anisearch'))] | |
sites = [i[0] for i in _sites if i[1] == 'true'] | |
_mirror_sites = [(world24, addon.getSetting('world24')), (tavernakoma, addon.getSetting('tavernakoma')), (tube, addon.getSetting('tube')), (anisearch, addon.getSetting('anisearch'))] | |
mirror_sites = [i[0] for i in _mirror_sites if i[1] == 'true'] | |
def root(): | |
addDir('Neu','index.php','get_anime_list','') | |
addDir('Airing Anime', 'calendar_show.inc.php','list_airing_anime','') | |
addDir('Serien','index.php?do=display&type=tv','list_alphabet','') | |
addDir('Movies','index.php?do=display&type=movie','list_alphabet','') | |
addDir('OVAs und Specials','index.php?do=display&type=OVA+%26+Specials','list_alphabet','') | |
addDir('Genres','','list_genres','') | |
addDir('Top 100','index.php?do=toplist','get_anime_list','') | |
addDir('AMV TV','','play_amv','') | |
addDir('Suche','','list_search','') | |
addDir('Meine Anime','','list_my_anime','') | |
if _clear_cache: addDir('Clear Cache','','clear_cache','') | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def list_my_anime(): | |
my_anime_list = [] | |
entries = mal.get_my_anime_entries() | |
if entries: | |
for entry in entries: | |
for site in _sites: | |
if entry['site'] in str(site[0]): | |
id = entry['id'] | |
anime = site[0].get_anime_info(id) | |
my_anime_list.append(anime) | |
list_anime(my_anime_list) | |
def add_to_mal(): | |
id = args['url'][0] | |
site = args['site'][0] | |
try: mal.add_to_mal(site,id) | |
except: pass | |
def remove_from_mal(): | |
id = args['url'][0] | |
site = args['site'][0] | |
try: mal.remove_from_mal(site,id) | |
except: pass | |
def list_airing_anime(): | |
url = args['url'][0] | |
aids = genx.get_airing_anime_aids(url) | |
if aids: | |
anime_list = genx.get_anime_list(aids) | |
list_anime(anime_list) | |
def show_similar(): | |
name = args['name'][0] | |
anime_list = anisearch.get_similar(name) | |
anime_list = common.remove_duplicates(anime_list) | |
for anime in anime_list: | |
cover = anime['cover'] | |
name = anime['original'].encode('utf-8') | |
addDir(name,'','list_search',cover) | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def list_search(): | |
name = args['name'][0] | |
if name == 'Suche': name = False | |
aids = genx.get_search_aids(name) | |
if aids: | |
anime_list = genx.get_anime_list(aids) | |
list_anime(anime_list) | |
def list_genres(): | |
genres = genx.get_genres() | |
for genre in genres: | |
url = 'index.php?do=display&genre=%s' % genre | |
addDir(genre,url,'get_anime_list','') | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def list_alphabet(): | |
type_url = args['url'][0] | |
alphabet = genx.get_alphabet() | |
for abc in alphabet: | |
url = type_url + '&char=' + abc | |
addDir(abc,url,'get_anime_list','') | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def get_anime_list(): | |
url = args['url'][0] | |
if '&type=tv&char=' in url: | |
abc = args['name'][0] | |
anime_list = abc_threads(url,abc) | |
elif 'index.php' == url: | |
anime_list = get_new_list(url) | |
else: anime_list = genx.get_anime_list(url) | |
if anime_list: list_anime(anime_list) | |
def get_new_list(url): | |
anime_list = [] | |
for site in sites: | |
if 'genx' in str(site): | |
anime_list = genx.get_anime_list(url) | |
else: | |
new_list = site.get_new_series() | |
for anime in new_list: | |
if anime and load_info == 'true': | |
id = anime['id'] | |
anime_info = site.get_anime_info(id) | |
if anime_info: anime = anime_info | |
anime_list.insert(0, anime) | |
return anime_list | |
def abc_threads(url, abc): | |
anime_list = [] | |
threads = [] | |
for site in sites: threads.append(threading.Thread(target=get_abc_list, args=(site,anime_list,url,abc))) | |
[i.start() for i in threads] | |
[i.join() for i in threads] | |
anime_list = common.remove_duplicates(anime_list) | |
return anime_list | |
def get_abc_list(site,anime_list,url,abc): | |
if site == genx: | |
abc_list = genx.get_anime_list(url) | |
for anime in abc_list: | |
anime_list.append(anime) | |
else: | |
abc_list = site.get_abc_series(abc) | |
for anime in abc_list: | |
if anime and load_info == 'true': | |
if not anime['beschreibung']: | |
id = anime['id'] | |
anime_info = site.get_anime_info(id) | |
if anime_info: anime = anime_info | |
anime_list.append(anime) | |
return anime_list | |
def list_anime(anime_list): | |
for anime in anime_list: | |
if anime: | |
try: | |
aid = anime['id'] | |
name = anime['original'] | |
try: name = name.encode('utf-8') | |
except: name = name | |
try: | |
plot = anime['beschreibung'] | |
try: plot = plot.encode('utf-8') | |
except: plot = plot | |
except: plot = '' | |
try: episodes = anime['folgenzahl'] | |
except: episodes = 0 | |
try: | |
final_genres = '' | |
genres = anime['genre'] | |
for genre in genres: | |
try: genre = genre.encode('utf-8') | |
except: genre = genre | |
final_genres += genre+' ' | |
except: genre = '' | |
try: episodes_aired = anime['length'] | |
except: episodes_aired = 0 | |
try: | |
setting = anime['setting'] | |
try: setting = setting.encode('utf-8') | |
except: setting = setting | |
except: setting = '' | |
try: typ = anime['typ'] | |
except: typ = '' | |
try: year = anime['year'] | |
except: year = '' | |
#try: languages = anime['languages'] | |
#except: languages = 'de' | |
try: site = anime['site'] | |
except: site = 'genx' | |
try: cover = anime['cover'] | |
except: | |
if site == 'genx': cover = 'http://www.genx-anime.org/upload/cover/180px/%s.png' % str(aid) | |
else: cover = '' | |
cm = [] | |
if args['name'][0] == 'Meine Anime': | |
u=sys.argv[0]+"?url="+urllib.quote_plus(str(aid))+"&mode="+urllib.quote_plus('remove_from_mal')+"&site="+urllib.quote_plus(str(site)) | |
cm.append( ('Delete %s' % name, "XBMC.RunPlugin(%s)" % u) ) | |
else: | |
u=sys.argv[0]+"?url="+urllib.quote_plus(str(aid))+"&mode="+urllib.quote_plus('add_to_mal')+"&site="+urllib.quote_plus(str(site)) | |
cm.append( ('Add %s' % name, "XBMC.RunPlugin(%s)" % u) ) | |
addAnime(site,name,aid,'list_episodes',cover,plot,final_genres,year,episodes,episodes_aired,cm) | |
except: | |
pass | |
if not args['name'][0] == 'Neu' and not args['name'][0] == 'Top 100': | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_TITLE) | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_STUDIO) | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) | |
if viewShows: | |
xbmcplugin.setContent(pluginhandle, 'tvshows') | |
xbmcplugin.endOfDirectory(pluginhandle) | |
xbmc.sleep(100) | |
xbmc.executebuiltin('Container.SetViewMode('+viewId+')') | |
def list_episodes(): | |
site = args['site'][0] | |
id = args['url'][0] | |
name = args['name'][0] | |
anime = name | |
cover = args['iconimage'][0] | |
episodes = '' | |
if site == 'burning': | |
list_burning_seasons(id, cover) | |
else: | |
if _sites[1][1] == 'true': | |
burning_seasons = burning.get_burning_seasons(name) | |
for season in burning_seasons: | |
name = season['name'].encode('utf-8') | |
bid = season['id'] | |
cover = season['cover'] | |
addDir(name,bid,'list_burning_episodes',cover) | |
episodes = eval(site).get_episodes(id) | |
if episodes: | |
if site == 'genx': | |
for episode in episodes: | |
try: name = episodes[episode]['name'].encode('utf-8') | |
except: name = '' | |
#name = 'Folge %s: %s' % (str(episode), name) | |
name = '%s E0%s - %s' % (anime,str(episode), name) | |
addEpisode(site,name,id,'get_mirrors',anime,episode) | |
else: | |
for epi in episodes: | |
try: name = epi['name'].encode('utf-8') | |
except: name = epi['name'] | |
url = epi['url'] | |
episode = epi['episode'] | |
addEpisode(site,anime+' - '+name,url,'get_mirrors',anime,episode) | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_TITLE) | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def list_burning_seasons(id, cover): | |
seasons = burning.get_seasons(id) | |
for i in range(int(seasons)): | |
name = 'S0%s' % str(i+1) | |
new_id = '%s/%s/' % (str(id), str(i+1)) | |
addDir(name,new_id,'list_burning_episodes',cover) | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_TITLE) | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def list_burning_episodes(): | |
id = args['url'][0] | |
myanime = args['name'][0] | |
episodes = burning.get_episodes(id) | |
for episode in episodes: | |
epi = episode['epi'] | |
titlede = episode['german'] | |
titleen = episode['english'] | |
if titlede: | |
name = myanime + 'E0' + epi + ': ' + titlede | |
elif titleen: | |
name = myanime + 'E0' + epi + ': ' + titleen | |
else: | |
name = myanime + 'E0' + epi | |
name = name.encode('UTF-8') | |
new_id = '%s%s/' % (id, str(epi)) | |
addEpisode('burning',name,new_id,'play_burning','','') | |
xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_TITLE) | |
xbmcplugin.endOfDirectory(pluginhandle) | |
def get_mirrors(): | |
site = args['site'][0] | |
anime = args['anime'][0] | |
episode = args['episode'][0] | |
if site == 'genx': | |
aid = args['url'][0] | |
hoster_list = genx.get_final_hoster_list(aid, episode) | |
else: | |
hoster_list = args['url'] | |
for mirror_site in mirror_sites: | |
if not site in str(mirror_site): | |
mirror = mirror_site.get_mirror(anime, episode) | |
if mirror: hoster_list.append(mirror) | |
play(hoster_list) | |
def play_burning(): | |
id = args['url'][0] | |
hoster_list = burning.get_final_hoster_list(id) | |
play(hoster_list) | |
def play(hoster_list): | |
from resources.lib import resolver | |
hoster_list = sort_hoster_list(hoster_list) | |
print 'Hoster Liste: '+str(hoster_list) | |
file = resolver.get_file(hoster_list) | |
if file: | |
listitem = xbmcgui.ListItem(path=file) | |
if 'crunchyroll' in file: | |
try: | |
subtitle = common.get_subtitle() | |
listitem.setSubtitles([subtitle]) | |
except: | |
xbmc.executebuiltin('Notification(Kodi Required For Subtitles,)') | |
xbmcplugin.setResolvedUrl(pluginhandle, True, listitem) | |
else: | |
xbmc.executebuiltin('Notification(No Stream Available,)') | |
def play_amv(): | |
name = args['name'][0] | |
if name == 'AMV TV': | |
playlist = amvnews.amv_tv() | |
xbmc.Player().play(playlist) | |
else: | |
amv = amvnews.get_amv(name) | |
if amv: | |
file = amv['url'] | |
name = amv['name'] | |
li = xbmcgui.ListItem(name) | |
xbmc.Player().play(file, listitem=li) | |
else: | |
xbmc.executebuiltin('Notification(No AMV Available,)') | |
def play_trailer(): | |
name = args['name'][0] | |
trailer = anisearch.get_trailer(name) | |
if trailer: | |
from resources.lib import resolver | |
file = resolver.get_file([[trailer]]) | |
li = xbmcgui.ListItem(name) | |
xbmc.Player().play(file, listitem=li) | |
else: | |
xbmc.executebuiltin('Notification(No Trailer Available,)') | |
def sort_hoster_list(links): | |
ehost1 = [i for i in links if addon.getSetting('ehost1') in i] | |
ehost2 = [i for i in links if addon.getSetting('ehost2') in i] | |
ehost3 = [i for i in links if addon.getSetting('ehost3') in i] | |
ehost4 = [i for i in links if addon.getSetting('ehost4') in i] | |
ehost5 = [i for i in links if addon.getSetting('ehost5') in i] | |
ehost6 = [i for i in links if addon.getSetting('ehost6') in i] | |
ehost7 = [i for i in links if addon.getSetting('ehost7') in i] | |
ihost1 = [i for i in links if addon.getSetting('ihost1') in i] | |
ihost2 = [i for i in links if addon.getSetting('ihost2') in i] | |
ihost3 = [i for i in links if addon.getSetting('ihost3') in i] | |
ihost6 = [i for i in links if addon.getSetting('ihost6') in i] | |
ihost7 = [i for i in links if addon.getSetting('ihost7') in i] | |
ihost8 = [i for i in links if addon.getSetting('ihost8') in i] | |
ihost9 = [i for i in links if addon.getSetting('ihost9') in i] | |
ihost10 = [i for i in links if addon.getSetting('ihost10') in i] | |
if prefer_ihosts: return [ihost1,ihost2,ihost3,ihost6,ihost7,ihost8,ihost9,ihost10,ehost1,ehost2,ehost3,ehost4,ehost5,ehost6,ehost7] | |
else: return [ehost1,ehost2,ehost3,ehost4,ehost5,ehost6,ehost7,ihost1,ihost2,ihost3,ihost6,ihost7,ihost8,ihost9,ihost10] | |
def clear_cache(): | |
try: | |
common.clear_cache() | |
addon.setSetting(id='clear_cache', value='false') | |
xbmc.executebuiltin('Notification(Cache Deleted,)') | |
except: | |
xbmc.executebuiltin('Notification(Error While Deleting Cache,)') | |
def build_url(query): | |
return sys.argv[0] + '?' + urllib.urlencode(query) | |
def addEpisode(site,name,url,mode,anime,episode): | |
u = build_url({'site': site, 'mode': mode, 'name': name, 'url': url, 'anime': anime, 'episode': episode}) | |
item=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage='') | |
item.setInfo( type="Video", infoLabels={ "Title": name } ) | |
item.setProperty('IsPlayable', 'true') | |
xbmcplugin.addDirectoryItem(pluginhandle,url=u,listitem=item) | |
def addAnime(site,name,url,mode,iconimage,plot,genre,year,episodes,episodes_aired,cm): | |
if not iconimage: iconimage = image | |
u = build_url({'site': site, 'mode': mode, 'name': name, 'url': url, 'iconimage': iconimage}) | |
item=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage) | |
item.setInfo( type="Video", infoLabels={ "Title": name, "Plot": plot, "Genre": genre, "Year": year, "Episode": episodes, "Studio": site } ) | |
amv_uri=build_url({'mode': 'play_amv', 'name': name}) | |
cm.append( ('Play AMV', "XBMC.RunPlugin(%s)" % amv_uri) ) | |
trailer_uri=build_url({'mode': 'play_trailer', 'name': name}) | |
cm.append( ('Play Trailer', "XBMC.RunPlugin(%s)" % trailer_uri) ) | |
similar_uri=build_url({'mode': 'show_similar', 'name': name}) | |
cm.append( ('Show Similar', "Container.Update(%s)" % similar_uri) ) | |
item.addContextMenuItems( cm ) | |
xbmcplugin.addDirectoryItem(pluginhandle,url=u,listitem=item,isFolder=True) | |
def addDir(name,url,mode,iconimage): | |
if not iconimage: iconimage = image | |
u = build_url({'mode': mode, 'name': name, 'url': url, 'iconimage': iconimage}) | |
item=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage) | |
xbmcplugin.addDirectoryItem(pluginhandle,url=u,listitem=item,isFolder=True) | |
args = urlparse.parse_qs(sys.argv[2][1:]) | |
mode = args.get('mode', None) | |
print 'Arguments: '+str(args) | |
if mode==None: | |
root() | |
else: | |
exec '%s()' % mode[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import xbmc,os,re,time | |
import json | |
from resources.lib import simple_requests as requests | |
from resources.lib import json_handle | |
from resources.lib import common | |
site = 'burning' | |
api_url = 'https://www.burning-seri.es/api/' | |
genre_url = api_url+'series:genre/' | |
series_url = api_url+'series/' | |
cover_url = 'https://s.burning-seri.es/img/cover/%s.jpg' | |
timeout = common.get_timeout() | |
def get_burning_seasons(name): | |
burning_seasons = [] | |
anime_list = get_complete_anime_list() | |
animename = name | |
match = common.find_anime(name, anime_list, clean_burning=True) | |
for series in match: | |
b_id = series['id'] | |
b_name = series['original'] | |
cover = 'https://s.burning-seri.es/img/cover/%s.jpg' % b_id | |
seasons = get_seasons(b_id) | |
for i in range(int(seasons)): | |
name = animename+' S0%s' % str(i+1) | |
id = '%s/%s/' % (str(b_id), str(i+1)) | |
burning_seasons.append({'name': name, 'id':id, 'cover': cover}) | |
return burning_seasons | |
def get_abc_series(abc): | |
abc_list = [] | |
if abc == 'num': abc = ('.','0', '1', '2', '3', '4', '5', '6', '7', '8', '9') | |
elif abc == 'all': abc = '' | |
else: abc = abc.lower() | |
anime_list = get_complete_anime_list() | |
if abc: | |
for anime in anime_list: | |
if anime['original'].lower().startswith(abc): | |
abc_list.append(anime) | |
else: | |
abc_list = anime_list | |
return abc_list | |
def get_new_series(): | |
return [] | |
def get_anime_info(id): | |
anime = [] | |
try: | |
json_data = get_anime_json(id) | |
name = json_data['series']['series'].encode('UTF-8') | |
id = json_data['series']['id'] | |
cover = 'https://s.burning-seri.es/img/cover/%s.jpg' % id | |
try: beschreibung = json_data['series']['description'] | |
except: beschreibung = '' | |
try: year = json_data['series']['start'] | |
except: year = '' | |
try: genres = json_data['series']['data']['genre'] | |
except: genres = [] | |
anime = ({'site': site, 'original': name, 'id': id, 'cover': cover, 'beschreibung': beschreibung, 'year': year, 'genre': genres}) | |
except: | |
pass | |
return anime | |
def get_complete_anime_list(): | |
cache_url = common.cleanfilename(genre_url) | |
anime_list = json_handle.load_json(site, cache_url, cache_time=1) | |
if anime_list: | |
return anime_list | |
else: | |
anime_list = [] | |
genre = 'Anime' | |
try: | |
json_data = requests.get(genre_url, timeout=timeout).json() | |
series = json_data[genre]['series'] | |
for serie in series: | |
name = serie['name'].encode('UTF-8') | |
id = serie['id'] | |
cover = 'https://s.burning-seri.es/img/cover/%s.jpg' % id | |
anime_list.append({'site': site, 'original': name, 'id': id, 'cover': cover, 'beschreibung': '', 'year': '', 'genre': ''}) | |
json_handle.save_json(site, cache_url, anime_list) | |
except: | |
pass | |
return anime_list | |
def get_anime_list(bids): | |
anime_list = [] | |
for id in bids: | |
anime = get_anime_info(id) | |
anime_list.append(anime) | |
return anime_list | |
def get_anime_json(id): | |
json_data = '' | |
site = 'burning' | |
json_data = json_handle.load_json(site, id) | |
if json_data: | |
return json_data | |
else: | |
try: | |
url = series_url+str(id)+'/1/' | |
json_data = requests.get(url, timeout=timeout).json() | |
json_handle.save_json(site, id, json_data) | |
except: | |
pass | |
return json_data | |
def get_seasons(id): | |
seasons = [] | |
try: | |
json_data = get_anime_json(id) | |
seasons = json_data['series']['seasons'] | |
except: | |
pass | |
return seasons | |
def get_episodes(id): | |
episodes = [] | |
try: | |
url = series_url+id | |
json_data = requests.get(url, timeout=timeout).json() | |
episodes = json_data['epi'] | |
except: | |
pass | |
return episodes | |
def get_final_hoster_list(id): | |
links = [] | |
hoster_list = get_hoster(id) | |
for hoster in hoster_list: | |
id = hoster['id'] | |
link = get_stream_link(id) | |
links.append(link) | |
return links | |
def get_hoster(id): | |
hoster = [] | |
try: | |
url = series_url+id | |
json_data = requests.get(url, timeout=timeout).json() | |
hoster = json_data['links'] | |
except: | |
pass | |
return hoster | |
def get_stream_link(id): | |
link = [] | |
try: | |
watch_url = api_url+'watch/%s' % id | |
json_data = requests.get(watch_url).json() | |
link = json_data['fullurl'] | |
except: | |
pass | |
return link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import xbmc, xbmcgui, xbmcplugin, xbmcaddon, xbmcvfs | |
import sys, random | |
import urllib, urllib2, cookielib | |
import re, base64 | |
from watched import * | |
from array import * | |
from htmlentitydefs import name2codepoint as n2cp | |
import htmlentitydefs | |
# new since v0.95 | |
import urlresolver | |
# new since 1.3.0 | |
from player import bsPlayer | |
thisPlugin = int(sys.argv[1]) | |
print thisPlugin | |
edenCompatibility = xbmcplugin.getSetting(thisPlugin,"caching") | |
if edenCompatibility=="true": | |
useCaching=True | |
else: | |
useCaching=False | |
print "-- switched off caching for eden-compatibility" | |
addonInfo = xbmcaddon.Addon() | |
cacheFile = addonInfo.getAddonInfo('path')+"/cache.data" | |
urlHost = "http://www.burning-seri.es/" | |
# by Alphabet | |
regexContentA = "<ul id='serSeries'>(.*?)</ul>" | |
regexContentB = '<li><a href="(.*?)">(.*?)</a></li>' | |
regexContentC = '<div class="genre">.*?<span><strong>(.*?)</strong></span>.*?<ul>(.*?)</ul>.*?</div>' | |
regexSeasonsA = '<ul class="pages">.*?</ul>' | |
regexSeasonsB = '<li.*?><a href="(.*?)">([^<]+)</a></li>' | |
regexSeasonsPic = 'id="sp_right">.*?<img src="(.*?)" alt="[cC]+over"/>' | |
regexEpisodesA = '<table>.*?</table>' | |
regexEpisodesB = '(<td>([^<]+)</td>[\\n\s]+<td><a href="([^"]+)">[\\n\s]+(<strong>[^<]+</strong>)?[\\n\s]+(<span lang="en">[^<]+</span>)?[\\n\s]+</a></td>[\\n\s]+<td class="nowrap">[\\n\s]+<a class.*?</td>.*?</tr>)' | |
regexEpisodesC = '<strong>(.*?)</strong>' | |
regexEpisodesD = '<span lang="en">(.*?)</span>' | |
regexHostsA = 'Episode</h3>.*?<ul style="width: [0-9]{1,3}px;">(.*?)</ul>.*?</section>' | |
regexHostsB = '<a.*?href="(.*?)"><span.*?class="icon (.*?)"></span>(.*?)</a>' | |
regexShowA = '<div id="video_actions">.*?<div>.*?<a href="(.*?)" target="_blank"><span' | |
# ------------------------ | |
# compile regexes on start | |
cRegConA = re.compile(regexContentA,re.DOTALL) | |
cRegConB = re.compile(regexContentB,re.DOTALL) | |
cRegConC = re.compile(regexContentC,re.DOTALL) | |
cRegSeaA = re.compile(regexSeasonsA,re.DOTALL) | |
cRegSeaB = re.compile(regexSeasonsB,re.DOTALL) | |
cRegSeaPic = re.compile(regexSeasonsPic,re.DOTALL) | |
cRegEpiA = re.compile(regexEpisodesA,re.DOTALL) | |
cRegEpiB = re.compile(regexEpisodesB,re.DOTALL) | |
cRegEpiC = re.compile(regexEpisodesC,re.DOTALL) | |
cRegEpiD = re.compile(regexEpisodesD,re.DOTALL) | |
cRegHosA = re.compile(regexHostsA,re.DOTALL) | |
cRegHosB = re.compile(regexHostsB,re.DOTALL) | |
cRegShoA = re.compile(regexShowA,re.DOTALL) | |
# --------- | |
# functions | |
def showContent(sortType): | |
global thisPlugin | |
print "[bs][showContent] started" | |
seriesList = {} | |
serie =[] | |
picture = "" | |
content = getUrl(urlHost+"serie-genre") | |
if content: | |
content = content.replace("&","&") | |
#print content | |
matchC = cRegConC.findall(content) | |
for n in matchC: | |
#print n | |
matchB = cRegConB.findall(n[1]) | |
for m in matchB: | |
if sortType[0] == "G": | |
serie = [n[0]+" : "+m[1].strip()+"",m[0],picture] | |
lKey = n[0] | |
if sortType[0] == "A": | |
serie = [""+m[1].strip()+" ("+n[0]+")",m[0],picture] | |
helper = ord(m[1][0]) | |
if helper>90: | |
helper = helper-32 | |
if (helper>64) and (helper<91): | |
lKey = chr(helper).upper() | |
else: | |
lKey = "0" | |
if lKey in seriesList: | |
seriesList[lKey].append(serie) | |
else: | |
seriesList[lKey] = [] | |
seriesList[lKey].append(serie) | |
if len(sortType)==1: | |
addDirectoryItem(".sort by Alphabet", {"sortType": "A"}) | |
addDirectoryItem(".sort by Genre", {"sortType": "G"}) | |
addDirectoryItem("", {"sortType": "A"}) | |
for key in sorted(seriesList): | |
skey = key | |
if key =="0": | |
skey = "0-9 etc" | |
addDirectoryItem(""+skey+" (%d)" % len(seriesList[key]), {"sortType": sortType+key}) | |
else: | |
sKey = sortType[1:] | |
for s in sorted(seriesList[sKey], key=lambda f:f[0]): | |
if useCaching: | |
cachedPic = readPictureData(s[1]) | |
if cachedPic: | |
picture = cachedPic | |
print "[bs][showContent] -- cached pic existing - "+picture | |
else: | |
print "[bs][showContent] -- pic not in cache" | |
cPic = getUrl(urlHost+s[1]) | |
if cPic: | |
cPic = cPic.replace("&","&") | |
matchPic = cRegSeaPic.findall(cPic) | |
try: | |
picture = "https:"+matchPic[0] | |
except IndexError: | |
picture = "" | |
cachedPic = writePictureData(urllib.unquote(s[1]), picture) | |
seriesName = unescape(s[0]) | |
# check if watched | |
if readWatchedData(urlHost+s[1]): | |
seriesName = changeToWatched(seriesName) | |
addDirectoryItem(seriesName, {"urlS": s[1], "series":s[1],"doFav":"0"},picture) | |
else: | |
addDirectoryItem("Oops there was an url-error. network?", {"sortType": sortType}) | |
print "[bs][showContent] --- ok" | |
xbmcplugin.endOfDirectory(thisPlugin) | |
def showSeasons(urlS,series,doFav): | |
global thisPlugin | |
matchCover = "" | |
print "[bs][showSeasons] started with "+urlS | |
print "[bs][showSeasons]--- series Data" | |
print series | |
content = getUrl(urlS) | |
matchA = cRegSeaA.findall(content) | |
if matchA: | |
matchB = cRegSeaB.findall(matchA[0]) | |
print "-- matchB" | |
#print matchB | |
if useCaching: | |
matchCover = readPictureData(series) | |
print "[bs][showSeasons] -- cached Picture - "+matchCover | |
addDirectoryItem(". "+series.replace("serie/","").replace("-"," ")+"", {},matchCover) | |
seasonsWatched = 0 | |
for m in matchB: | |
preString = "" | |
if is_number(m[1]): | |
preString = "Staffel " | |
seasonName = unescape(preString+m[1]) | |
# check if watched | |
if readWatchedData(urlHost+m[0]): | |
seasonsWatched +=1 | |
seasonName = changeToWatched(seasonName) | |
addDirectoryItem(seasonName, {"urlE": m[0], "series":series}, matchCover) | |
#print m | |
# mark series if all seasons were watched | |
if seasonsWatched == len(matchB): | |
markParentEntry(urlHost+series) | |
else: | |
addDirectoryItem("ERROR in Seasons matchA", {"urlS": urlS}) | |
print "[bs][showSeasons] --- ok" | |
xbmcplugin.endOfDirectory(thisPlugin) | |
def showEpisodes(urlE,series): | |
global thisPlugin | |
matchCover = "" | |
print "[bs][showEpisodes] started with "+urlE | |
content = getUrl(urlE) | |
#print content | |
print "[bs] --- series Data" | |
print series | |
matchA = cRegEpiA.findall(content) | |
if useCaching: | |
print "[bs][showEpisodes] -- reading cached picture - "+series | |
matchCover = readPictureData(series) | |
print "[bs][showEpisodes] cached Picture - "+matchCover | |
print "[bs][showEpisodes] ---matchA" | |
#print matchA | |
if matchA: | |
print "found matchA - now regexing" | |
matchB = cRegEpiB.findall(matchA[0]) | |
print "matchB regexed" | |
if matchB: | |
#print "[bs][showEpisodes] ---matchB" | |
episodesWatched = 0 | |
for m in matchB: | |
matchD = cRegEpiD.findall(m[0]) | |
if matchD: | |
englishTitle = " - "+matchD[0] | |
else: | |
englishTitle = "" | |
mS = cRegEpiC.findall(m[0]) | |
#print mS | |
if mS: | |
print mS | |
matchStrong = " - "+mS[0] | |
else: | |
matchStrong = "" | |
episodeName = unescape(series.replace("serie/","").replace("-"," ")+matchStrong+englishTitle) | |
# check if watched | |
if readWatchedData(urlHost+m[2]): | |
episodesWatched += 1 | |
episodeName = changeToWatched(episodeName) | |
addDirectoryItem(episodeName, {"urlH": m[2], "series":series, "urlE":urlE},matchCover) | |
# if watched all episodes, mark Season | |
if episodesWatched == len(matchB): | |
markParentEntry(urlE) | |
else: | |
addDirectoryItem("ERROR in Episodes B regex - matchB", {"urlH": ""}) | |
else: | |
addDirectoryItem("ERROR in Episodes A regex - matchA", {"urlH": ""}) | |
print "[bs][showEpisodes] ok" | |
xbmcplugin.endOfDirectory(thisPlugin) | |
def showHosts(urlH, series, urlE): | |
global thisPlugin | |
matchCover = "" | |
print "[bs][showHosts] started with "+urlH | |
if useCaching: | |
matchCover = readPictureData(series) | |
print "[bs][showHosts] cached Picture - "+matchCover | |
content = getUrl(urlH) | |
#print "-- showHosts" | |
#print content | |
matchA = cRegHosA.findall(content) | |
print "[bs][showHosts] -- matchesA" | |
print matchA | |
matchB = cRegHosB.findall(matchA[0]) | |
print "[bs][showHosts] -- matchB" | |
print matchB | |
for m in matchB: | |
#print m | |
addDirectoryItem("Host: "+m[1].strip(), {"urlV": m[0],"urlE":urlE},matchCover) | |
print "[bs][showHosts] -- "+m[1]+" : "+m[0] | |
print "[bs][showHosts] ok" | |
xbmcplugin.endOfDirectory(thisPlugin) | |
def showVideo(urlV,urlE): | |
global thisPlugin | |
print "[bs][showVideo] started on "+urlV | |
print "[bs][showVideo] got urlE for watchedStatus: "+urlE | |
content = getUrl(urlV) | |
if content: | |
#print content | |
matchVideo = cRegShoA.findall(content) | |
print "[bs][showVideo] matchVideo - "+matchVideo[0] | |
videoLink = urlresolver.resolve(matchVideo[0]); | |
print "[bs][showVideo] urlResolver returns - " | |
print videoLink | |
if videoLink: | |
print "[bs][showVideo] urlResolver videoLink --" | |
print videoLink | |
#videoLink = unescape(videoLink) | |
item = xbmcgui.ListItem(path=videoLink) | |
bsPlayer().playStream(videoLink,urlV[:urlV.rfind("/")]) | |
else: | |
addDirectoryItem("ERROR. Video deleted or urlResolver cant handle Host", {"urlV": "/"}) | |
xbmcplugin.endOfDirectory(thisPlugin) | |
else: | |
addDirectoryItem("ERROR. Video deleted or urlResolver cant handle Host", {"urlV": "/"}) | |
xbmcplugin.endOfDirectory(thisPlugin) | |
#def showFavorites(): | |
# global thisPlugin | |
# print "[bs][showFavorites] started" | |
# favs.add_my_fav_directory() | |
# -------- helper ------ | |
def is_number(s): | |
try: | |
float(s) | |
return True | |
except ValueError: | |
return False | |
def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"): | |
return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b]) | |
def getUrl(url): | |
try: | |
req = urllib2.Request(url) | |
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3') | |
response = urllib2.urlopen(req) | |
return response.read() | |
response.close() | |
except: | |
return False | |
def addDirectoryItem(name, parameters={},pic=""): | |
iconpic = pic | |
if pic == "": | |
iconpic = "DefaultFolder.png" | |
li = xbmcgui.ListItem(name,iconImage=iconpic, thumbnailImage=pic) | |
url = sys.argv[0] + '?' + urllib.urlencode(parameters) | |
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=True) | |
def addPlayableItem(name, parameters={},pic=""): | |
iconpic = pic | |
if pic == "": | |
iconpic = "DefaultFolder.png" | |
li = xbmcgui.ListItem(name,iconImage=iconpic, thumbnailImage=pic) | |
li.setProperty("IsPlayable","true") | |
url = sys.argv[0] + '?' + urllib.urlencode(parameters) | |
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=False) | |
def parameters_string_to_dict(parameters): | |
''' Convert parameters encoded in a URL to a dict. ''' | |
paramDict = {} | |
if parameters: | |
paramPairs = parameters[1:].split("&") | |
for paramsPair in paramPairs: | |
paramSplits = paramsPair.split('=') | |
if (len(paramSplits)) == 2: | |
paramDict[paramSplits[0]] = paramSplits[1] | |
return paramDict | |
def unescape(text): | |
def fixup(m): | |
text = m.group(0) | |
if text[:2] == "&#": | |
# character reference | |
try: | |
if text[:3] == "&#x": | |
return unichr(int(text[3:-1], 16)) | |
else: | |
return unichr(int(text[2:-1])) | |
except ValueError: | |
pass | |
else: | |
# named entity | |
try: | |
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]]) | |
except KeyError: | |
pass | |
return text # leave as is | |
return re.sub("&#?\w+;", fixup, unicode(text, "UTF-8"), re.UNICODE) | |
# since v1.1.0 | |
def writePictureData(id,url): | |
global cacheFile | |
f = xbmcvfs.File(cacheFile) | |
d = f.read() | |
f.close() | |
f = xbmcvfs.File(cacheFile, 'w') | |
b = d+id+"<>"+url+"\n" | |
result = f.write(b) | |
print "[bs][writePictureData] write -> "+ id + " <> " +url | |
f.close() | |
return result | |
def readPictureData(id): | |
global cacheFile | |
f = xbmcvfs.File(cacheFile) | |
b = f.read() | |
f.close() | |
cacheData = b.splitlines() | |
for n in cacheData: | |
splittedData = n.split("<>") | |
if splittedData[0]==id: | |
print "[bs][readPictureData] found cached "+id | |
return splittedData[1] | |
return False | |
# ----- main ----- | |
# ---------------- | |
params = parameters_string_to_dict(sys.argv[2]) | |
#showFavs = str(params.get("showFavs","")) | |
sortType = str(params.get("sortType", "")) | |
urlSeasons = str(params.get("urlS", "")) | |
doFav = str(params.get("doFav","")) | |
urlEpisodes = str(params.get("urlE", "")) | |
urlHosts = str(params.get("urlH", "")) | |
urlVideo = str(params.get("urlV", "")) | |
seriesName = str(params.get("sName", "")) | |
dataSeries = urllib.unquote(str(params.get("series", ""))) | |
if not sys.argv[2]: | |
# new start | |
ok = showContent("A") | |
else: | |
if sortType: | |
ok = showContent(sortType) | |
# if showFavs: | |
# ok = showFavorites() | |
if urlSeasons: | |
newUrl = urlHost + urllib.unquote(urlSeasons) | |
#print newUrl | |
ok = showSeasons(newUrl,dataSeries, doFav) | |
if urlEpisodes and not urlHosts and not urlVideo: | |
newUrl = urlHost + urllib.unquote(urlEpisodes) | |
#print newUrl | |
ok = showEpisodes(newUrl,dataSeries) | |
if urlHosts: | |
newUrl = urlHost + urllib.unquote(urlHosts) | |
#print newUrl | |
ok = showHosts(newUrl,dataSeries,urlEpisodes) | |
if urlVideo: | |
newUrl = urlHost + urllib.unquote(urlVideo) | |
#print newUrl | |
ok = showVideo(newUrl,urlEpisodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment