Skip to content

Commit

Permalink
Merge pull request #194 from Cigaras/referer
Browse files Browse the repository at this point in the history
Version 2.1.9
  • Loading branch information
Cigaras committed May 23, 2018
2 parents 5e81a35 + e93a295 commit 40f0ad0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
20 changes: 13 additions & 7 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -288,12 +289,17 @@ 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

# Custom HTTP referer
if c_referer:
HTTP.Headers['Referer'] = c_referer
HTTP.Headers['Referrer'] = c_referer

return IndirectResponse(VideoClipObject, key = url)

####################################################################################################
Expand Down
8 changes: 7 additions & 1 deletion Contents/Code/m3u_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 40f0ad0

Please sign in to comment.