From 05ccb39ca1e3ab49954afc1bda5a334c12de9275 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Mon, 13 May 2019 13:26:57 +0200 Subject: [PATCH] Assorted fixes (#219) 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 --- Makefile | 3 +++ resources/lib/kodiwrappers/kodiwrapper.py | 8 +++++--- resources/lib/vrtplayer/streamservice.py | 20 ++++++++++---------- resources/lib/vrtplayer/tokenresolver.py | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 8491f7b8..9edf3f36 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/resources/lib/kodiwrappers/kodiwrapper.py b/resources/lib/kodiwrappers/kodiwrapper.py index 00ee9416..999b905d 100644 --- a/resources/lib/kodiwrappers/kodiwrapper.py +++ b/resources/lib/kodiwrappers/kodiwrapper.py @@ -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, @@ -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) @@ -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 ''' diff --git a/resources/lib/vrtplayer/streamservice.py b/resources/lib/vrtplayer/streamservice.py index ce3faa5b..cab81e7c 100644 --- a/resources/lib/vrtplayer/streamservice.py +++ b/resources/lib/vrtplayer/streamservice.py @@ -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: @@ -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): @@ -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) @@ -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: @@ -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])) @@ -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 diff --git a/resources/lib/vrtplayer/tokenresolver.py b/resources/lib/vrtplayer/tokenresolver.py index 33e60ee8..02c34bc7 100644 --- a/resources/lib/vrtplayer/tokenresolver.py +++ b/resources/lib/vrtplayer/tokenresolver.py @@ -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