Skip to content

Commit

Permalink
2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz89B committed Aug 7, 2021
1 parent f3e1488 commit d2b20ab
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<description lang="nb_NO">Se innhold fra Viaplay.</description>
<description lang="sv_SE">Titta på innehåll från Viaplay.</description>
<description lang="pl_PL">Oglądaj treści z Viaplay.</description>
<news>2021.08.05 v.2.1.3[CR]+ Added viaplay.pl[CR]2021.08.07 v2.1.4[CR]+ Added watched and purchased categories for viaplay.pl
<news>2021.08.05 v.2.1.3[CR]+ Added viaplay.pl[CR]2021.08.07 v2.1.4[CR]+ Added watched and purchased categories for viaplay.pl[CR]+ Fixed category error
</news>
<platform>all</platform>
<language>sv dk no fi en pl</language>
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2021.08.07 v.2.1.4
+ Added watched and purchased categories for viaplay.pl @Mariusz89B
+ Fixed category error

2021.08.05 v.2.1.3
+ Added viaplay.pl @Mariusz89B @Zuzia-Dev
Expand Down
3 changes: 3 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def vod():
helper.add_item(helper.language(30041), plugin.url_for(categories, url=plugin.args['url'][0]))
collections = helper.vp.get_collections(plugin.args['url'][0])
for i in collections:
if i['type'] == 'list-featurebox': # skip feature box for now
continue

if i['title'] == '':
if 'a6-00' in i['id']:
i['title'] = '3+'
Expand Down
55 changes: 55 additions & 0 deletions resources/lib/viaplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@
import iso8601
import requests
import xbmc
import xbmcvfs
from xbmcaddon import Addon


class Viaplay(object):
def __init__(self, settings_folder, country, debug=False):
addon = self.get_addon()
self.debug = debug
self.country = country
self.settings_folder = settings_folder
if sys.version_info[0] > 2:
self.addon_path = xbmcvfs.translatePath(addon.getAddonInfo('path'))
self.addon_profile = xbmcvfs.translatePath(addon.getAddonInfo('profile'))
else:
self.addon_path = xbmc.translatePath(addon.getAddonInfo('path'))
self.addon_profile = xbmc.translatePath(addon.getAddonInfo('profile'))
self.cookie_jar = cookielib.LWPCookieJar(os.path.join(self.settings_folder, 'cookie_file'))
#self.replace_cookies = self.replace_cookies() ### workaround to switch country sites
self.tempdir = os.path.join(settings_folder, 'tmp')
if not os.path.exists(self.tempdir):
os.makedirs(self.tempdir)
Expand All @@ -44,6 +54,51 @@ def __init__(self, settings_folder, country, debug=False):
pass
self.http_session.cookies = self.cookie_jar

def get_addon(self):
"""Returns a fresh addon instance."""
return Addon()

def get_setting(self, setting_id):
addon = self.get_addon()
setting = addon.getSetting(setting_id)
if setting == 'true':
return True
elif setting == 'false':
return False
else:
return setting

def get_country_code(self):
country_id = self.get_setting('site')
if country_id == '0':
country_code = 'se'
elif country_id == '1':
country_code = 'dk'
elif country_id == '2':
country_code = 'no'
elif country_id == '3':
country_code = 'fi'
elif country_id == '4':
country_code = 'pl'

return country_code

def replace_cookies(self):
cookie_file = os.path.join(self.addon_profile, 'cookie_file')
f = open(cookie_file, 'r')
cookies = f.read()

country_code = self.get_country_code()

pattern = re.compile('viaplay.(\w{2})', re.IGNORECASE)
n_country_code = pattern.search(cookies).group(1)

if n_country_code != country_code:
cookies = re.sub('viaplay.{cc}'.format(cc=n_country_code), 'viaplay.{cc}'.format(cc=country_code), cookies)
w = open(cookie_file, 'w')
w.write(cookies)
w.close()

class ViaplayError(Exception):
def __init__(self, value):
self.value = value
Expand Down

0 comments on commit d2b20ab

Please sign in to comment.