From d4b982781b62670f12a078564a2459bb4746c5dc Mon Sep 17 00:00:00 2001 From: Valdas Vaitiekaitis Date: Wed, 23 May 2018 08:31:16 +0300 Subject: [PATCH 1/2] HTTP referer Trying to add referer for issue #187 --- Contents/Code/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 665cca4..9782753 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -12,7 +12,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# Version 2.1.8 +# Version 2.1.9 from m3u_parser import LoadPlaylist, PlaylistReloader from xmltv_parser import LoadGuide, GuideReloader @@ -294,6 +294,9 @@ def PlayVideo(url, c_user_agent = None): if c_user_agent: HTTP.Headers['User-Agent'] = c_user_agent + HTTP.Headers['Referer'] = 'http://player.livesports.pw/la2/' + HTTP.Headers['Referrer'] = 'http://player.livesports.pw/la2/' + return IndirectResponse(VideoClipObject, key = url) #################################################################################################### From e93a295a7d410284b9d9f272a77dac639ac5c9e7 Mon Sep 17 00:00:00 2001 From: Valdas Vaitiekaitis Date: Wed, 23 May 2018 10:04:27 +0300 Subject: [PATCH 2/2] HTTP referer Trying to add HTTP referer for issue #187 --- Contents/Code/__init__.py | 19 +++++++++++-------- Contents/Code/m3u_parser.py | 8 +++++++- Contents/DefaultPrefs.json | 6 ++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 9782753..e47c7bb 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -222,6 +222,7 @@ def ListItems(group = unicode('All'), query = '', page = 1): c_container = item['container'] if item['container'] else Prefs['container'] if Prefs['container'] else None, c_protocol = item['protocol'] if item['protocol'] else Prefs['protocol'] if Prefs['protocol'] else None, c_user_agent = item.get('user_agent') if item.get('user_agent') else Prefs['user_agent'] if Prefs['user_agent'] else None, + c_referer = item.get('referer') if item.get('referer') else Prefs['referer'] if Prefs['referer'] else None, optimized_for_streaming = item['optimized_for_streaming'] in ['y', 'yes', 't', 'true', 'on', '1'] if item['optimized_for_streaming'] else Prefs['optimized_for_streaming'], include_container = False ) @@ -249,16 +250,16 @@ def ListItems(group = unicode('All'), query = '', page = 1): def CreateVideoClipObject(url, title, thumb, art, summary, c_audio_codec = None, c_video_codec = None, c_container = None, c_protocol = None, - c_user_agent = None, optimized_for_streaming = True, - include_container = False, *args, **kwargs): + c_user_agent = None, c_referer = None, + optimized_for_streaming = True, include_container = False, *args, **kwargs): vco = VideoClipObject( key = Callback(CreateVideoClipObject, url = url, title = title, thumb = thumb, art = art, summary = summary, c_audio_codec = c_audio_codec, c_video_codec = c_video_codec, c_container = c_container, c_protocol = c_protocol, - c_user_agent = c_user_agent, optimized_for_streaming = optimized_for_streaming, - include_container = True), + c_user_agent = c_user_agent, c_referer = c_referer, + optimized_for_streaming = optimized_for_streaming, include_container = True), rating_key = url, title = title, thumb = thumb, @@ -268,7 +269,7 @@ def CreateVideoClipObject(url, title, thumb, art, summary, MediaObject( parts = [ PartObject( - key = HTTPLiveStreamURL(Callback(PlayVideo, url = url, c_user_agent = c_user_agent)) + key = HTTPLiveStreamURL(Callback(PlayVideo, url = url, c_user_agent = c_user_agent, c_referer = c_referer)) ) ], audio_codec = c_audio_codec if c_audio_codec else None, @@ -288,14 +289,16 @@ def CreateVideoClipObject(url, title, thumb, art, summary, #################################################################################################### @indirect @route(PREFIX + '/playvideo.m3u8') -def PlayVideo(url, c_user_agent = None): +def PlayVideo(url, c_user_agent = None, c_referer = None): # Custom User-Agent string if c_user_agent: HTTP.Headers['User-Agent'] = c_user_agent - HTTP.Headers['Referer'] = 'http://player.livesports.pw/la2/' - HTTP.Headers['Referrer'] = 'http://player.livesports.pw/la2/' + # Custom HTTP referer + if c_referer: + HTTP.Headers['Referer'] = c_referer + HTTP.Headers['Referrer'] = c_referer return IndirectResponse(VideoClipObject, key = url) diff --git a/Contents/Code/m3u_parser.py b/Contents/Code/m3u_parser.py index aef6ff6..5a9f31e 100644 --- a/Contents/Code/m3u_parser.py +++ b/Contents/Code/m3u_parser.py @@ -74,6 +74,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None): container = GetAttribute(line_1, 'container').lower() protocol = GetAttribute(line_1, 'protocol').lower() user_agent = GetAttribute(line_1, 'user_agent').lower() + referer = GetAttribute(line_1, 'referer').lower() optimized_for_streaming = GetAttribute(line_1, 'optimized_for_streaming').lower() group_title = GetAttribute(line_1, 'group-title') url = None @@ -82,8 +83,12 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None): if line_2: if line_2.startswith('#EXTGRP:') and not group_title: group_title = GetAttribute(line_2, '#EXTGRP', ':', '') - elif line_2.startswith('#EXTVLCOPT:') and not user_agent: + elif line_2.startswith('#EXTVLCOPT:http-user-agent') and not user_agent: user_agent = GetAttribute(line_2, 'http-user-agent', '=', '') + elif line_2.startswith('#EXTVLCOPT:http-referer') and not referer: + referer = GetAttribute(line_2, 'http-referer', '=', '') + elif line_2.startswith('#EXTVLCOPT:http-referrer') and not referer: + referer = GetAttribute(line_2, 'http-referrer', '=', '') elif not line_2.startswith('#'): url = line_2 i = j + 1 @@ -102,6 +107,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None): 'container': container, 'protocol': protocol, 'user_agent': user_agent, + 'referer': referer, 'optimized_for_streaming': optimized_for_streaming, 'order': stream_count } diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index 40796b3..45d8c90 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -135,6 +135,12 @@ "type": "text", "default": "" }, + { + "id": "referer", + "label": "Custom HTTP referer string (might require playlist reaload for changes to take effect)", + "type": "text", + "default": "" + }, { "id": "optimized_for_streaming", "label": "Optimized for streaming - switching this off might force PMS to transcode everything even when Direct Play and Direct Stream options are unavailable",