Skip to content

Commit

Permalink
Added CDN location option to the settings (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
quarckster authored Nov 19, 2021
1 parent 97ae231 commit 2550e40
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
exclude: tests/expected_results.py|tests/data
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0
rev: v2.6.0
hooks:
- id: reorder-python-imports
language_version: python36
language_version: python3
args:
- --application-directories=.:src:tests
- repo: https://github.com/psf/black
rev: 21.6b0
rev: 21.11b1
hooks:
- id: black
language_version: python36
language_version: python3
args: [--safe, --quiet, --line-length, "100"]
require_serial: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
language_version: python36
language_version: python3
- id: end-of-file-fixer
language_version: python36
language_version: python3
- id: debug-statements
language_version: python36
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: "3.9.2"
hooks:
- id: flake8
language_version: python36
language_version: python3
args:
- --max-line-length=100
- --ignore=W503,E203
- repo: https://github.com/asottile/pyupgrade
rev: v2.20.0
rev: v2.29.1
hooks:
- id: pyupgrade
language_version: python36
language_version: python3
22 changes: 19 additions & 3 deletions src/resources/lib/modeling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import re
import sys
import urllib
from collections import namedtuple

import xbmcgui
Expand Down Expand Up @@ -218,6 +219,19 @@ def __repr__(self):
class PlayableItem(ItemEntity):
isdir = False

def _choose_cdn_loc(self, url):
parsed = urllib.parse.urlparse(url)
return urllib.parse.urlunparse(
(
parsed.scheme,
parsed.netloc,
parsed.path,
parsed.params,
f"loc={self.plugin.settings.loc}",
parsed.fragment,
)
)

@property
def media_url(self):
quality = self.plugin.settings.video_quality
Expand Down Expand Up @@ -246,13 +260,15 @@ def alphanum_key(key):
if result == -1:
sys.exit()
else:
return flatten_urls_dict[urls_list[result]]
return self._choose_cdn_loc(flatten_urls_dict[urls_list[result]])
else:
try:
return files[quality][stream_type]
return self._choose_cdn_loc(files[quality][stream_type])
except KeyError:
# if there is no such quality then return a link with the highest available quality
return files[natural_sort(list(files.keys()))[-1]][stream_type]
return self._choose_cdn_loc(
files[natural_sort(list(files.keys()))[-1]][stream_type]
)

@property
def list_item(self):
Expand Down
7 changes: 7 additions & 0 deletions src/resources/lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ class Settings(object):
("video", "ignorepercentatend"): 8,
}

_locs = {
"Россия": "ru",
"Нидерланды": "nl",
}

def __getattr__(self, name):
if name == "advanced":
return self._get_adv_setting
if name.startswith("show_"):
return eval(xbmcaddon.Addon().getSetting(name).title())
if name == "loc":
self._locs[xbmcaddon.Addon().getSetting(name)]
return xbmcaddon.Addon().getSetting(name)

def __setattr__(self, name, value):
Expand Down
5 changes: 3 additions & 2 deletions src/resources/settings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="Общие">
<setting id="video_quality" type="select" label="Качество видео" values="2160p|1080p|720p|480p" enable="eq(2,false)" default="1080p"/>
<setting id="stream_type" type="select" label="Тип стриминга" values="http|hls|hls2|hls4" enable="eq(1,false)" default="hls"/>
<setting id="video_quality" type="select" label="Качество видео" values="2160p|1080p|720p|480p" enable="eq(3,false)" default="720p"/>
<setting id="stream_type" type="select" label="Тип стриминга" values="http|hls|hls2|hls4" enable="eq(2,false)" default="http"/>
<setting id="loc" type="select" label="Локация CDN" values="Россия|Нидерланды" default="Россия"/>
<setting id="ask_quality" type="bool" label="Задавать вопрос о качестве видео перед воспроизведением" default="false"/>
<setting id="mark_advert" type="bool" label="Отмечать видео с рекламой (!)" default="false"/>
<setting id="exclude_anime" type="bool" label="Исключать аниме" default="false"/>
Expand Down

0 comments on commit 2550e40

Please sign in to comment.