Skip to content

Commit

Permalink
Assorted fixes (#219)
Browse files Browse the repository at this point in the history
This PR includes:
- Unquote URLs in log messages
- Add 'clean' target in Makefile
- Change log-levels for common output
  - Info: Print URL played
  - Verbose: Print all HTTP requests
  - Debug: Various other stuff
  • Loading branch information
dagwieers authored May 13, 2019
1 parent 04d3c3b commit 05ccb39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ zip: test
@rm -f ../$(zip_name)
cd ..; zip -r $(zip_name) $(include_paths) -x $(exclude_files)
@echo -e "$(white)=$(blue) Successfully wrote package as: $(white)../$(zip_name)$(reset)"

clean:
find . -name '*.pyc' -delete
8 changes: 5 additions & 3 deletions resources/lib/kodiwrappers/kodiwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import xbmcplugin

try:
from urllib.parse import urlencode
from urllib.parse import urlencode, unquote
except ImportError:
from urllib import urlencode
from urllib2 import unquote

sort_methods = dict(
# date=xbmcplugin.SORT_METHOD_DATE,
Expand Down Expand Up @@ -128,9 +129,10 @@ def play(self, video):
subtitles_visible = self.get_setting('showsubtitles') == 'true'
# Separate subtitle url for hls-streams
if subtitles_visible and video.subtitle_url is not None:
self.log_notice('Subtitle URL: ' + video.subtitle_url)
self.log_notice('Subtitle URL: ' + unquote(video.subtitle_url), 'Verbose')
play_item.setSubtitles([video.subtitle_url])

self.log_notice('Play: %s' % unquote(video.stream_url), 'Info')
xbmcplugin.setResolvedUrl(self._handle, bool(video.stream_url), listitem=play_item)
while not xbmc.Player().isPlaying() and not xbmc.Monitor().abortRequested():
xbmc.sleep(100)
Expand Down Expand Up @@ -270,7 +272,7 @@ def log_access(self, url, query_string, log_level='Verbose'):
''' Log addon access '''
if log_levels.get(log_level, 0) <= self._max_log_level:
message = url + ('?' if query_string else '') + query_string
xbmc.log(msg='[%s] Access: %s' % (self._addon_id, message), level=xbmc.LOGNOTICE)
xbmc.log(msg='[%s] Access: %s' % (self._addon_id, unquote(message)), level=xbmc.LOGNOTICE)

def log_notice(self, message, log_level='Info'):
''' Log info messages to Kodi '''
Expand Down
20 changes: 10 additions & 10 deletions resources/lib/vrtplayer/streamservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from resources.lib.helperobjects import apidata, streamurls

try:
from urllib.parse import urlencode, quote
from urllib.parse import quote, unquote, urlencode
from urllib.error import HTTPError
from urllib.request import build_opener, install_opener, urlopen, ProxyHandler
except ImportError:
from urllib import urlencode # pylint: disable=ungrouped-imports
from urllib2 import build_opener, install_opener, urlopen, ProxyHandler, quote, HTTPError
from urllib2 import build_opener, install_opener, urlopen, ProxyHandler, quote, unquote, HTTPError


class StreamService:
Expand All @@ -33,7 +33,7 @@ def __init__(self, _kodiwrapper, _tokenresolver):
self._license_url = None

def _get_license_url(self):
self._kodiwrapper.log_notice('URL get: ' + self._VUPLAY_API_URL, 'Verbose')
self._kodiwrapper.log_notice('URL get: ' + unquote(self._VUPLAY_API_URL), 'Verbose')
self._license_url = json.loads(urlopen(self._VUPLAY_API_URL).read()).get('drm_providers', dict()).get('widevine', dict()).get('la_url')

def _create_settings_dir(self):
Expand Down Expand Up @@ -100,7 +100,7 @@ def _get_api_data(self, video):
def _webscrape_api_data(self, video_url):
'''Scrape api data from VRT NU html page'''
from bs4 import BeautifulSoup, SoupStrainer
self._kodiwrapper.log_notice('URL get: ' + video_url, 'Verbose')
self._kodiwrapper.log_notice('URL get: ' + unquote(video_url), 'Verbose')
html_page = urlopen(video_url).read()
strainer = SoupStrainer('div', {'class': 'cq-dd-vrtvideo'})
soup = BeautifulSoup(html_page, 'html.parser', parse_only=strainer)
Expand Down Expand Up @@ -149,7 +149,7 @@ def _get_video_json(self, api_data):
if playertoken:
api_url = api_data.media_api_url + '/videos/' + api_data.publication_id + \
api_data.video_id + '?vrtPlayerToken=' + playertoken + '&client=' + api_data.client
self._kodiwrapper.log_notice('URL get: ' + api_url, 'Verbose')
self._kodiwrapper.log_notice('URL get: ' + unquote(api_url), 'Verbose')
try:
video_json = json.loads(urlopen(api_url).read())
except HTTPError as e:
Expand Down Expand Up @@ -239,22 +239,22 @@ def _select_stream(self, stream_dict, vudrm_token):
protocol = None
if vudrm_token and self._can_play_drm and self._kodiwrapper.get_setting('usedrm') == 'true':
protocol = 'mpeg_dash drm'
self._kodiwrapper.log_notice('Protocol: ' + protocol)
self._kodiwrapper.log_notice('Protocol: ' + protocol, 'Verbose')
stream_url = self._try_get_drm_stream(stream_dict, vudrm_token)

if vudrm_token and stream_url is None:
protocol = 'hls_aes'
self._kodiwrapper.log_notice('Protocol: ' + protocol)
self._kodiwrapper.log_notice('Protocol: ' + protocol, 'Verbose')
stream_url = streamurls.StreamURLS(*self._select_hls_substreams(stream_dict[protocol])) if protocol in stream_dict else None

if self._kodiwrapper.has_inputstream_adaptive_installed() and stream_url is None:
protocol = 'mpeg_dash'
self._kodiwrapper.log_notice('Protocol: ' + protocol)
self._kodiwrapper.log_notice('Protocol: ' + protocol, 'Verbose')
stream_url = streamurls.StreamURLS(stream_dict[protocol], use_inputstream_adaptive=True) if protocol in stream_dict else None

if stream_url is None:
protocol = 'hls'
self._kodiwrapper.log_notice('Protocol: ' + protocol)
self._kodiwrapper.log_notice('Protocol: ' + protocol, 'Verbose')
# No if-else statement because this is the last resort stream selection
stream_url = streamurls.StreamURLS(*self._select_hls_substreams(stream_dict[protocol]))

Expand All @@ -267,7 +267,7 @@ def _select_hls_substreams(self, master_hls_url):
hls_audio_id = None
hls_subtitle_id = None
hls_base_url = master_hls_url.split('.m3u8')[0]
self._kodiwrapper.log_notice('URL get: ' + master_hls_url + '?hd', 'Verbose')
self._kodiwrapper.log_notice('URL get: ' + unquote(master_hls_url) + '?hd', 'Verbose')
hls_playlist = urlopen(master_hls_url + '?hd').read()
max_bandwidth = self._kodiwrapper.get_max_bandwidth()
stream_bandwidth = None
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/vrtplayer/tokenresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _get_cached_token(self, path, token_name):
self._kodiwrapper.log_notice('Got cached token', 'Verbose')
cached_token = token.get(token_name)
else:
self._kodiwrapper.log_notice('Cached token deleted', 'Info')
self._kodiwrapper.log_notice('Cached token deleted', 'Verbose')
self._kodiwrapper.delete_file(path)
return cached_token

Expand Down

0 comments on commit 05ccb39

Please sign in to comment.