123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- # 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 = ""
|