1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# -*- coding: utf-8 -*-
# Wakanim - Watch videos from the german anime platform Wakanim.tv on Kodi.
# Copyright (C) 2017 MrKrabat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import urllib
import xbmc
import xbmcgui
import xbmcplugin
# keys allowed in setInfo
types = ["count", "size", "date", "genre", "year", "episode", "season", "top250", "tracknumber",
"rating", "userrating", "watched", "playcount", "overlay", "cast", "castandrole", "director",
"mpaa", "plot", "plotoutline", "title", "originaltitle", "sorttitle", "duration", "studio",
"tagline", "writer", "tvshowtitle", "premiered", "status", "code", "aired", "credits", "lastplayed",
"album", "artist", "votes", "trailer", "dateadded", "mediatype"]
def endofdirectory():
# sort methods are required in library mode
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE)
# let xbmc know the script is done adding items to the list
xbmcplugin.endOfDirectory(handle = int(sys.argv[1]))
def add_item(args, info, isFolder=True, total_items=0, mediatype="video"):
"""Add item to directory listing.
"""
# create list item
li = xbmcgui.ListItem(label = info["title"])
# get infoLabels
infoLabels = make_infolabel(args, info)
infoLabels["genre"] = "Anime"
# get url
u = build_url(args, info)
if isFolder:
# directory
li.setInfo(mediatype, infoLabels)
else:
# playable video
infoLabels["mediatype"] = "video"
li.setInfo(mediatype, infoLabels)
li.setProperty("IsPlayable", "true")
# set media image
li.setArt({"thumb": info.get("thumb", "DefaultFolder.png"),
"poster": info.get("thumb", "DefaultFolder.png"),
"banner": info.get("thumb", "DefaultFolder.png"),
"fanart": info.get("fanart", xbmc.translatePath(args._addon.getAddonInfo("fanart"))),
"icon": info.get("thumb", "DefaultFolder.png")})
# add item to list
xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]),
url = u,
listitem = li,
isFolder = isFolder,
totalItems = total_items)
def quote_value(value):
return urllib.quote_plus(value.encode("utf8") if isinstance(value, unicode) else value)
def build_url(args, info):
"""Create url
"""
s = ""
# step 1 copy new information from info
for key, value in info.iteritems():
if value:
s = s + "&" + key + "=" + quote_value(value)
# step 2 copy old information from args, but don't append twice
for key, value in args.__dict__.iteritems():
if value and key in types and not "&" + str(key) + "=" in s:
s = s + "&" + key + "=" + quote_value(value)
return sys.argv[0] + "?" + s[1:]
def make_infolabel(args, info):
"""Generate infoLabels from existing dict
"""
infoLabels = {}
# step 1 copy new information from info
for key, value in info.iteritems():
if value and key in types:
infoLabels[key] = value
# step 2 copy old information from args, but don't overwrite
for key, value in args.__dict__.iteritems():
if value and key in types and key not in infoLabels:
infoLabels[key] = value
return infoLabels
|