From ddc14dd206ea3e47ff82f9df74706b980eb13589 Mon Sep 17 00:00:00 2001 From: kiddac Date: Tue, 12 Nov 2024 23:20:21 +0000 Subject: [PATCH] imdb prefix stripping --- CONTROL/control | 2 +- .../XKlass/locale/de/LC_MESSAGES/XKlass.mo | Bin 12610 -> 13688 bytes .../XKlass/locale/de/LC_MESSAGES/XKlass.po | 37 ++--- .../Plugins/Extensions/XKlass/series.py | 146 +++++++++--------- .../Extensions/XKlass/twisteddownloader.py | 125 +++++++++++++++ .../Plugins/Extensions/XKlass/version.txt | 2 +- .../python/Plugins/Extensions/XKlass/vod.py | 87 ++++++----- 7 files changed, 267 insertions(+), 132 deletions(-) create mode 100644 XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/twisteddownloader.py diff --git a/CONTROL/control b/CONTROL/control index de134b1..0f7c7ec 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,5 +1,5 @@ Package: enigma2-plugin-extensions-xklass -Version: 1.18-20241030 +Version: 1.19-20241112 Section: misc Priority: optional Architecture: all diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.mo b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.mo index f38e97a1cf5fdbf5c6f4311b2c8b00d5818f9e4f..6ab8fd5515dfe5854b20b355ea963d81c62502e0 100644 GIT binary patch delta 5185 zcmZvf3vg7`8OKi^K!||^6r))1@(2(lO9Fy4zDNZPQ4kv-pn$!}-Xzy-?#A7_#2|L@ z2^H#tsD-Matq-uRid(deC{+}7)M=@Mb*L?4A2M}HO9!Uaf@6RG-IES8?V0@dch0%@ zeCKuN;Le zF<;to;V@%PXFLotWh$WFn+eCj%isX$!LyA?n+`hXGI1v?hfhMi_zFA&9)cs`amWHw zI^39ZU?nVsbDX8_)x1&2WeI2n$D4RADUhXdK)tfQj{?}3VN z2gG@^7goRz;b3?Y7QumpQw>X@BAN~5&~m8fw?a8|H{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3)sq!WAShj2Z4pNu3W63?fNn7uif^k`Kvra*+K0(8kXtvq(8fCtJwdqzmzo(!l%! zZ^Ls`yiDF8#YAsRXYwSON_2c2!2h{~&j_;0*6EFTf~+OA?NaproV!uKvX7BvWD7v?V%quAL&ItB5T++QBEPH)kBLw~qRFcy zlWZfAq!p<>k}34HC)=&dt>e*4o`=ftHNMFaC*8iO(Hq>}guV?7YkzPeN{Pz9+X$c8)J3@x03yo-{VdcRux=+j}E@ lh_5)~j>}urHr2POZI;`2IqSaL_e;+2F7F&qzW1=_=)VUwi01$R diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.po b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.po index d4e0cfa..c4156cb 100644 --- a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.po +++ b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/locale/de/LC_MESSAGES/XKlass.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "POT-Creation-Date: 2024-09-14 22:41+0100\n" -"PO-Revision-Date: 2024-09-14 22:42+0100\n" +"PO-Revision-Date: 2024-11-12 17:33+0000\n" "Last-Translator: Masta2002\n" "Language-Team: \n" "Language: de\n" @@ -233,7 +233,7 @@ msgstr "Konto-Informationen" #: channelmenu.py:114 channelmenu.py:148 channelmenu.py:257 playlists.py:63 #: startmenu.py:582 msgid "Manage Playlists" -msgstr "" +msgstr "Wiedergabelisten verwalten" #: channelmenu.py:115 channelmenu.py:150 channelmenu.py:259 msgid "Add New Playlist" @@ -518,11 +518,11 @@ msgstr "Name bereits verwendet. Bitte gib einen eindeutigen Namen ein." #: plugin.py:179 plugin.py:180 msgid "Original" -msgstr "" +msgstr "Original" #: plugin.py:180 msgid "Added" -msgstr "" +msgstr "Hinzugefügt" #: plugin.py:180 series.py:2052 series.py:2075 vod.py:510 vod.py:536 #: vod.py:1684 vod.py:1704 @@ -531,7 +531,7 @@ msgstr "Sortierung: Jahr" #: plugin.py:180 msgid "Year" -msgstr "" +msgstr "Jahr" #: plugin.py:277 plugin.py:385 msgid "XKlass" @@ -733,11 +733,11 @@ msgstr "Standardtyp VOD/Serien-Stream" #: settings.py:155 msgid "Default VOD category sort order" -msgstr "" +msgstr "Standard-Sortierreihenfolge der VOD-Kategorien" #: settings.py:156 msgid "Default VOD stream sort order" -msgstr "" +msgstr "Standard-Sortierreihenfolge für VOD-Streams" #: settings.py:158 msgid "XKlass parental control" @@ -785,7 +785,7 @@ msgstr "Intro-Video in Schleife" #: settings.py:169 msgid "Intro video selection" -msgstr "" +msgstr "Auswahl des Intro-Videos" #: settings.py:170 msgid "Show channel picons" @@ -809,11 +809,11 @@ msgstr "XKlass beim Booten automatisch starten" #: settings.py:175 msgid "Play satellite channel audio in background" -msgstr "" +msgstr "Satellitenkanal-Audio im Hintergrund abspielen" #: settings.py:176 msgid "Add speedtest plugin to main menu" -msgstr "" +msgstr "Speedtest-Plugin zum Hauptmenü hinzufügen" #: settings.py:303 msgid "Choose Directory:" @@ -837,11 +837,11 @@ msgstr "Catchup TV" #: startmenu.py:590 msgid "Reboot GUI" -msgstr "" +msgstr "Neustart-GUI" #: startmenu.py:593 msgid "Speed Test" -msgstr "" +msgstr "Geschwindigkeitstest" #: startmenu.py:734 msgid "" @@ -850,6 +850,10 @@ msgid "" "Playlists will not be deleted.\n" "Do you wish to continue?" msgstr "" +"Achtung: Gespeicherte json-Daten für alle Playlists löschen... " +"Einstellungen, Favoriten etc.\n" +"Wiedergabelisten werden nicht gelöscht.\n" +"Möchten Sie fortfahren?" #: vod.py:116 msgid "Vod Categories" @@ -878,12 +882,3 @@ msgstr "" #: vodplayer.py:497 msgid "VOD" msgstr "Video-on-Demand" - -#~ msgid "Set As Default Playlist" -#~ msgstr "Als Standard-Wiedergabeliste festlegen" - -#~ msgid "Switch Playlist" -#~ msgstr "Playliste wechseln" - -#~ msgid "Server not responding." -#~ msgstr "Server reagiert nicht." diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/series.py b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/series.py index 3e04166..20b5bdb 100644 --- a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/series.py +++ b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/series.py @@ -1118,6 +1118,81 @@ def selectionChanged(self): self["key_yellow"].setText("") self["key_blue"].setText("") + def stripjunk(self, text, database=None): + searchtitle = text.lower() + + # if title ends in "the", move "the" to the beginning + if searchtitle.endswith("the"): + searchtitle = "the " + searchtitle[:-4] + + # remove xx: at start + searchtitle = re.sub(r'^\w{2}:', '', searchtitle) + + # remove xx|xx at start + searchtitle = re.sub(r'^\w{2}\|\w{2}\s', '', searchtitle) + + # remove xx - at start + searchtitle = re.sub(r'^.{2}\+? ?- ?', '', searchtitle) + + # remove all leading content between and including || + searchtitle = re.sub(r'^\|\|.*?\|\|', '', searchtitle) + searchtitle = re.sub(r'^\|.*?\|', '', searchtitle) + + # remove everything left between pipes. + searchtitle = re.sub(r'\|.*?\|', '', searchtitle) + + # remove all content between and including () multiple times + if database == "TMDB": + searchtitle = re.sub(r'\(\(.*?\)\)|\(.*?\)', '', searchtitle) + + # remove all content between and including [] multiple times + searchtitle = re.sub(r'\[\[.*?\]\]|\[.*?\]', '', searchtitle) + + # List of bad strings to remove + bad_strings = [ + + "ae|", "al|", "ar|", "at|", "ba|", "be|", "bg|", "br|", "cg|", "ch|", "cz|", "da|", "de|", "dk|", + "ee|", "en|", "es|", "eu|", "ex-yu|", "fi|", "fr|", "gr|", "hr|", "hu|", "in|", "ir|", "it|", "lt|", + "mk|", "mx|", "nl|", "no|", "pl|", "pt|", "ro|", "rs|", "ru|", "se|", "si|", "sk|", "sp|", "tr|", + "uk|", "us|", "yu|", + "1080p", "1080p-dual-lat-cine-calidad.com", "1080p-dual-lat-cine-calidad.com-1", + "1080p-dual-lat-cinecalidad.mx", "1080p-lat-cine-calidad.com", "1080p-lat-cine-calidad.com-1", + "1080p-lat-cinecalidad.mx", "1080p.dual.lat.cine-calidad.com", "3d", "'", "#", "(", ")", "-", "[]", "/", + "4k", "720p", "aac", "blueray", "ex-yu:", "fhd", "hd", "hdrip", "hindi", "imdb", "multi:", "multi-audio", + "multi-sub", "multi-subs", "multisub", "ozlem", "sd", "top250", "u-", "uhd", "vod", "x264" + ] + + # Remove numbers from 1900 to 2030 + if database == "TMDB": + bad_strings.extend(map(str, range(1900, 2030))) + + # Construct a regex pattern to match any of the bad strings + bad_strings_pattern = re.compile('|'.join(map(re.escape, bad_strings))) + + # Remove bad strings using regex pattern + searchtitle = bad_strings_pattern.sub('', searchtitle) + + # List of bad suffixes to remove + bad_suffix = [ + " al", " ar", " ba", " da", " de", " en", " es", " eu", " ex-yu", " fi", " fr", " gr", " hr", " mk", + " nl", " no", " pl", " pt", " ro", " rs", " ru", " si", " swe", " sw", " tr", " uk", " yu" + ] + + # Construct a regex pattern to match any of the bad suffixes at the end of the string + bad_suffix_pattern = re.compile(r'(' + '|'.join(map(re.escape, bad_suffix)) + r')$') + + # Remove bad suffixes using regex pattern + searchtitle = bad_suffix_pattern.sub('', searchtitle) + + # Replace ".", "_", "'" with " " + searchtitle = re.sub(r'[._\'\*]', ' ', searchtitle) + + # Replace "-" with space and strip trailing spaces + searchtitle = searchtitle.strip(' -') + + searchtitle = searchtitle.strip() + return str(searchtitle) + def getTMDB(self): # print("**** getTMDB ***") @@ -1167,76 +1242,7 @@ def getTMDB(self): except: pass - searchtitle = title.lower() - - # if title ends in "the", move "the" to the beginning - if searchtitle.endswith("the"): - searchtitle = "the " + searchtitle[:-4].strip() - - # remove xx: at start - searchtitle = re.sub(r'^\w{2}:', '', searchtitle) - - # remove xx|xx at start - searchtitle = re.sub(r'^\w{2}\|\w{2}\s', '', searchtitle) - - # remove xx - at start - searchtitle = re.sub(r'^.{2}\+? ?- ?', '', searchtitle) - - # remove all leading content between and including || - searchtitle = re.sub(r'^\|\|.*?\|\|', '', searchtitle) - searchtitle = re.sub(r'^\|.*?\|', '', searchtitle) - - # remove everything left between pipes. - searchtitle = re.sub(r'\|.*?\|', '', searchtitle) - - # remove all content between and including () multiple times - searchtitle = re.sub(r'\(\(.*?\)\)|\(.*?\)', '', searchtitle) - - # remove all content between and including [] multiple times - searchtitle = re.sub(r'\[\[.*?\]\]|\[.*?\]', '', searchtitle) - - # Remove any prefix of characters followed by the special symbol ▎ and some content after it - searchtitle = re.sub(r'^.*?▎\s*', '', searchtitle) - - # Remove any prefix of characters followed by the special symbol | and some content after it - searchtitle = re.sub(r'^.*?\|\s*', '', searchtitle) - - # List of bad strings to remove - bad_strings = [ - "1080p", "1080p-dual-lat-cine-calidad.com", "1080p-dual-lat-cine-calidad.com-1", - "1080p-dual-lat-cinecalidad.mx", "1080p-lat-cine-calidad.com", "1080p-lat-cine-calidad.com-1", - "1080p-lat-cinecalidad.mx", "1080p.dual.lat.cine-calidad.com", "3d", "'", "#", "(", ")", "-", "[]", "/", - "4k", "720p", "aac", "blueray", "ex-yu:", "fhd", "hd", "hdrip", "hindi", "imdb", "multi:", "multi-audio", - "multi-sub", "multi-subs", "multisub", "ozlem", "sd", "top250", "u-", "uhd", "vod", "x264" - ] - - # Remove numbers from 1900 to 2030 - bad_strings.extend(map(str, range(1900, 2030))) - - # Construct a regex pattern to match any of the bad strings - bad_strings_pattern = re.compile('|'.join(map(re.escape, bad_strings))) - - # Remove bad strings using regex pattern - searchtitle = bad_strings_pattern.sub('', searchtitle) - - # List of bad suffixes to remove - bad_suffix = [ - " al", " ar", " ba", " da", " de", " en", " es", " eu", " ex-yu", " fi", " fr", " gr", " hr", " mk", - " nl", " no", " pl", " pt", " ro", " rs", " ru", " si", " swe", " sw", " tr", " uk", " yu" - ] - - # Construct a regex pattern to match any of the bad suffixes at the end of the string - bad_suffix_pattern = re.compile(r'(' + '|'.join(map(re.escape, bad_suffix)) + r')$') - - # Remove bad suffixes using regex pattern - searchtitle = bad_suffix_pattern.sub('', searchtitle) - - # Replace ".", "_", "'" with " " - searchtitle = re.sub(r'[._\'\*]', ' ', searchtitle) - - # Replace "-" with space and strip trailing spaces - searchtitle = searchtitle.strip(' -') - + searchtitle = self.stripjunk(title, "TMDB") searchtitle = quote(searchtitle, safe="") searchurl = 'http://api.themoviedb.org/3/search/tv?api_key={}&query={}'.format(self.check(self.token), searchtitle) diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/twisteddownloader.py b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/twisteddownloader.py new file mode 100644 index 0000000..21f1d48 --- /dev/null +++ b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/twisteddownloader.py @@ -0,0 +1,125 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import json +from twisted.internet import reactor +from twisted.web.client import readBody +from twisted.web.http_headers import Headers + +try: + from twisted.web.client import BrowserLikePolicyForHTTPS + contextFactory = BrowserLikePolicyForHTTPS() +except ImportError: + from twisted.web.client import WebClientContextFactory + contextFactory = WebClientContextFactory() + + +class DataDownloader: + def __init__(self, agent, python_version): + self.agent = agent + self.python_version = python_version + + def downloadData(self, searchurl, filepath, callback, data_type, errback, timeout=10): + print("*** downloadData ***") + try: + if self.python_version == 3: + self.data_download_deferred = self.agent.request( + b'GET', + searchurl, + Headers({'User-Agent': [b"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"]}), + None + ) + else: + self.data_download_deferred = self.agent.request( + 'GET', + searchurl, + Headers({'User-Agent': ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"]}), + None + ) + + # Adding a timeout to the deferred (this will cancel it if it exceeds the timeout) + self.data_download_deferred = self.data_download_deferred.addTimeout(timeout, reactor) + + # Adding callbacks to process the result and handle errors + self.data_download_deferred.addCallback(self.handleResponse, filepath, callback, data_type, errback) # Pass errback here + self.data_download_deferred.addErrback(errback) # Use the passed errback function + + except Exception as e: + print("Download error: {}".format(e)) + + def handleResponse(self, response, filepath, callback, data_type, errback, redirect_count=0): + print("*** handleResponse ***") + if response.code == 200: + d = readBody(response) + d.addCallback(self.processData, filepath, callback, data_type) + return d + elif response.code in (301, 302): # Handle redirects + if redirect_count >= 2: + print("Exceeded maximum redirects. Stopping further processing.") + self.failed() + return + + new_location = response.headers.getRawHeaders('location') + if new_location: + new_url = new_location[0].decode() if self.python_version == 3 else new_location[0] + print("Redirecting to:", new_url) + return self.downloadData(new_url, filepath, callback, data_type, errback, redirect_count + 1) # Pass errback here + else: + print("Redirect response but no location provided.") + self.failed() + return + else: + print("Failed to download data, HTTP response code: {}".format(response.code)) + self.failed() + + def processData(self, result, filepath, callback, data_type): + print("*** processData ***") + try: + # Directly handle the raw result without decoding it + if data_type == "json": + # Decode and process JSON data + data = result.decode('utf-8') if self.python_version == 3 else result + self.processJSON(data, filepath, callback) + + elif data_type == "image": + # Process image data directly + self.processImage(result, filepath, callback) + + else: + print("Unsupported data type: {}".format(data_type)) + + except Exception as e: + print("Error processing data: {}".format(e)) + self.failed() + + def processJSON(self, result, filepath, callback): + print("*** processJSON ***") + try: + json_data = json.loads(result) # No need to decode again, as it's already a string + with open(filepath, 'w') as json_file: + json.dump(json_data, json_file, indent=4) + + callback(json_data) + + except Exception as e: + print("Error processing JSON or saving file: {}".format(e)) + self.failed() + + def processImage(self, result, filepath, callback): + print("*** processImage ***") + try: + with open(filepath, 'wb') as f: + f.write(result) # Write the raw binary data directly + + print("Image saved to {}".format(filepath)) + callback() # Call the callback after saving the image + + except Exception as e: + print("Error processing Image or saving file: {}".format(e)) + self.failed() + + def failed(self, error=None): + print("*** failed ***") + if error: + print("Download failed: {}".format(error)) + return diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/version.txt b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/version.txt index 91db710..eb9faf1 100644 --- a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/version.txt +++ b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/version.txt @@ -1 +1 @@ -1.18-20241030 \ No newline at end of file +1.19-20241112 \ No newline at end of file diff --git a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/vod.py b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/vod.py index 3a4d598..59248eb 100644 --- a/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/vod.py +++ b/XKlass/usr/lib/enigma2/python/Plugins/Extensions/XKlass/vod.py @@ -920,43 +920,8 @@ def selectionChanged(self): self["key_yellow"].setText("") self["key_blue"].setText("") - def getTMDB(self): - # print("**** getTMDB ***") - title = "" - searchtitle = "" - self.searchtitle = "" - self.isIMDB = False - self.tmdb_id_exists = False - year = "" - - try: - os.remove(os.path.join(dir_tmp, "search.txt")) - except: - pass - - next_url = self["main_list"].getCurrent()[3] - - if next_url != "None" and "/movie/" in next_url: - title = self["main_list"].getCurrent()[0] - - if self.tmdbresults: - if "name" in self.tmdbresults and self.tmdbresults["name"]: - title = self.tmdbresults["name"] - elif "o_name" in self.tmdbresults and self.tmdbresults["o_name"]: - title = self.tmdbresults["o_name"] - - if "releasedate" in self.tmdbresults and self.tmdbresults["releasedate"]: - year = self.tmdbresults["releasedate"] - year = year[0:4] - - if "tmdb_id" in self.tmdbresults and self.tmdbresults["tmdb_id"]: - if str(self.tmdbresults["tmdb_id"])[:1].isdigit(): - self.getTMDBDetails(self.tmdbresults["tmdb_id"]) - return - else: - self.isIMDB = True - - searchtitle = title.lower() + def stripjunk(self, text, database=None): + searchtitle = text.lower() # if title ends in "the", move "the" to the beginning if searchtitle.endswith("the"): @@ -979,7 +944,8 @@ def getTMDB(self): searchtitle = re.sub(r'\|.*?\|', '', searchtitle) # remove all content between and including () multiple times - searchtitle = re.sub(r'\(\(.*?\)\)|\(.*?\)', '', searchtitle) + if database == "TMDB": + searchtitle = re.sub(r'\(\(.*?\)\)|\(.*?\)', '', searchtitle) # remove all content between and including [] multiple times searchtitle = re.sub(r'\[\[.*?\]\]|\[.*?\]', '', searchtitle) @@ -999,7 +965,8 @@ def getTMDB(self): ] # Remove numbers from 1900 to 2030 - bad_strings.extend(map(str, range(1900, 2030))) + if database == "TMDB": + bad_strings.extend(map(str, range(1900, 2030))) # Construct a regex pattern to match any of the bad strings bad_strings_pattern = re.compile('|'.join(map(re.escape, bad_strings))) @@ -1025,6 +992,46 @@ def getTMDB(self): # Replace "-" with space and strip trailing spaces searchtitle = searchtitle.strip(' -') + searchtitle = searchtitle.strip() + return str(searchtitle) + + def getTMDB(self): + # print("**** getTMDB ***") + title = "" + searchtitle = "" + self.searchtitle = "" + self.isIMDB = False + self.tmdb_id_exists = False + year = "" + + try: + os.remove(os.path.join(dir_tmp, "search.txt")) + except: + pass + + next_url = self["main_list"].getCurrent()[3] + + if next_url != "None" and "/movie/" in next_url: + title = self["main_list"].getCurrent()[0] + + if self.tmdbresults: + if "name" in self.tmdbresults and self.tmdbresults["name"]: + title = self.tmdbresults["name"] + elif "o_name" in self.tmdbresults and self.tmdbresults["o_name"]: + title = self.tmdbresults["o_name"] + + if "releasedate" in self.tmdbresults and self.tmdbresults["releasedate"]: + year = self.tmdbresults["releasedate"] + year = year[0:4] + + if "tmdb_id" in self.tmdbresults and self.tmdbresults["tmdb_id"]: + if str(self.tmdbresults["tmdb_id"])[:1].isdigit(): + self.getTMDBDetails(self.tmdbresults["tmdb_id"]) + return + else: + self.isIMDB = True + + searchtitle = self.stripjunk(title, "TMDB") searchtitle = quote(searchtitle, safe="") if not self.isIMDB: @@ -2145,6 +2152,7 @@ def openIMDb(self): if DreamOS and TMDB_installed: try: name = str(self["main_list"].getCurrent()[0]) + name = self.stripjunk(name) self.session.open(ScreenMain, name, 2) except: self.session.open(MessageBox, _("The TMDB plugin is not installed!\nPlease install it."), type=MessageBox.TYPE_INFO, timeout=10) @@ -2153,6 +2161,7 @@ def openIMDb(self): from Plugins.Extensions.IMDb.plugin import IMDB try: name = str(self["main_list"].getCurrent()[0]) + name = self.stripjunk(name) except: name = "" self.session.open(IMDB, name, False)