Skip to content

Commit

Permalink
Add proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
f-lawe committed Jun 19, 2024
1 parent 2cdf87c commit 02d6af5
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 4 deletions.
38 changes: 38 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,44 @@ msgctxt "#30204"
msgid "Help 30204"
msgstr ""

# Proxy settings (from 30300 to 30399)

msgctxt "#30300"
msgid "Proxy"
msgstr ""

msgctxt "#30301"
msgid "Enable"
msgstr ""

msgctxt "#30302"
msgid "Help 30302"
msgstr ""

msgctxt "#30303"
msgid "Type"
msgstr ""

msgctxt "#30304"
msgid "Help 30304"
msgstr ""

msgctxt "#30305"
msgid "IP"
msgstr ""

msgctxt "#30306"
msgid "Help 30306"
msgstr ""

msgctxt "#30307"
msgid "Port"
msgstr ""

msgctxt "#30308"
msgid "Help 30308"
msgstr ""

# Dialogs (from 30900 to 30999)

msgctxt "#30900"
Expand Down
38 changes: 38 additions & 0 deletions resources/language/resource.language.fr_fr/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,44 @@ msgctxt "#30204"
msgid "Help 30204"
msgstr ""

# Proxy settings (from 30300 to 30399)

msgctxt "#30300"
msgid "Proxy"
msgstr "Proxy"

msgctxt "#30301"
msgid "Activer"
msgstr ""

msgctxt "#30302"
msgid "Help 30302"
msgstr ""

msgctxt "#30303"
msgid "Type"
msgstr "Type"

msgctxt "#30304"
msgid "Help 30304"
msgstr ""

msgctxt "#30305"
msgid "IP"
msgstr "Adresse IP"

msgctxt "#30306"
msgid "Help 30306"
msgstr ""

msgctxt "#30307"
msgid "Port"
msgstr "Numéro de port"

msgctxt "#30308"
msgid "Help 30308"
msgstr ""

# Dialogs (from 30900 to 30999)

msgctxt "#30900"
Expand Down
5 changes: 2 additions & 3 deletions resources/lib/providers/cache_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import os
from urllib.error import URLError

import xbmc
import xbmcvfs
Expand Down Expand Up @@ -38,8 +37,8 @@ def get_streams(self) -> list:
streams = self.provider.get_streams()
with open(os.path.join(self.cache_folder, "streams.json"), "wb") as file:
file.write(json.dumps(streams).encode("utf-8"))
except URLError:
log("Can't reach server: load streams from cache", xbmc.LOGWARNING)
except Exception:
log("Can't load streams: using cache instead", xbmc.LOGWARNING)
with open(os.path.join(self.cache_folder, "streams.json"), encoding="utf-8") as file:
streams = json.loads("".join(file.readlines()))

Expand Down
4 changes: 3 additions & 1 deletion resources/lib/utils/orange.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import xbmc

from lib.utils.request import get_random_ua
from lib.utils.request import get_random_ua, install_proxy
from lib.utils.xbmc import get_drm, get_global_setting, log

_EPG_ENDPOINT = "https://rp-ott-mediation-tv.woopic.com/api-gw/live/v3/applications/STB4PC/programs?period={period}&epgIds=all&mco={mco}"
Expand Down Expand Up @@ -205,6 +205,8 @@ def _build_request(url: str, additional_headers: dict = None) -> Request:
if additional_headers is None:
additional_headers = {}

install_proxy()

return Request(url, headers={"User-Agent": get_random_ua(), "Host": urlparse(url).netloc, **additional_headers})


Expand Down
35 changes: 35 additions & 0 deletions resources/lib/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from random import randint

# from socks import SOCKS5
# from sockshandler import SocksiPyHandler
from lib.utils.xbmc import get_addon_setting

_USER_AGENTS = [
# Chrome
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.3",
Expand All @@ -25,3 +29,34 @@
def get_random_ua() -> str:
"""Get a randomised user agent."""
return _USER_AGENTS[randint(0, len(_USER_AGENTS) - 1)]


def install_proxy():
"""Install proxy server for the next requests."""
if get_addon_setting("proxy.enabled") != "true":
return

ip = get_addon_setting("proxy.ip")
port = get_addon_setting("proxy.port")

if ip == "" or port == "":
return

# protocol = get_addon_setting('proxy.protocol')

# if protocol == 'HTTP':
# proxies = {
# 'https': f"http://{ip}:{port}",
# 'http': f"http://{ip}:{port}"
# }
# log(proxies, xbmc.LOGDEBUG)
# proxy_support = ProxyHandler(proxies)

# elif protocol == 'Socks5 Local DNS':
# proxy_support = SocksiPyHandler(SOCKS5, ip, int(port), False)

# elif protocol == 'Socks5 Remote DNS':
# proxy_support = SocksiPyHandler(SOCKS5, ip, int(port), True)

# opener = build_opener(proxy_support)
# install_opener(opener)
7 changes: 7 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
<setting id="provider.country" label="30201" help="30202" type="select" values="France" default="France"/>
<setting id="provider.name" visible="eq(-1,France)" label="30203" help="30204" type="labelenum" values="Orange|Orange Caraïbe|Orange Réunion" default="Orange"/>
</category>

<category label="30300">
<setting id="proxy.enabled" label="30301" help="30302" type="bool" default="false" />
<setting id="proxy.protocol" label="30303" help="30304" enable="eq(-1,true)" type="labelenum" values="HTTP|Socks5 Local DNS|Socks5 Remote DNS" default="HTTP"/>
<setting id="proxy.ip" label="30305" help="30306" enable="eq(-2,true)" type="text" default=""/>
<setting id="proxy.port" label="30307" help="30308" enable="eq(-3,true)" type="text" default=""/>
</category>
</settings>

0 comments on commit 02d6af5

Please sign in to comment.