Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Some cleanup + add autogenerated colour for providers
Browse files Browse the repository at this point in the history
  • Loading branch information
fugkco committed Mar 31, 2023
1 parent a2db628 commit 247d2e0
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 183 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $(ZIP_FILE): $(BUILD_DIR)
--requirement /dev/stdin \
--target $(BUILD_DIR)/resources/libs \
--progress-bar off
@find $(BUILD_DIR) -iname "*.egg-info" -or -iname "*.pyo" -or -iname "*.pyc" | xargs rm -rf
@find $(BUILD_DIR) -iname "*.egg-info" -or -iname "*.pyo" -or -iname "*.pyc" -or -iname "__pycache__" | xargs rm -rf
@poetry run ./scripts/update-version.py $(GIT_VERSION) > $(BUILD_DIR)/addon.xml
@(cd $(BUILD_BASE) && $(ZIP) -r $(CURDIR)/$(ZIP_FILE) $(NAME))

Expand Down
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<import addon="script.module.urllib3"/>
<import addon="script.module.kodi-six" />
</requires>
<extension point="xbmc.python.script" library="jackett.py">
<extension point="xbmc.python.script" library="src/main.py">
<provides>executable</provides>
</extension>
<extension point="xbmc.addon.metadata">
Expand Down
357 changes: 214 additions & 143 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "script.elementum.jackett"
version = "0.0.1"
description = ""
authors = ["Fugkco <fugkco@github.io>"]
authors = ["fugkco <fugkco@users.noreply.github.com>"]
license = "WTFPL"

[tool.poetry.dependencies]
Expand All @@ -16,6 +16,7 @@ kodistubs = "^19.0.0"
flake8 = "^3.8.2"
pytest = "^4.6.10"
kodi-six = {git = "https://github.com/romanvm/kodi.six.git", rev = "0.1.3"}
elementum = { git = "https://github.com/fugkco/plugin.video.elementum.git" }

[build-system]
requires = ["poetry>=0.12"]
Expand Down
20 changes: 11 additions & 9 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
from requests_toolbelt import sessions
from torrentool.torrent import Torrent

from src import utils
from src.utils import notify, translation, get_icon_path, human_size, get_resolution, get_release_type, get_setting, \
import utils
from utils import notify, translation, get_icon_path, human_size, get_resolution, get_release_type, get_setting, \
set_setting


# import logging
# log = logging

class Jackett(object):
"""docstring for Jackett"""

Expand Down Expand Up @@ -209,10 +206,10 @@ def _do_search_request(self, request_params):
log.error(f"got code {err['code']}: {err['description']}")
return []

# log.debug("Jackett returned below response")
# log.debug("===============================")
# log.debug(search_resp.content)
# log.debug("===============================")
log.debug("Jackett returned below response")
log.debug("===============================")
log.debug(search_resp.content)
log.debug("===============================")

return self._parse_items(search_resp.content)

Expand Down Expand Up @@ -285,18 +282,23 @@ def _parse_item(self, item):
log.debug(f"Failed item is: {ElementTree.tostring(item, encoding='utf8')}")
return None

provider_color = utils.get_provider_color(result["provider"])

# result["name"] = result["name"].decode("utf-8") # might be needed for non-english items
result["seeds"] = int(result["seeds"])
result["peers"] = int(result["peers"])
resolution = get_resolution(result["name"])
result["resolution"] = list(utils.resolutions.keys())[::-1].index(resolution)
result["_resolution"] = resolution
result["release_type"] = get_release_type(result["name"])
result["provider"] = f'[COLOR {provider_color}]{result["provider"]}[/COLOR]'

if result["size"] != "Unknown":
result["_size_bytes"] = int(result["size"])
result["size"] = human_size(result["_size_bytes"])

log.debug("final item: {}".format(result))

return result


Expand Down
2 changes: 1 addition & 1 deletion src/debugger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
def load():
from elementum.provider import log
from src.utils import get_setting
from utils import get_setting

if get_setting("enable_debugger", bool):
import pkgutil
Expand Down
20 changes: 3 additions & 17 deletions src/filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
from elementum.provider import log

from src.utils import get_setting, UNKNOWN
from utils import get_setting, UNKNOWN


#
Expand Down Expand Up @@ -78,15 +78,7 @@ def keywords(results):
return results


def _should_include_size_result(size, min, max, include_unknown):
if size == -1:
return include_unknown

return min <= size <= max


def size(method, results):
log.info("hiii", 50*"-")
include_unknown = get_setting('size_include_' + UNKNOWN, bool)

if method in ["movie", "season", "episode"]:
Expand All @@ -99,28 +91,22 @@ def size(method, results):
# MB KB B
min_size = min_size * (1024 * 1024 * 1024)
max_size = max_size * (1024 * 1024 * 1024)
log.info(results[0]["_size_bytes"])

return [
result
for result in results
if _should_include_size_result(result["_size_bytes"], min_size, max_size, include_unknown)
if (size == -1 and include_unknown) or (size != -1 and min_size <= result["_size_bytes"] <= max_size)
]


def resolution(results):
filtered = []
for result in results:
log.info(f"res {result['name']}: name={result['_resolution']}; id={result['resolution']}")
log.debug(f"res {result['name']}: name={result['_resolution']}; id={result['resolution']}")
if get_setting('include_resolution_' + result["_resolution"], bool):
filtered.append(result)

return filtered
# return [
# result
# for result in results
# if get_setting('include_resolution_' + result["_resolution"], bool)
# ]


def seed(results):
Expand Down
7 changes: 3 additions & 4 deletions src/jackett.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
from kodi_six import xbmc, xbmcgui
from elementum.provider import log

from src import filter
from src import utils
from src.client import Jackett
from src.utils import get_setting
import filter, utils
from client import Jackett
from utils import get_setting

available_providers = 0
special_chars = "()\"':.[]<>/\\?"
Expand Down
12 changes: 6 additions & 6 deletions jackett.py → src/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
import os
from os import path
import sys

from kodi_six import xbmcgui
from elementum.provider import register, log

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'libs'))
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, path.realpath(path.join(path.dirname(__file__), '..', 'resources', 'libs')))
sys.path.insert(0, path.dirname(__file__))

if __name__ == '__main__':
import src.debugger as debugger
import src.utils as utils
import src.jackett as jackett
import debugger
import utils
import jackett

if len(sys.argv) == 1:
log.error("Elementum Jackett plugin must be run through Elementum")
Expand Down
23 changes: 23 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding=utf-8
import hashlib
import os
import xbmcvfs
import re
Expand All @@ -10,6 +11,8 @@

_plugin_setting_prefix = "elementum.jackett."

PROVIDER_COLOR_MIN_BRIGHTNESS = 50

ADDON = xbmcaddon.Addon()
ADDON_ID = ADDON.getAddonInfo("id")
ADDON_NAME = ADDON.getAddonInfo("name")
Expand Down Expand Up @@ -104,3 +107,23 @@ def set_setting(key, value):

def get_setting(key, converter=str, choices=None):
return original_get_settings(_plugin_setting_prefix + key, converter, choices)


def get_provider_color(provider_name):
hash = hashlib.sha256(provider_name.encode("utf")).hexdigest()
colors = []

spec = 10
for i in range(0, 3):
offset = spec * i
rounded = round(int(hash[offset:offset + spec], 16) / int("F" * spec, 16) * 255)
colors.append(int(max(rounded, PROVIDER_COLOR_MIN_BRIGHTNESS)))

while (sum(colors) / 3) < PROVIDER_COLOR_MIN_BRIGHTNESS:
for i in range(0, 3):
colors[i] += 10

for i in range(0, 3):
colors[i] = f'{colors[i]:02x}'

return "FF" + "".join(colors).upper()

0 comments on commit 247d2e0

Please sign in to comment.