Skip to content

Commit

Permalink
Add option to redirect streams using stream proxy anxdpanic#1040
Browse files Browse the repository at this point in the history
- As headers are not matched this can lead to detection of Kodi being used as a client
  • Loading branch information
MoojMidge committed Jan 9, 2025
1 parent 9a15623 commit 1f22cdd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,11 @@ msgid "InputStream.Adaptive"
msgstr ""

msgctxt "#30618"
msgid ""
msgid "Stream redirect"
msgstr ""

msgctxt "#30619"
msgid ""
msgid "Enable to reduce resource usage on less powerful devices, but could lead to IP bans. Use at own risk."
msgstr ""

msgctxt "#30620"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@
HTTPD_LISTEN = 'kodion.http.listen' # (str)
HTTPD_WHITELIST = 'kodion.http.ip.whitelist' # (str)
HTTPD_IDLE_SLEEP = 'youtube.http.idle_sleep' # (bool)
HTTPD_STREAM_REDIRECT = 'youtube.http.stream_redirect' # (bool)

LOGGING_ENABLED = 'kodion.logging.enabled' # (bool)
9 changes: 9 additions & 0 deletions resources/lib/youtube_plugin/kodion/network/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def do_GET(self):

original_query_str = urlencode(params, doseq=True)

stream_redirect = settings.httpd_stream_redirect()

response = None
for server in servers:
if not server:
Expand All @@ -405,6 +407,13 @@ def do_GET(self):
'',
))

if stream_redirect and server in _server_list:
self.send_response(301)
self.send_header('Location', stream_url)
self.send_header('Connection', 'close')
self.end_headers()
break

headers['Host'] = server
with self.requests.request(stream_url,
method='GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ def httpd_sleep_allowed(self, value=None):
return self.set_bool(SETTINGS.HTTPD_IDLE_SLEEP, value)
return self.get_bool(SETTINGS.HTTPD_IDLE_SLEEP, True)

def httpd_stream_redirect(self, value=None):
if value is not None:
return self.set_bool(SETTINGS.HTTPD_STREAM_REDIRECT, value)
return self.get_bool(SETTINGS.HTTPD_STREAM_REDIRECT, False)

def api_config_page(self):
return self.get_bool(SETTINGS.API_CONFIG_PAGE, False)

Expand Down
3 changes: 3 additions & 0 deletions resources/lib/youtube_plugin/youtube/helper/stream_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,9 @@ def load_stream_info(self, video_id):
title='',
url=manifest_url,
meta=meta_info,
headers={
'User-Agent': 'youtube/0.1 ({0})'.format(self.video_id),
},
playback_stats=playback_stats,
)

Expand Down
5 changes: 5 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,11 @@
<default>true</default>
<control type="toggle"/>
</setting>
<setting id="youtube.http.stream_redirect" type="boolean" label="30618" help="30619">
<level>0</level>
<default>False</default>
<control type="toggle"/>
</setting>
</group>
<group id="logging" label="14092">
<setting id="kodion.logging.enabled" type="boolean" label="20191" help="36392">
Expand Down

0 comments on commit 1f22cdd

Please sign in to comment.