# coding=utf-8 import hashlib import re import os import sys import pprint import xbmc import platform from consts import * if sys.version_info[0] >= 3: unicode = str long = int def string_str(s): return s def md5_string(i): m = hashlib.md5() m.update(i.encode("utf-8")) return m.hexdigest() def md5_file(fname): hash_md5 = hashlib.md5() with open(fname, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk.encode("utf-8")) return hash_md5.hexdigest() def string_to_json(i): try: return json.loads(i) except: return None def is_hex(val): try: int(val, 16) return True except ValueError: return False def get_poster_url(link): """ @param link: @return: """ url = "" if not link or link == "": return "DefaultVideo.png" if link.find("http") > -1: url = link else: url = IMAGEPATH + IMAGESIZE_COVER + link return url def get_scene_url(link): """ @param link: @return: """ url = "" if not link or link == "": return "DefaultVideo.png" if link.find("http") > -1: url = link else: url = IMAGEPATH + IMAGESIZE_SCENE + link return url def get_backdrop_url(link): """ @param link: @return: """ url = "" if link: url = IMAGEPATH + IMAGESIZE_POSTER + link return url def xor_string(data, key): s = "" dl = len(data) kl = len(key) for i in range(0, dl): c = ord(data[i]) ^ ord(key[(i + dl) % kl]) s += chr(c) return s def format_seconds_to_hhmmss(seconds): seconds = int(seconds) hours = seconds // (60 * 60) seconds %= (60 * 60) minutes = seconds // 60 seconds %= 60 return "%02i:%02i:%02i" % (hours, minutes, seconds) def misc_menu(menu=None, data=None, episode_id=None): """ @param data: @param episode_id: @return: """ if not menu: menu = [] if True and episode_id and data: menu.append( ( "Als %sgesehen markieren" % ("un" if data["in_watchedlist"] else ""), 'RunPlugin("%s")' % PLUGIN.url_for(endpoint="mark_as_seen", episodeid=episode_id, seen=int(not data["in_watchedlist"])) ) ) menu.append( ( "Zum Listenanfang", "Action(firstpage)" ) ) menu.append( ( u"Zum Hauptmenü", 'Container.Update("%s",replace)' % PLUGIN.url_for(endpoint="main") ) ) menu.append( ( u"Ebene zurück", 'Action(Back)' ) ) return menu def has_played(movie_id=0): """ @param movie_id: @return: """ return False def get_user_agent(): user_agent = "" try: user_agent = xbmc.getUserAgent() except: # getUserAgent not supported build_version = xbmc.getInfoLabel("System.BuildVersion") matches = re.search(r"([^\s]+)", build_version, re.IGNORECASE) user_agent = "Kodi/" if matches: user_agent += matches.group(1) else: user_agent += "00.00" try: user_agent += " (%s; %s)" % (platform.system(), platform.machine()) except: user_agent += " (%s)" % (sys.platform) user_agent += " Version/" + build_version.replace(" ", "-") # Kodi 16: Kodi/16.1 (Linux; Android 8.0; BRAVIA 4K GB Build/OPR2.170623.027.S30) Android/8.0.0 Sys_CPU/armv7l App_Bitness/32 Version/16.1-Git:2016-04-24-c327c53 # Kodi 17: Kodi/17.6 (Linux; Android 7.1.2; AFTMM Build/NS6271) Android/7.1.2 Sys_CPU/armv7l App_Bitness/32 Version/17.6-Git:20171114-a9a7a20 # Kodi 18: Kodi/18.6 (Windows NT 10.0.17763; Win64; x64) App_Bitness/64 Version/18.6-Git:20200229-8e967df921 return user_agent def convert_to_bytes(text, encoding="utf-8"): if sys.version_info.major < 3: return text else: try: return text.encode(encoding, "ignore") except Exception: return text def convert_to_str(text, encoding="utf-8"): if sys.version_info.major < 3: return text else: try: return text.decode(encoding, "ignore") except Exception: return text def set_thumbnail(item): if "art" not in item or not isinstance(item["art"], dict): item["art"] = {} thumbnail = item.get("thumbnail") fanart = item.get("properties", {}).get("thumbnail") if fanart is not None: item["art"]["fanart"] = fanart if thumbnail is not None: item["art"]["thumb"] = thumbnail item["art"]["landscape"] = item["art"]["thumb"] item["art"]["icon"] = item["art"]["thumb"] item["art"]["clearlogo"] = item["art"]["thumb"] item["art"]["banner"] = item["art"]["thumb"] """ item["art"]["poster"] = item["art"]["thumb"] """ return item def prepare_entry(entry, isfirst=False, prefixed=True): if not entry["id"]: return None trailer_id = None if entry["trailer"]: # trailer_id = re.match(r'^[^v]+v[/=](.{3,11}).*', entry["trailer"]) trailer_id = re.search(r"(?:v=|//[^/]+\.be/)(.{3,11})", entry["trailer"]) if trailer_id: trailer_id = trailer_id.group(1) fanart_url = get_backdrop_url(entry["backdropurl"]) title = unicode(entry['title']) if prefixed: if entry["type"] == 1: title = "HD: %s" % title elif entry["type"] == 2: title = "Serie: %s" % title elif entry["type"] == 3: title = "3D: %s" % title elif entry["type"] == 4: title = "UHD: %s" % title elif entry["type"] == 5: title = "UHD Serie: %s" % title if entry["isline"]: title = "[COLOR %s]%s[/COLOR]" % (COLOR_LINE, title) elif entry["type"] == 4 or entry["type"] == 5: title = "[COLOR %s]%s[/COLOR]" % (COLOR_UHD, title) if not "description" in entry and "overview" in entry: entry["description"] = entry["overview"] """ if MASTERLOCK[0] and MINIMALMPAA > 0 and (entry["age"] > MINIMALMPAA or not entry["age"]): title = "* %s" % title """ menu = [ ( "Informationen", "Action(Info)" ) ] play_trailer = None if trailer_id: play_trailer = PLUGIN.url_for(endpoint="play_trailer", trailer_id=str(trailer_id), age=entry["age"] if "age" in entry and entry["age"] else "0") menu.append( ( "Trailer abspielen", 'RunPlugin("%s")' % play_trailer ) ) if True: # and entry["tmdb_id"]: menu.append( ( "Schauspieler anzeigen", 'Container.Update("%s",True)' % PLUGIN.url_for(endpoint="view_actors", movie_id=entry['id']) ) ) menu.append( ( "%sTrailer suchen" % ("weitere " if trailer_id else ""), 'Container.Update("%s",True)' % PLUGIN.url_for(endpoint="search_trailer", title=entry['title'] if isinstance(entry["title"], int) else entry['title'].encode("utf-8"), date="%s" % entry['release_date'], fanart=fanart_url if fanart_url else "None", age=entry["age"] if "age" in entry and entry["age"] else "0") ) ) in_watchlist_view = (PLUGIN.request.url.find("watchlist") > -1) if True: menu.append( ( u"Von der Merkliste entfernen" if in_watchlist_view else u"Zur Merkliste hinzufügen", 'RunPlugin("%s")' % (PLUGIN.url_for(endpoint="watchlist_action", movie_id=entry['id'], action="remove" if in_watchlist_view else "add", refresh=in_watchlist_view * 1)) ) ) if True: # and entry["tmdb_id"]: menu.append( ( u"Ähnliche Einträge", 'Container.Update("%s",True)' % PLUGIN.url_for(endpoint="search_similars", movie_id="%s" % entry['id'], page=0, type=entry["type"]) ) ) if False and entry["collection"]: menu.append( ( "Filmreihe anzeigen", 'Container.Update("%s",True)' % PLUGIN.url_for(endpoint="search_similars", movie_id="%s" % entry['id'], page=0, type=entry["type"]) ) ) watched = (entry["in_watchedlist"] * 1) if "in_watchedlist" in entry else (has_played(entry['episode_id']) if not entry["has_episodes"] else 0) item = { "label": title, "info_type": "video", "mime_type": "application/octet-stream", "thumbnail": get_poster_url(entry['posterurl']), "is_playable": False, # "selected": isfirst, "path": PLUGIN.url_for(endpoint="seasons", movie_id=entry['id']), "properties": { "fanart_image": fanart_url }, "info": { # "cast": [("lol", "hehe", "http://www.google.com", "http://www.google.com"), u"lol2"], "count": entry["id"], # "playcount": hasPlayed(entry['episode_id']) if entry["has_episodes"] == False else 0, # "watched": hasPlayed(entry['episode_id']) if entry["has_episodes"] == False else 0, "playcount": watched, "watched": watched, "plot": unicode(entry['description']) if entry['description'] else None, "rating": "%s" % entry["rating"], "year": entry["year"], "mpaa": entry["age"] if "age" in entry and entry["age"] else None, "director": None, "genre": entry["genres"], "date": entry["release_date"] if entry["release_date"] else None, "title": unicode(entry['title']), "originaltitle": unicode(entry["original_title"]) if entry["original_title"] else None, "tagline": (u"%s - %s" % (entry["year"], entry["genres"])) if USE_TAGLINE else None, "trailer": play_trailer, "duration": ("%s" % (int(entry["runtime"]) * 60)) if entry["runtime"] else None, "imdbnumber": entry["imdb_id"] if entry["imdb_id"] else None, "dateadded": entry["updated_at"] }, "stream_info": { "video": { "duration": ("%s" % (int(entry["runtime"]) * 60)) if entry["runtime"] else None, } }, "context_menu": misc_menu(menu, data=entry, episode_id=entry['episode_id'] if not entry["has_episodes"] else None), "replace_context_menu": False, "art": {} } set_thumbnail(item) return item def prepare_movies_to_list(data, prefixed=True): items = [] for i, movie in enumerate(data): item = prepare_entry(movie, isfirst=(i == 0), prefixed=prefixed) if not item: continue items.append(item) return items def show_busy_dialog(): if KODI_VERSION < 18: xbmc.executebuiltin('ActivateWindow(busydialog)') else: xbmc.executebuiltin('ActivateWindow(busydialognocancel)') def hide_busy_dialog(): if KODI_VERSION < 18: xbmc.executebuiltin("Dialog.Close(busydialog)") else: xbmc.executebuiltin('Dialog.Close(busydialognocancel)') def logout_kodi(): """ @return: """ global PORTAL_USERNAME, PORTAL_USERID try: os.remove(COOKIE_PATH) except: pass db = PLUGIN.get_storage("movies") db["id"] = None db.sync() PLUGIN.set_setting("username", "") PLUGIN.set_setting("password", "") PORTAL_USERID = 0 PORTAL_USERNAME = ""