diff --git a/galdPl.py b/galdPl.py index 6c87d96..74f8e4b 100644 --- a/galdPl.py +++ b/galdPl.py @@ -662,6 +662,65 @@ def db(params): def mojedb(params): xbmc.log("Debug: mojedb funkce spuštěna", xbmc.LOGDEBUG) popinfo("Debug: mojedb funkce spuštěna") + + # Funkce pro stahování JSON souborů z GITu + def update_json_db(): + try: + import urllib.request + import re + + def get_json_files_from_folder(folder): + base_url = "https://git.gald.site/gald/galdistream/src/branch/main/resources/" + url = base_url + folder + + req = urllib.request.Request(url) + req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36') + + with urllib.request.urlopen(req, timeout=10) as response: + html_content = response.read().decode('utf-8') + + json_pattern = r'href="(/gald/galdistream/src/branch/main/resources/[^"]*\.json)"' + matches = re.findall(json_pattern, html_content) + + files = [] + for match in matches: + file_name = match.split("/")[-1] + files.append(file_name) + return files + + base_url_raw = "https://git.gald.site/gald/galdistream/raw/branch/main/resources/" + folders = ["movies", "series"] + all_files = [] + + for folder in folders: + try: + files = get_json_files_from_folder(folder) + all_files += [f"{folder}/{file}" for file in files] + except Exception as e: + xbmc.log(f"Chyba při získávání souborů ze složky {folder}: {e}", xbmc.LOGERROR) + + for file in all_files: + url = base_url_raw + file + local_path = os.path.join(_addon.getAddonInfo('path'), 'resources', file) + try: + req = urllib.request.Request(url) + req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36') + + with urllib.request.urlopen(req, timeout=10) as response: + content = response.read() + + os.makedirs(os.path.dirname(local_path), exist_ok=True) + with open(local_path, "wb") as f: + f.write(content) + xbmc.log(f"Staženo: {file}", xbmc.LOGDEBUG) + except Exception as e: + xbmc.log(f"Chyba při stahování {file}: {e}", xbmc.LOGERROR) + except Exception as e: + xbmc.log(f"Chyba při stahování JSON souborů: {e}", xbmc.LOGERROR) + + # Stáhni aktuální JSON soubory z GITu + update_json_db() + xbmcplugin.setPluginCategory(_handle, _addon.getAddonInfo('name') + " \\ " + _addon.getLocalizedString(30220)) token = revalidate() updateListing=False diff --git a/main.py b/main.py index d52c38b..9362938 100644 --- a/main.py +++ b/main.py @@ -6,59 +6,6 @@ import sys import galdPl -import urllib.request -import urllib.parse -import re -import os - -def get_json_files_from_folder(folder): - base_url = "https://git.gald.site/gald/galdistream/src/branch/main/resources/" - url = base_url + folder - - # Použijeme urllib místo requests - req = urllib.request.Request(url) - req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36') - - with urllib.request.urlopen(req, timeout=10) as response: - html_content = response.read().decode('utf-8') - - # Hledáme JSON soubory pomocí regex - json_pattern = r'href="(/gald/galdistream/src/branch/main/resources/[^"]*\.json)"' - matches = re.findall(json_pattern, html_content) - - files = [] - for match in matches: - # Extrahujeme pouze název souboru - file_name = match.split("/")[-1] - files.append(file_name) - return files - -def update_json_db(): - base_url_raw = "https://git.gald.site/gald/galdistream/raw/branch/main/resources/" - folders = ["movies", "series"] - all_files = [] - for folder in folders: - try: - files = get_json_files_from_folder(folder) - all_files += [f"{folder}/{file}" for file in files] - except Exception as e: - print(f"Chyba při získávání souborů ze složky {folder}: {e}") - for file in all_files: - url = base_url_raw + file - local_path = "resources/" + file - try: - req = urllib.request.Request(url) - req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36') - - with urllib.request.urlopen(req, timeout=10) as response: - content = response.read() - - os.makedirs(os.path.dirname(local_path), exist_ok=True) - with open(local_path, "wb") as f: - f.write(content) - except Exception as e: - print(f"Chyba při stahování {file}: {e}") if __name__ == '__main__': - update_json_db() galdPl.router(sys.argv[2][1:])