Skip to content

Commit

Permalink
code update:
Browse files Browse the repository at this point in the history
* removed unnecessary import statements
* all Globals/Settings instances are private
* added Monitor to track changes at settings
* service moved to libs folder
* Settings class revised

Signed-off-by: Sandmann79 <sandmann79@gmx.net>
  • Loading branch information
Sandmann79 committed Aug 22, 2023
1 parent 0b11f44 commit 8aa8d3c
Show file tree
Hide file tree
Showing 19 changed files with 598 additions and 532 deletions.
5 changes: 4 additions & 1 deletion plugin.video.amazon-test/default.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from resources.lib.startup import EntryPoint
from resources.lib.service import SettingsMonitor

EntryPoint()
if __name__ == '__main__':
EntryPoint()
SettingsMonitor().start()
7 changes: 4 additions & 3 deletions plugin.video.amazon-test/resources/lib/ages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from kodi_six import xbmcgui
import pyxbmct
from .configs import *
from .l10n import *
from kodi_six import xbmcgui

from .common import Globals
from .configs import getConfig, writeConfig
from .l10n import getString


class AgeRestrictions:
Expand Down
61 changes: 35 additions & 26 deletions plugin.video.amazon-test/resources/lib/android_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os.path
import re
import time
import json
from copy import deepcopy

from datetime import date
from kodi_six import xbmcgui, xbmc, xbmcplugin

try:
from urllib.parse import quote_plus
except ImportError:
from urllib import quote_plus

from .ages import AgeRestrictions
from .singleton import Singleton
from .network import *
from .itemlisting import *
from .users import *
from .common import findKey
from .logging import LogJSON, Log
from .ages import AgeRestrictions
from .network import getURL, MechanizeLogin, getATVData, LocaleSelector, refreshToken
from .itemlisting import addDir, addVideo, setContentAndView
from .users import loadUser, updateUser
from .configs import writeConfig
from .l10n import getString

try:
from urllib.parse import quote_plus, urlencode, parse_qs
except ImportError:
from urllib import quote_plus, urlencode
from urlparse import parse_qs


class PrimeVideo(Singleton):
Expand Down Expand Up @@ -43,7 +51,7 @@ def __init__(self, globalsInstance, settingsInstance):
'&osLocale={}&uxLocale={}' \
'&supportsPKMZ=false' \
'&isLiveEventsV2OverrideEnabled=true' \
'&swiftPriorityLevel=critical'.format(self.def_dtid, g.deviceID, self.lang, self.lang)
'&swiftPriorityLevel=critical'.format(self.def_dtid, self._g.deviceID, self.lang, self.lang)

def BrowseRoot(self):
cm_wl = [(getString(30185) % 'Watchlist', 'RunPlugin(%s?mode=getListMenu&url=%s&export=1)' % (self._g.pluginid, self._g.watchlist))]
Expand Down Expand Up @@ -84,14 +92,14 @@ def addCtxMenu(self, il, wl):
cm.append((getString(30182), 'Container.Update(%s?%s)' % (self._g.pluginid, u)))
return cm

def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, root=False):
def getPage(self, page='home', params='&pageType=home&pageId=home', pagenr=1, root=False):
url_path = ['', '/cdp/mobile/getDataByTransform/v1/', '/cdp/switchblade/android/getDataByJvmTransform/v1/']
url_dict = {'home': {'p': 2, 'js': 'dv-android/landing/initial/v1.kt', 'q': ''},
'landing': {'p': 2, 'js': 'dv-android/landing/initial/v1.kt', 'q': '&removeFilters=false'},
'browse': {'p': 1, 'js': 'dv-android/browse/v2/browseInitial.js', 'q': ''},
'detail': {'p': 1, 'js': 'dv-android/detail/v2/user/v2.5.js', 'q': '&capabilities='},
'details': {'p': 1, 'js': 'android/atf/v3.jstl', 'q': '&capabilities='},
'watchlist': {'p': 1, 'js': 'dv-android/watchlist/watchlistInitial/v3.js', 'q': ''},
'watchlist': {'p': 1, 'js': 'dv-android/watchlist/watchlistInitial/v3.js', 'q': '&appendTapsData=true&titleActionScheme=bond-2&version=mobile-android-v2'},
'library': {'p': 1, 'js': 'dv-android/library/libraryInitial/v2.js', 'q': ''},
'find': {'p': 1, 'js': 'dv-android/find/v1.js', 'q': '&pageId=findv2&pageType=home'},
'search': {'p': 1, 'js': 'dv-android/search/searchInitial/v3.js', 'q': ''},
Expand All @@ -103,12 +111,13 @@ def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, roo
resp = self.loadCache(params)
else:
pg = url_dict.get(page, url_dict['home'])
url = self._g.ATVUrl + url_path[pg['p']] +pg['js']
url = self._g.ATVUrl + url_path[pg['p']] + pg['js']
params += pg['q']
params = '&' + params if not params.startswith('&') else params
query_dict = parse_qs(params)
url = url.replace('Initial', 'Next') if 'Initial' in url and int(query_dict.get('startIndex', ['0'])[0]) > 0 else url
url = url.replace('initial', 'next') if 'initial' in url and 'startIndex' in query_dict else url
resp = getURL('%s?%s&%s' % (url, self.defparam, params), useCookie=MechanizeLogin(True), headers=self._g.headers_android)
resp = getURL('%s?%s%s' % (url, self.defparam, params), useCookie=MechanizeLogin(True), headers=self._g.headers_android)
LogJSON(resp)

if resp:
Expand All @@ -127,7 +136,7 @@ def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, roo
if page in ['watchlist', 'library'] and 'Initial' in url and 'serviceToken' not in query_dict:
for k, v in self.filter.items():
addDir(k, 'getPage', page, opt=urlencode(v))
xbmcplugin.endOfDirectory(g.pluginhandle)
xbmcplugin.endOfDirectory(self._g.pluginhandle)
return

if page == 'details':
Expand Down Expand Up @@ -183,7 +192,7 @@ def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, roo
if facetxt is not None:
isprime = prdata.get('offerClassification', '') == 'PRIME'
isincl = item.get('containerMetadata', {}).get('entitlementCues', {}).get('entitledCarousel', 'Entitled') == 'Entitled'
if self._s.payCont:
if self._s.paycont:
if isprime:
facetxt = '[COLOR {}]{}[/COLOR]'.format(self._g.PrimeCol, facetxt)
if isincl is False:
Expand Down Expand Up @@ -219,7 +228,7 @@ def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, roo
if ct in ['movie', 'episode', 'live', 'videos']:
addVideo(self.formatTitle(il), il['asins'], il, cm=cm)
else:
pgnr = -1 if self._s.dispShowOnly and ct in 'season' else 1
pgnr = -1 if self._s.disptvshow and ct in 'season' else 1
addDir(self.formatTitle(il), 'getPage', 'details', infoLabels=il, opt='itemId=' + il['asins'], cm=cm, page=pgnr)

if pgmodel and page != 'cache':
Expand All @@ -232,7 +241,7 @@ def getPage(self, page='home', params='pageType=home&pageId=home', pagenr=1, roo
else:
nextp['pageSize'] = len(col)
pagenr = int(nextp['startIndex'] / len(col) + 1)
addDir(' --= %s =--' % (getString(30111) % pagenr), 'getPage', pgtype, opt=urlencode(nextp), page=pagenr, thumb=self._s.NextIcon)
addDir(' --= %s =--' % (getString(30111) % pagenr), 'getPage', pgtype, opt=urlencode(nextp), page=pagenr, thumb=self._g.NextIcon)

setContentAndView(ct)
xbmc.executebuiltin('RunPlugin(%s?mode=processMissing)' % self._g.pluginid)
Expand All @@ -243,7 +252,7 @@ def formatTitle(self, il):
if il['contentType'] in 'episode':
if il['episode'] > 0:
name = '{}. {}'.format(il['episode'], name)
if not il['isPrime'] and self._s.payCont:
if not il['isPrime'] and self._s.paycont:
name = '[COLOR %s]%s[/COLOR]' % (self._g.PayCol, name)
return name

Expand Down Expand Up @@ -277,7 +286,7 @@ def editWatchList(self, asin, remove):
cPath = xbmc.getInfoLabel('Container.FolderPath')
xbmc.executebuiltin('Container.Update("{}", replace)'.format(cPath))
else:
g.dialog.notification(g.__plugin__, msg, xbmcgui.NOTIFICATION_ERROR)
self._g.dialog.notification(self._g.__plugin__, msg, xbmcgui.NOTIFICATION_ERROR)

def _createDB(self, table):
c = self._cacheDb.cursor()
Expand Down Expand Up @@ -334,8 +343,8 @@ def getArtandInfo(self, infoLabels, contentType, item):
asins = infoLabels['asins']
infoLabels['banner'] = None
season = int(infoLabels.get('season', -2))
series = contentType == 'season' and self._s.dispShowOnly
series_art = season > -1 and self._s.showfanart and self._s.tmdb_art != 0
series = contentType == 'season' and self._s.disptvshow
series_art = season > -1 and self._s.useshowfanart and self._s.tmdb_art != 0
extra = ' and season = %s' % season if season > -2 else ''
for asin in asins.split(','):
j = None
Expand Down Expand Up @@ -503,7 +512,7 @@ def getInfos(self, item, items='', noart=False):
infoLabels['duration'] = item['runtimeMillis'] / 1000
if item.get('runtimeSeconds'):
infoLabels['duration'] = item['runtimeSeconds']
if 'season' in ct and 'tvshowtitle' in infoLabels and self._s.dispShowOnly and noart is False:
if 'season' in ct and 'tvshowtitle' in infoLabels and self._s.disptvshow and noart is False:
infoLabels['title'] = infoLabels['tvshowtitle']
infoLabels['plot'] = '{}\n\n{}'.format(getString(30253).format(infoLabels['totalseasons']), infoLabels['plot'])
if 'episode' in ct:
Expand Down Expand Up @@ -612,7 +621,7 @@ def languageselect(self):
'&deviceID={}'
'&locale={}&osLocale={}&uxLocale={}'
'&version=1'
'&preferenceType=IMPLICIT'.format(self._g.ATVUrl, self.def_dtid, g.deviceID, loc, loc, loc), headers=self._g.headers_android, postdata='')
'&preferenceType=IMPLICIT'.format(self._g.ATVUrl, self.def_dtid, self._g.deviceID, loc, loc, loc), headers=self._g.headers_android, postdata='')
if resp.get('success', False):
updateUser('lang', loc)
Log('Text language changed to [{}] {}'.format(loc, lang), Log.DEBUG)
Expand All @@ -622,7 +631,7 @@ def Route(self, mode, args):
searchString = args.get('searchstring')
self.Search(searchString)
elif mode in ['processMissing', 'switchProfile', 'languageselect']:
exec ('g.pv.{}()'.format(mode))
exec ('self._g.pv.{}()'.format(mode))
elif mode == 'ageSettings':
AgeRestrictions().Settings()
elif mode == 'getPage':
Expand Down
3 changes: 1 addition & 2 deletions plugin.video.amazon-test/resources/lib/art.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from bs4 import BeautifulSoup

from .common import Globals, Settings
from .logging import Log
from .network import getURL
from .common import Globals, Settings

try:
from urllib.parse import quote_plus
Expand Down

0 comments on commit 8aa8d3c

Please sign in to comment.