Skip to content

Commit

Permalink
added domain alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
elgatito committed Nov 24, 2017
1 parent 2fee81d commit 59ae400
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 10 deletions.
6 changes: 5 additions & 1 deletion burst/burst.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from providers.definitions import definitions, longest
from filtering import apply_filters, Filtering
from client import USER_AGENT, Client, get_cloudhole_key, get_cloudhole_clearance
from utils import ADDON_ICON, notify, translation, sizeof, get_icon_path, get_enabled_providers
from utils import ADDON_ICON, notify, translation, sizeof, get_icon_path, get_enabled_providers, get_alias

provider_names = []
provider_results = []
Expand Down Expand Up @@ -130,6 +130,7 @@ def got_results(provider, results):
global provider_results
global available_providers
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))

max_results = get_setting('max_results', int)
sorted_results = sorted(results, key=lambda r: (r['seeds']), reverse=True)
Expand Down Expand Up @@ -157,6 +158,7 @@ def extract_torrents(provider, client):
tuple: A torrent result
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
log.debug("Extracting torrents from %s using definitions: %s" % (provider, repr(definition)))

if not client.content:
Expand Down Expand Up @@ -299,6 +301,7 @@ def extract_from_api(provider, client):
log.debug("[%s] JSON response from API: %s" % (provider, repr(data)))

definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
api_format = definition['api_format']

results = []
Expand Down Expand Up @@ -384,6 +387,7 @@ def extract_from_page(provider, content):
str: Torrent or magnet link extracted from sub-page
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))

matches = re.findall(r'magnet:\?[^\'"\s<>\[\]]+', content)
if matches:
Expand Down
7 changes: 6 additions & 1 deletion burst/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from elementum.provider import log, get_setting
from providers.definitions import definitions
from providers.helpers import t411season, t411episode
from utils import Magnet, get_int, get_float, clean_number, size_int
from utils import Magnet, get_int, get_float, clean_number, size_int, get_alias

try:
from collections import OrderedDict
Expand Down Expand Up @@ -146,6 +146,7 @@ def use_general(self, provider, payload):
payload (dict): Elementum search payload
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
general_query = definition['general_query'] if definition['general_query'] else ''
log.debug("General URL: %s%s" % (definition['base_url'], general_query))
self.info = payload
Expand All @@ -162,6 +163,7 @@ def use_movie(self, provider, payload):
payload (dict): Elementum search payload
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
movie_query = definition['movie_query'] if definition['movie_query'] else ''
log.debug("Movies URL: %s%s" % (definition['base_url'], movie_query))
if get_setting('separate_sizes', bool):
Expand All @@ -182,6 +184,7 @@ def use_episode(self, provider, payload):
payload (dict): Elementum search payload
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
show_query = definition['show_query'] if definition['show_query'] else ''
log.debug("Episode URL: %s%s" % (definition['base_url'], show_query))
if get_setting('separate_sizes', bool):
Expand All @@ -206,6 +209,7 @@ def use_season(self, provider, info):
payload (dict): Elementum search payload
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
season_query = definition['season_query'] if definition['season_query'] else ''
log.debug("Season URL: %s%s" % (definition['base_url'], season_query))
if get_setting('separate_sizes', bool):
Expand All @@ -229,6 +233,7 @@ def use_anime(self, provider, info):
payload (dict): Elementum search payload
"""
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))
anime_query = definition['anime_query'] if definition['anime_query'] else ''
log.debug("Anime URL: %s%s" % (definition['base_url'], anime_query))
if get_setting('separate_sizes', bool):
Expand Down
5 changes: 3 additions & 2 deletions burst/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from client import Client
from elementum.provider import log, get_setting, set_setting
from providers.definitions import definitions, longest
from utils import ADDON_PATH, get_int, clean_size

from utils import ADDON_PATH, get_int, clean_size, get_alias

def generate_payload(provider, generator, filtering, verify_name=True, verify_size=True):
""" Payload formatter to format results the way Elementum expects them
Expand All @@ -32,6 +31,7 @@ def generate_payload(provider, generator, filtering, verify_name=True, verify_si
results = []

definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))

for name, info_hash, uri, size, seeds, peers in generator:
size = clean_size(size)
Expand Down Expand Up @@ -69,6 +69,7 @@ def process(provider, generator, filtering, verify_name=True, verify_size=True):
"""
log.debug("execute_process for %s with %s" % (provider, repr(generator)))
definition = definitions[provider]
definition = get_alias(definition, get_setting("%s_alias" % provider))

client = Client()
token = None
Expand Down
37 changes: 37 additions & 0 deletions burst/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xbmcaddon
from elementum.provider import get_setting
from providers.definitions import definitions
from urlparse import urlparse

ADDON = xbmcaddon.Addon()
ADDON_ID = ADDON.getAddonInfo("id")
Expand Down Expand Up @@ -52,6 +53,42 @@ def __init__(self, magnet):
self.trackers = re.findall('tr=(.*?)&', self.magnet)


def get_domain(url):
if "//" not in url:
url = "http://" + url

parsed_uri = urlparse(url)
domain = '{uri.netloc}'.format(uri=parsed_uri)
return domain


def get_alias(definition, alias):
definition["alias"] = ""

if alias:
old_domain = ""
for k in ["root_url", "base_url"]:
domain = get_domain(definition[k])
if domain:
old_domain = domain
break

new_domain = get_domain(alias)
if old_domain and new_domain:
definition["alias"] = new_domain
definition["old_domain"] = old_domain

# Substitue all ocurrences of old domain name and replace with new one
for k in definition:
if isinstance(definition[k], basestring):
definition[k] = definition[k].replace(old_domain, new_domain)
for k in definition["parser"]:
if isinstance(definition["parser"][k], basestring):
definition["parser"][k] = definition["parser"][k].replace(old_domain, new_domain)

return definition


def get_providers():
""" Utility method to get all provider IDs available in the definitions
Expand Down
4 changes: 4 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ msgstr ""
msgctxt "#32076"
msgid "Passkey"
msgstr ""

msgctxt "#32077"
msgid "Domain Alias [Optional]"
msgstr ""
10 changes: 7 additions & 3 deletions resources/language/Russian/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ msgctxt "#32075"
msgid "No torrents found"
msgstr "Не найден ни один торрент"

#~ msgctxt "#32040"
#~ msgid "Maximum torrents"
#~ msgstr "Максимально торрентов"
msgctxt "#32076"
msgid "Passkey"
msgstr ""

msgctxt "#32077"
msgid "Domain Alias [Optional]"
msgstr "Альтернативный домен [Опционально]"
10 changes: 7 additions & 3 deletions resources/language/Ukrainian/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ msgctxt "#32075"
msgid "No torrents found"
msgstr "Не знайдено жодного торренту"

#~ msgctxt "#32040"
#~ msgid "Maximum torrents"
#~ msgstr "Максимально торрентів"
msgctxt "#32076"
msgid "Passkey"
msgstr ""

msgctxt "#32077"
msgid "Domain Alias [Optional]"
msgstr "Альтернативний домен [Опціонально]"
4 changes: 4 additions & 0 deletions resources/language/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ msgstr ""
msgctxt "#32076"
msgid "Passkey"
msgstr ""

msgctxt "#32077"
msgid "Domain Alias [Optional]"
msgstr ""
Loading

0 comments on commit 59ae400

Please sign in to comment.