/
plugin_content.py
154 lines (140 loc) · 5.82 KB
/
plugin_content.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
import xbmcplugin
from resources.lib.helper import *
from resources.lib.pvr_running_at import PVRRunningAt
from resources.lib.pvr_timers import PVRTimers
from resources.lib.pvr_channellist import PVRChannelList
#######################################################################################
class PluginContent:
def __init__(self):
self.resultlist = list()
def result(self):
return self.resultlist
def fetchNextEpisodes( self ):
inprogress_shows = self.getInprogressTVShows()
for show in inprogress_shows:
tvshowid = int(show['tvshowid'])
last_played_episode = self.getLastPlayedEpisode(tvshowid)
if not last_played_episode:
continue
next_episode_id = self.getNextEpisode(tvshowid, last_played_episode)
if (next_episode_id > 0):
next_episode = self.getEpisode(next_episode_id)
append_items(self.resultlist,[next_episode],type='episodes')
def fetchActors( self, movie_id, tvshow ):
cast = []
if movie_id:
query = json_call('VideoLibrary.GetMovieDetails',
properties=['cast'],
params={'movieid': int(movie_id)}
)
cast = query['result']['moviedetails']['cast']
elif tvshow:
query = json_call('VideoLibrary.GetTVShows',
properties=['cast'],
limit=1,
query_filter={'operator': 'is', 'field': 'title', 'value': tvshow}
)
cast = query['result']['tvshows'][0]['cast']
append_items(self.resultlist,cast,type='cast')
def fetchRunningAt( self, pointintime, channel_ids ):
running_at = PVRRunningAt()
ok = pvrAvailable()
if not ok:
log("pvr not available, aborting")
return
channel_ids = channel_ids.replace('-', ',')
channel_ids = json.loads(channel_ids)
broadcast_ids = []
for channel_id in channel_ids:
bc = running_at.getBroadcastAt(pointintime, channel_id)
if bc:
broadcast = {
'broadcastid': bc['broadcastid'],
'channelid': channel_id
}
broadcast_ids.append(broadcast)
broadcasts = running_at.getBroadcastsById(broadcast_ids)
append_items(self.resultlist, broadcasts, type='broadcasts')
def fetchTimers(self):
ok = pvrAvailable()
if not ok:
log("pvr not available, aborting")
return
ti = PVRTimers()
timers = ti.fetchTimers()
for t in timers:
channel = ti.fetchChannel(t['channelid'])
if channel:
t['channelicon'] = channel['icon']
else:
t['channelicon'] = ''
append_items(self.resultlist, timers, type='timers')
def fetchBroadcasts(self, channel_num, channel_ids):
channel_id = -1
try:
channel_id = channel_ids[channel_num]
except Exception:
return
cl = PVRChannelList()
broadcasts = cl.fetchBroadcasts(channel_id)
append_items(self.resultlist, broadcasts, type='broadcasts_short')
#######################################################################################
# private
#######################################################################################
def getInprogressTVShows(self):
query = json_call('VideoLibrary.GetTVShows',
properties=[],
limit=25,
sort={"method": "lastplayed", "order": "descending"},
query_filter={'field': 'inprogress', 'operator': 'true', 'value': ''}
)
try:
tvshows = query['result']['tvshows']
except Exception:
log('getNextEpisodes: No Inprogress TVShows found.')
return []
return tvshows
def getLastPlayedEpisode( self, tvshowid ):
query = json_call('VideoLibrary.GetEpisodes',
properties=['season'],
limit=1,
sort={"method": "lastplayed", "order": "descending"},
query_filter={"field":"playcount", "operator":"isnot", "value":"0"},
params={'tvshowid': tvshowid}
)
try:
last_played = query['result']['episodes']
except Exception:
log('getLastPlayedEpisode: No Last Played Episode found.')
return 0
return last_played[0]
def getNextEpisode( self, tvshowid, last_played_episode ):
season = last_played_episode['season'] - 1
query = json_call('VideoLibrary.GetEpisodes',
properties=[],
sort={"method": "episode"},
query_filter={"field":"season", "operator":"greaterthan", "value":"%s" % season},
params={'tvshowid': tvshowid}
)
try:
episodes = query['result']['episodes']
except Exception:
return 0
found = False
for episode in episodes:
if (found):
return episode['episodeid']
if (episode['episodeid'] == last_played_episode['episodeid']):
found = True
return 0
def getEpisode( self, episodeid ):
query = json_call('VideoLibrary.GetEpisodeDetails',
properties=episode_properties,
params={'episodeid': episodeid}
)
try:
episode = query['result']['episodedetails']
except Exception:
return {}
return episode