Skip to content

Commit 40f0ad0

Browse files
authored
Merge pull request #194 from Cigaras/referer
Version 2.1.9
2 parents 5e81a35 + e93a295 commit 40f0ad0

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Contents/Code/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
1414

15-
# Version 2.1.8
15+
# Version 2.1.9
1616

1717
from m3u_parser import LoadPlaylist, PlaylistReloader
1818
from xmltv_parser import LoadGuide, GuideReloader
@@ -222,6 +222,7 @@ def ListItems(group = unicode('All'), query = '', page = 1):
222222
c_container = item['container'] if item['container'] else Prefs['container'] if Prefs['container'] else None,
223223
c_protocol = item['protocol'] if item['protocol'] else Prefs['protocol'] if Prefs['protocol'] else None,
224224
c_user_agent = item.get('user_agent') if item.get('user_agent') else Prefs['user_agent'] if Prefs['user_agent'] else None,
225+
c_referer = item.get('referer') if item.get('referer') else Prefs['referer'] if Prefs['referer'] else None,
225226
optimized_for_streaming = item['optimized_for_streaming'] in ['y', 'yes', 't', 'true', 'on', '1'] if item['optimized_for_streaming'] else Prefs['optimized_for_streaming'],
226227
include_container = False
227228
)
@@ -249,16 +250,16 @@ def ListItems(group = unicode('All'), query = '', page = 1):
249250
def CreateVideoClipObject(url, title, thumb, art, summary,
250251
c_audio_codec = None, c_video_codec = None,
251252
c_container = None, c_protocol = None,
252-
c_user_agent = None, optimized_for_streaming = True,
253-
include_container = False, *args, **kwargs):
253+
c_user_agent = None, c_referer = None,
254+
optimized_for_streaming = True, include_container = False, *args, **kwargs):
254255

255256
vco = VideoClipObject(
256257
key = Callback(CreateVideoClipObject,
257258
url = url, title = title, thumb = thumb, art = art, summary = summary,
258259
c_audio_codec = c_audio_codec, c_video_codec = c_video_codec,
259260
c_container = c_container, c_protocol = c_protocol,
260-
c_user_agent = c_user_agent, optimized_for_streaming = optimized_for_streaming,
261-
include_container = True),
261+
c_user_agent = c_user_agent, c_referer = c_referer,
262+
optimized_for_streaming = optimized_for_streaming, include_container = True),
262263
rating_key = url,
263264
title = title,
264265
thumb = thumb,
@@ -268,7 +269,7 @@ def CreateVideoClipObject(url, title, thumb, art, summary,
268269
MediaObject(
269270
parts = [
270271
PartObject(
271-
key = HTTPLiveStreamURL(Callback(PlayVideo, url = url, c_user_agent = c_user_agent))
272+
key = HTTPLiveStreamURL(Callback(PlayVideo, url = url, c_user_agent = c_user_agent, c_referer = c_referer))
272273
)
273274
],
274275
audio_codec = c_audio_codec if c_audio_codec else None,
@@ -288,12 +289,17 @@ def CreateVideoClipObject(url, title, thumb, art, summary,
288289
####################################################################################################
289290
@indirect
290291
@route(PREFIX + '/playvideo.m3u8')
291-
def PlayVideo(url, c_user_agent = None):
292+
def PlayVideo(url, c_user_agent = None, c_referer = None):
292293

293294
# Custom User-Agent string
294295
if c_user_agent:
295296
HTTP.Headers['User-Agent'] = c_user_agent
296297

298+
# Custom HTTP referer
299+
if c_referer:
300+
HTTP.Headers['Referer'] = c_referer
301+
HTTP.Headers['Referrer'] = c_referer
302+
297303
return IndirectResponse(VideoClipObject, key = url)
298304

299305
####################################################################################################

Contents/Code/m3u_parser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
7474
container = GetAttribute(line_1, 'container').lower()
7575
protocol = GetAttribute(line_1, 'protocol').lower()
7676
user_agent = GetAttribute(line_1, 'user_agent').lower()
77+
referer = GetAttribute(line_1, 'referer').lower()
7778
optimized_for_streaming = GetAttribute(line_1, 'optimized_for_streaming').lower()
7879
group_title = GetAttribute(line_1, 'group-title')
7980
url = None
@@ -82,8 +83,12 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
8283
if line_2:
8384
if line_2.startswith('#EXTGRP:') and not group_title:
8485
group_title = GetAttribute(line_2, '#EXTGRP', ':', '')
85-
elif line_2.startswith('#EXTVLCOPT:') and not user_agent:
86+
elif line_2.startswith('#EXTVLCOPT:http-user-agent') and not user_agent:
8687
user_agent = GetAttribute(line_2, 'http-user-agent', '=', '')
88+
elif line_2.startswith('#EXTVLCOPT:http-referer') and not referer:
89+
referer = GetAttribute(line_2, 'http-referer', '=', '')
90+
elif line_2.startswith('#EXTVLCOPT:http-referrer') and not referer:
91+
referer = GetAttribute(line_2, 'http-referrer', '=', '')
8792
elif not line_2.startswith('#'):
8893
url = line_2
8994
i = j + 1
@@ -102,6 +107,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
102107
'container': container,
103108
'protocol': protocol,
104109
'user_agent': user_agent,
110+
'referer': referer,
105111
'optimized_for_streaming': optimized_for_streaming,
106112
'order': stream_count
107113
}

Contents/DefaultPrefs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
"type": "text",
136136
"default": ""
137137
},
138+
{
139+
"id": "referer",
140+
"label": "Custom HTTP referer string (might require playlist reaload for changes to take effect)",
141+
"type": "text",
142+
"default": ""
143+
},
138144
{
139145
"id": "optimized_for_streaming",
140146
"label": "Optimized for streaming - switching this off might force PMS to transcode everything even when Direct Play and Direct Stream options are unavailable",

0 commit comments

Comments
 (0)