-
Notifications
You must be signed in to change notification settings - Fork 0
/
appfeed.py
355 lines (321 loc) · 14.9 KB
/
appfeed.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulStoneSoup
from BeautifulSoup import BeautifulSoup
import xbmcplugin
import xbmc
import xbmcgui
import os.path
import sys
import urllib
import resources.lib.common as common
import re
import demjson
import listtv
import listmovie
import xbmclibrary
import movies as moviesDB
import tv as tvDB
pluginhandle = common.pluginhandle
confluence_views = [500,501,502,503,504,508]
#Modes
#===============================================================================
# 'catalog/GetCategoryList'
# 'catalog/Browse'
# 'catalog/Search'
# 'catalog/GetSearchSuggestions'
# 'catalog/GetASINDetails'
# 'catalog/GetSimilarities'
#
# 'catalog/GetStreamingUrls'
# 'catalog/GetStreamingTrailerUrls'
# 'catalog/GetContentUrls'
#
# 'library/GetLibrary'
# 'library/Purchase'
# 'library/GetRecentPurchases'
#
# 'link/LinkDevice'
# 'link/UnlinkDevice'
# 'link/RegisterClient'
# 'licensing/Release'
#
# 'usage/UpdateStream'
# 'usage/ReportLogEvent'
# 'usage/ReportEvent'
# 'usage/GetServerConfig'
#===============================================================================
MAX_VALUES = [25,50,100,150,200,250]
MAX=MAX_VALUES[int(common.addon.getSetting("perpage"))]
common.gen_id()
deviceID = common.addon.getSetting("GenDeviceID")#'000000000000'
deviceTypeID = 'A2W5AJPLW5Q6YM' #Android Type
#deviceTypeID = 'A13Q6A55DBZB7M' #WEB Type
firmware = 'fmw:15-app:1.1.19'
format = 'json'
PARAMETERS = '?firmware='+firmware+'&deviceTypeID='+deviceTypeID+'&deviceID='+deviceID+'&format='+format
def BUILD_BASE_API(MODE,HOST='https://atv-ext.amazon.com/cdp/'):
return HOST+MODE+PARAMETERS
def getList(ContentType,start=0,isPrime=True,NumberOfResults=250,OrderBy='SalesRank',version=2):
if isPrime:
BROWSE_PARAMS = '&OfferGroups=B0043YVHMY'
BROWSE_PARAMS +='&NumberOfResults='+str(NumberOfResults)
BROWSE_PARAMS +='&StartIndex='+str(start)
BROWSE_PARAMS +='&ContentType='+ContentType
BROWSE_PARAMS +='&OrderBy='+OrderBy
#BROWSE_PARAMS +='&Detailed=T'
#BROWSE_PARAMS +='&IncludeNonWeb=T'
#BROWSE_PARAMS +=
#&HighDef=F # T or F ??
#&playbackInformationRequired=false
#&OrderBy=SalesRank
#SuppressBlackedoutEST=T
#&HideNum=T
#&Detailed=T
#&AID=1
#&IncludeNonWeb=T
BROWSE_PARAMS +='&version='+str(version)
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS
return demjson.decode(common.getATVURL(url))
def ASIN_LOOKUP(ASINLIST):
results = len(ASINLIST.split(','))-1
# &NumberOfResults=400
BROWSE_PARAMS = '&asinList='+ASINLIST+'&NumberOfResults='+str(results)+'&IncludeAll=T&playbackInformationRequired=true&version=2'
url = BUILD_BASE_API('catalog/GetASINDetails')+BROWSE_PARAMS
return demjson.decode(common.getATVURL(url))
def URL_LOOKUP(url):
return demjson.decode(common.getATVURL(url+PARAMETERS.replace('?','&')))
################################ Library listing
def APP_ROOT():
common.addDir('Prime Movie Categories','appfeed','APP_LEVEL2','2,2')
common.addDir('Prime TV shows Categories','appfeed','APP_LEVEL2','3,2')
common.addDir('All Seasons','appfeed','BROWSE_SEASONS','')
common.addDir('All Shows','appfeed','BROWSE_SERIES','')
common.addDir('Full Category List','appfeed','APP_LEVEL0','')
xbmcplugin.endOfDirectory(pluginhandle)
def APP_LEVEL0():
url = BUILD_BASE_API('catalog/GetCategoryList')+'&version=1'
data = common.getATVURL(url)
json = demjson.decode(data)
del data
categories = json['message']['body']['categories']
del json
for item in categories:
if item.has_key('categories'):
common.addDir(item['title'],'appfeed','APP_LEVEL1',str(categories.index(item)))
else:
common.addDir(item['title'],'appfeed','BROWSE',item['query'])
xbmcplugin.endOfDirectory(pluginhandle)
def APP_LEVEL1():
url = BUILD_BASE_API('catalog/GetCategoryList')+'&version=1'
data = common.getATVURL(url)
json = demjson.decode(data)
del data
categories = json['message']['body']['categories'][int(common.args.url)]['categories']
del json
for item in categories:
if item.has_key('categories'):
common.addDir(item['title'],'appfeed','APP_LEVEL2',common.args.url+','+str(categories.index(item)))
else:
common.addDir(item['title'],'appfeed','BROWSE',item['query'])
xbmcplugin.endOfDirectory(pluginhandle)
def APP_LEVEL2():
url = BUILD_BASE_API('catalog/GetCategoryList')+'&version=1'
data = common.getATVURL(url)
json = demjson.decode(data)
del data
categories = json['message']['body']['categories'][int(common.args.url.split(',')[0])]['categories'][int(common.args.url.split(',')[1])]['categories']
del json
for item in categories:
if item.has_key('categories'):
common.addDir(item['title'],'appfeed','APP_LEVEL3',common.args.url+','+str(categories.index(item)))
else:
cm = [('Export to Library', 'XBMC.RunPlugin(plugin://plugin.video.amazon?mode="appfeed"&sitemode="BROWSE_EXPORT"&url="%s")' % ( urllib.quote_plus(item['query']) ) ) ]
common.addDir(item['title'],'appfeed','BROWSE',item['query'],cm=cm)
xbmcplugin.endOfDirectory(pluginhandle)
def APP_LEVEL3():
url = BUILD_BASE_API('catalog/GetCategoryList')+'&version=1'
data = common.getATVURL(url)
json = demjson.decode(data)
del data
categories = json['message']['body']['categories'][int(common.args.url.split(',')[0])]['categories'][int(common.args.url.split(',')[1])]['categories'][int(common.args.url.split(',')[2])]['categories']
del json
for item in categories:
if item.has_key('categories'):
common.addDir(item['title'],'appfeed','APP_LEVEL4',common.args.url+','+str(categories.index(item)))
else:
cm = [('Export to Library', 'XBMC.RunPlugin(plugin://plugin.video.amazon?mode="appfeed"&sitemode="BROWSE_EXPORT"&url="%s")' % ( urllib.quote_plus(item['query']) ) ) ]
common.addDir(item['title'],'appfeed','BROWSE',item['query'],cm=cm)
xbmcplugin.endOfDirectory(pluginhandle)
def APP_LEVEL4():
common.addDir('ADD LEVEL4','appfeed','APP_LEVEL4','')
def ADD_MOVIE(addASIN,isPrime=True,inWatchlist=False,export=False):
movies = moviesDB.lookupMoviedb(addASIN,isPrime=True)
for moviedata in movies:
if export:
xbmclibrary.EXPORT_MOVIE(moviedata[0])
else:
righturl='http://www.amazon.com/gp/product/' + addASIN
listmovie.ADD_MOVIE_ITEM(moviedata,righturl,inWatchlist=inWatchlist)
#listmovie.ADD_MOVIE_ITEM(moviedata,inWatchlist=inWatchlist)
def ADD_SERIES(addASIN,isPrime=True,export=False):
shows = tvDB.lookupShowsdb(addASIN,isPrime)
for showdata in shows:
if export:
xbmclibrary.EXPORT_SHOW(showdata[0])
else:
listtv.ADD_SHOW_ITEM(showdata,'appfeed','BROWSE_SEASONS4SERIES')
def ADD_SEASON_SERIES(addASIN,mode='appfeed',submode='BROWSE_SEASONS4SERIES',isPrime=True,checklist='',export=False):
seasons = tvDB.lookupSeasondb(addASIN,isPrime)
for seasondata in seasons:
if seasondata[1] not in checklist:
shows = tvDB.lookupShowsdb(seasondata[1],isPrime)
for showdata in shows:
if export:
xbmclibrary.EXPORT_SHOW(showdata[0])
else:
listtv.ADD_SHOW_ITEM(showdata,mode,submode)
return showdata[0],showdata[1]
return False,False
def ADD_SEASON(addASIN,mode='appfeed',submode='BROWSE_EPISODES',isPrime=True,seriesTitle=True,inWatchlist=False,export=False,addSeries=False,seriesfilter=False):
seasons = tvDB.lookupSeasondb(addASIN,isPrime,addSeries=addSeries)
for seasondata in seasons:
if export:
xbmclibrary.EXPORT_SEASON(seasondata[0])
else:
if not seriesfilter:
listtv.ADD_SEASON_ITEM(seasondata,mode=mode,submode=submode,seriesTitle=seriesTitle,inWatchlist=inWatchlist)
elif seriesfilter == seasondata[5]:
listtv.ADD_SEASON_ITEM(seasondata,mode=mode,submode=submode,seriesTitle=seriesTitle,inWatchlist=inWatchlist)
def ADD_EPISODE(addASIN,isPrime=True,seriesTitle=False,export=False):
episodes = tvDB.lookupEpisodedb(addASIN,isPrime)
for episodedata in episodes:
if export:
xbmclibrary.EXPORT_EPISODE(episodedata[0])
else:
listtv.ADD_EPISODE_ITEM(episodedata,seriesTitle=seriesTitle)
def BROWSE_NEXT(results=MAX):
index = int(common.args.page)*results
BROWSE(results=results,index=index)
def BROWSE_EXPORT():
BROWSE(export=True)
def BROWSE(results=MAX,index=0,export=False):
BROWSE_PARAMS = '&OfferGroups=B0043YVHMY&HighDef=T&NumberOfResults='+str(results)+'&StartIndex='+str(index)+'&playbackInformationRequired=true&SuppressBlackedoutEST=T&version=2&'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS+common.args.url
BROWSE_ADDITEMS(url,results,index,series4season=True,export=export)
# No way to filter only prime shows. OfferGroup B0043YVHMY doesn't work
def BROWSE_SERIES(results=MAX,index=0):
BROWSE_PARAMS = '&OfferGroups=&NumberOfResults='+str(results)+'&StartIndex='+str(index)+'&playbackInformationRequired=true&SuppressBlackedoutEST=T&version=2'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS+'&ContentType=TVSeries&Detailed=T&tag=1&Detailed=T&AID=0&IncludeNonWeb=T&IncludeAll=T'
BROWSE_ADDITEMS(url,results,index)
def BROWSE_SEASONS(results=MAX,index=0):
BROWSE_PARAMS = '&OfferGroups=&NumberOfResults='+str(results)+'&StartIndex='+str(index)+'&HighDef=T&playbackInformationRequired=true&SuppressBlackedoutEST=T&version=2'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS+'&ContentType=TVSeaon&HideNum=T&Detailed=T&AID=1&IncludeNonWeb=T&OfferGroups=B0043YVHMY&IncludeAll=T'
BROWSE_ADDITEMS(url,results,index,series4season=True)
def BROWSE_SEASONS4SERIES(results=MAX,index=0):
BROWSE_PARAMS = '&SeriesASIN='+common.args.url+'&ContentType=TVSeason&OfferGroups=B0043YVHMY&version=2&HideNum=F&Detailed=T&AID=1&IncludeNonWeb=T&IncludeAll=T'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS
BROWSE_ADDITEMS(url,results,index)
def BROWSE_EPISODES(results=MAX,index=0):
BROWSE_PARAMS = '&SeasonASIN='+common.args.url+'&IncludeAll=T&NumberOfResults=400&playbackInformationRequired=true&version=2'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS
BROWSE_ADDITEMS(url,results,index)
def BROWSE_EPISODES_HD(results=MAX,index=0):
BROWSE_PARAMS = '&SeasonASIN='+common.args.url+'&IncludeAll=T&NumberOfResults=400&playbackInformationRequired=true&version=2'
url = BUILD_BASE_API('catalog/Browse')+BROWSE_PARAMS
BROWSE_ADDITEMS(url,results,index,HD=True)
def SEARCH_PRIME(searchString=False,results=MAX,index=0):
if not searchString:
keyboard = xbmc.Keyboard('')
keyboard.doModal()
q = keyboard.getText()
if (keyboard.isConfirmed()):
searchString=urllib.quote_plus(keyboard.getText())
if searchString <> '':
common.addDir('[Search Suggestions]','appfeed','SEARCH_SUGGEST_PRIME',searchString) # '+str(results)+'
BROWSE_PARAMS = '&searchString='+searchString+'&OfferGroups=B0043YVHMY&IncludeAll=T&SuppressBlackedoutEST=T&version=2&NumberOfResults='+str(results)+'&StartIndex='+str(index)
url = BUILD_BASE_API('catalog/Search')+BROWSE_PARAMS
BROWSE_ADDITEMS(url,results,index,search=True)
def SEARCH_SUGGEST_PRIME():
BROWSE_PARAMS = '&query='+common.args.url+'&version=1'
url = BUILD_BASE_API('catalog/GetSearchSuggestions')+BROWSE_PARAMS
data = common.getATVURL(url)
suggestions = demjson.decode(data)['message']['body']['searchSuggestion']
if len(suggestions) > 0:
selected=xbmcgui.Dialog().select('Suggestions', [suggestion for suggestion in suggestions])
SEARCH_PRIME(searchString=urllib.quote_plus(suggestions[selected]))
def BROWSE_ADDITEMS(url,results,index,search=False,series4season=False,HD=False,export=False):
data = common.getATVURL(url)
json = demjson.decode(data)
del data
titles = json['message']['body']['titles']
del json
if len(titles) == results:
if index == 0:
page = 1
else:
page = index/results
if not search or not export:
common.addDir('Next Page (%s-%s)'% (page*results+1,(page+1)*results),'appfeed','BROWSE_NEXT',common.args.url,page=page)
Movies = False
Series = False
Season = False
Episode = False
if series4season:
allSeries = ''
for title in titles:
if title['contentType'] == 'MOVIE':
ADD_MOVIE(title['titleId'],export=export)
Movies = True
elif title['contentType'] == 'SERIES':
ADD_SERIES(title['titleId'],export=export)
Series = True
elif title['contentType'] == 'SEASON':
if series4season:
seriesId = title['ancestorTitles'][0]['titleId']
if seriesId not in allSeries:
ADD_SERIES(seriesId,export=export)
allSeries += seriesId+','
Series = True
else:
asin = title['titleId']
ADD_SEASON(asin,seriesTitle=search,export=export)
for format in title['formats']:
if format['videoFormatType'] == 'HD':
for offer in format['offers']:
if offer['offerType'] == 'SEASON_PURCHASE':
asin = offer['asin']
#ADD_SEASON(asin,seriesTitle=True)
ADD_SEASON(asin,seriesTitle=search,submode='BROWSE_EPISODES_HD',export=export)
Season = True
elif title['contentType'] == 'EPISODE':
asin = title['titleId']
if HD:
for format in title['formats']:
if format['videoFormatType'] == 'HD':
for offer in format['offers']:
if offer['offerType'] == 'PURCHASE':
asin = offer['asin']
ADD_EPISODE(asin,seriesTitle=search,export=export)
Episode = True
if not export:
if Series:
view='showview'
xbmcplugin.setContent(pluginhandle, 'tvshows')
elif Season:
view = 'seasonview'
xbmcplugin.setContent(pluginhandle, 'tvshows')
elif Movies:
view='movieview'
xbmcplugin.setContent(pluginhandle, 'Movies')
elif Episode:
view='episodeview'
xbmcplugin.setContent(pluginhandle, 'Episodes')
else:
view='showview'
xbmcplugin.setContent(pluginhandle, 'tvshows')
xbmcplugin.endOfDirectory(pluginhandle)
viewenable=common.addon.getSetting("viewenable")
if viewenable == 'true':
view=int(common.addon.getSetting(view))
xbmc.executebuiltin("Container.SetViewMode("+str(confluence_views[view])+")")