diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a591fbf..f891eeb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,10 +3,18 @@ + - - - + + + + + + + + + + @@ -33,20 +41,19 @@ - + - + - @@ -66,140 +73,129 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + + + - - + + - - + + - - - - - - + @@ -209,7 +205,7 @@ - + @@ -219,12 +215,9 @@ - - - @@ -256,47 +249,27 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - + @@ -347,80 +320,80 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -429,33 +402,23 @@ - + - + - + - - - - - - - - - - @@ -478,13 +441,6 @@ @@ -842,12 +805,6 @@ @@ -1146,6 +1109,7 @@ + @@ -1160,7 +1124,6 @@ - @@ -1177,7 +1140,6 @@ - @@ -1202,7 +1164,8 @@ - @@ -1211,34 +1174,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1274,20 +1209,6 @@ - - - - - - - - - - - - - - @@ -1316,13 +1237,6 @@ - - - - - - - @@ -1337,13 +1251,6 @@ - - - - - - - @@ -1365,32 +1272,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1501,10 +1382,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1512,7 +1468,7 @@ - + @@ -1522,12 +1478,9 @@ - - - @@ -1554,10 +1507,140 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1565,13 +1648,12 @@ - + - @@ -1591,264 +1673,128 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Content.py b/Content.py index df5a9d9..10b2e33 100644 --- a/Content.py +++ b/Content.py @@ -39,11 +39,11 @@ class Content: cookieJar = None baseurl = '' - def __del__(self): - print '!!!!!!!!!!!!!!!!!! DIED !!! '+self.__class__.__name__ + #def __del__(self): + # print '!!!!!!!!!!!!!!!!!! DIED !!! '+self.__class__.__name__ - def __init__(self): - print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ + #def __init__(self): + # print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ def isTracker(self): return 'Never seen' @@ -188,13 +188,13 @@ class Content: response = opener.open(url, encodedData) except urllib2.HTTPError as e: if e.code == 404: - print '[makeRequest]: Not Found! HTTP Error, e.code=' + str(e.code) + self.log('[makeRequest]: Not Found! HTTP Error, e.code=' + str(e.code)) return elif e.code in [503]: - print '[makeRequest]: Denied, HTTP Error, e.code=' + str(e.code) + self.log('[makeRequest]: Denied, HTTP Error, e.code=' + str(e.code)) return else: - print '[makeRequest]: HTTP Error, e.code=' + str(e.code) + self.log('[makeRequest]: HTTP Error, e.code=' + str(e.code)) return if response.info().get('Content-Encoding') == 'gzip': buf = StringIO(response.read()) diff --git a/Core.py b/Core.py index 9c20cb3..f569f71 100644 --- a/Core.py +++ b/Core.py @@ -41,10 +41,10 @@ class Core: language = {0: 'en', 1: 'ru', 2: 'ru'}.get(int(__settings__.getSetting("language"))) scrapperDB_ver = {'en':'1.1', 'ru':'1.3'} - print 'SYS ARGV: ' + str(sys.argv) + log('SYS ARGV: ' + str(sys.argv)) def __init__(self): - print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ + #print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ if len(self.userStorageDirectory) == 0: download_dir = get_download_dir() else: @@ -243,7 +243,7 @@ class Core: if 0 != len(torrentUrl): self.Downloader = Downloader.Torrent(self.userStorageDirectory, torrentUrl) else: - print self.__plugin__ + " Unexpected access to method Anteoloader() without torrent content" + log(self.__plugin__ + " Unexpected access to method Anteoloader() without torrent content") #if self.Downloader: # x=self.Downloader.getContentList() # print str(x) @@ -578,7 +578,7 @@ class Core: try: self.contenterObject[contenter] = getattr(__import__(contenter), contenter)() except Exception, e: - print 'Unable to use contenter: ' + contenter + ' at ' + ' Content(). Exception: ' + str(e) + log('Unable to use contenter: ' + contenter + ' at ' + ' Content(). Exception: ' + str(e)) if not subcategory: if not category and not provider: @@ -678,7 +678,7 @@ class Core: try: self.contenterObject[contenter] = getattr(__import__(contenter), contenter)() except Exception, e: - print 'Unable to use contenter: ' + contenter + ' at ' + ' Content(). Exception: ' + str(e) + log('Unable to use contenter: ' + contenter + ' at ' + ' Content(). Exception: ' + str(e)) if provider: for cat in self.Contenters.get_activedic().keys(): @@ -904,7 +904,7 @@ class Core: try: self.Content = getattr(__import__(contenter), contenter)() except Exception, e: - print 'Unable to use contenter: ' + contenter + ' at ' + ' ActionInfo(). Exception: ' + str(e) + log('Unable to use contenter: ' + contenter + ' at ' + ' ActionInfo(). Exception: ' + str(e)) movieInfo=self.Content.get_info(infolink) if movieInfo: @@ -1293,13 +1293,13 @@ class Core: if 0 != len(torrentUrl): self.Player = TorrentPlayer(userStorageDirectory=self.userStorageDirectory, torrentUrl=torrentUrl, params=params) else: - print self.__plugin__ + " Unexpected access to method playTorrent() without torrent content" + log(self.__plugin__ + " Unexpected access to method playTorrent() without torrent content") elif self.torrent_player == '2': from Anteoloader import AnteoPlayer if 0 != len(torrentUrl): self.Player = AnteoPlayer(userStorageDirectory=self.userStorageDirectory, torrentUrl=torrentUrl, params=params) else: - print self.__plugin__ + " Unexpected access to method playTorrent() without torrent content" + log(self.__plugin__ + " Unexpected access to method playTorrent() without torrent content") elif self.torrent_player == '1': __ASsettings__ = xbmcaddon.Addon(id='script.module.torrent.ts') folder=__ASsettings__.getSetting("folder") @@ -1336,7 +1336,7 @@ class Core: localFile.close() return torrentFile except: - print 'Unable to save torrent file from "' + url + '" to "' + torrentFile + '" in Torrent::saveTorrent' + log('Unable to save torrent file from "' + url + '" to "' + torrentFile + '" in Torrent::saveTorrent') return def playSTRM(self, params={}): diff --git a/Downloader.py b/Downloader.py index 823e5da..69d2492 100644 --- a/Downloader.py +++ b/Downloader.py @@ -24,7 +24,7 @@ import sys import Libtorrent import AceStream import Anteoloader - +from functions import log class Torrent(): __settings__ = sys.modules["__main__"].__settings__ @@ -136,6 +136,6 @@ class Torrent(): def dump(self, obj): for attr in dir(obj): try: - print "'%s':'%s'," % (attr, getattr(obj, attr)) + log("'%s':'%s'," % (attr, getattr(obj, attr))) except: pass diff --git a/Libtorrent.py b/Libtorrent.py index 11dd7df..9b009c8 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -116,15 +116,14 @@ class Libtorrent: localFile.write(content) localFile.close() except Exception, e: - print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str( - e) + log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(e)) return if xbmcvfs.exists(torrentFile): try: e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read()) self.torrentFileInfo = self.lt.torrent_info(e) except Exception, e: - print 'Exception: ' + str(e) + log('Exception: ' + str(e)) xbmcvfs.delete(torrentFile) return baseName = file_encode(os.path.basename(self.getFilePath())) @@ -503,7 +502,7 @@ class Libtorrent: # print str(s.pieces) #except: else: - print 'debug error' + log('debug error') pass def get_debug_info(self, info): @@ -534,6 +533,6 @@ class Libtorrent: def dump(self, obj): for attr in dir(obj): try: - print "'%s':'%s'," % (attr, getattr(obj, attr)) + log("'%s':'%s'," % (attr, getattr(obj, attr))) except: pass diff --git a/SearcherABC.py b/SearcherABC.py index d6dc548..4c7f3cb 100644 --- a/SearcherABC.py +++ b/SearcherABC.py @@ -48,11 +48,11 @@ class SearcherABC: socket.setdefaulttimeout(10+(10*int(timeout_multi))) - def __del__(self): - print '!!!!!!!!!!!!!!!!!! DIED !!! '+self.__class__.__name__ + #def __del__(self): + # print '!!!!!!!!!!!!!!!!!! DIED !!! '+self.__class__.__name__ - def __init__(self): - print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ + #def __init__(self): + # print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__ def search(self, keyword): ''' diff --git a/controlcenter.py b/controlcenter.py index bf46302..faf0a0c 100644 --- a/controlcenter.py +++ b/controlcenter.py @@ -23,7 +23,7 @@ import sys import xbmcaddon import xbmc import xbmcgui -from functions import getParameters, HistoryDB, Searchers +from functions import getParameters, HistoryDB, Searchers, log from resources.pyxbmct.addonwindow import * __settings__ = xbmcaddon.Addon(id='plugin.video.torrenter') @@ -32,7 +32,7 @@ __version__ = __settings__.getAddonInfo('version') __plugin__ = __settings__.getAddonInfo('name') + " v." + __version__ __root__ = __settings__.getAddonInfo('path') -print 'SYS ARGV: ' + str(sys.argv) +log('SYS ARGV: ' + str(sys.argv)) if len(sys.argv) > 1: params = getParameters(sys.argv[1]) diff --git a/default.py b/default.py index 61f0b6b..7a7d548 100644 --- a/default.py +++ b/default.py @@ -21,6 +21,7 @@ import sys import gc import xbmcaddon +from functions import log __settings__ = xbmcaddon.Addon(id='plugin.video.torrenter') @@ -29,7 +30,7 @@ __plugin__ = __settings__.getAddonInfo('name') + " v." + __version__ __root__ = __settings__.getAddonInfo('path') if (__name__ == "__main__" ): - print __plugin__ + log(__plugin__) import Core core = Core.Core() @@ -41,4 +42,4 @@ if (__name__ == "__main__" ): del core collected = gc.collect() -print "Garbage collector: collected %d objects." % (collected) \ No newline at end of file +log("Garbage collector: collected %d objects." % (collected)) \ No newline at end of file diff --git a/functions.py b/functions.py index 357152f..40d294c 100644 --- a/functions.py +++ b/functions.py @@ -426,7 +426,6 @@ def cutFolder(contentList, tdir=None): common = True for fileTitle, contentId in contentList: if common_folder not in fileTitle: - print 'no common' common = False break @@ -1065,28 +1064,26 @@ class Searchers(): slist = self.list() if slist[searcher]['path'] not in sys.path: sys.path.insert(0, slist[searcher]['path']) - print 'Added %s in sys.path' % (slist[searcher]['path']) + log('Added %s in sys.path' % (slist[searcher]['path'])) try: searcherObject = getattr(__import__(searcher), searcher) filesList = searcherObject().search(keyword) del searcherObject except Exception, e: - print 'Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' searchWithSearcher(). Exception: ' + str( - e) - print(traceback.format_exc()) + log('Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' searchWithSearcher(). Exception: ' + str(e)) + log(traceback.format_exc()) return filesList def downloadWithSearcher(self, url, searcher): slist = Searchers().list() if slist[searcher]['path'] not in sys.path: sys.path.insert(0, slist[searcher]['path']) - print 'Added %s in sys.path' % (slist[searcher]['path']) + log('Added %s in sys.path' % (slist[searcher]['path'])) try: searcherObject = getattr(__import__(searcher), searcher)() url = searcherObject.getTorrentFile(url) except Exception, e: - print 'Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' downloadWithSearcher(). Exception: ' + str( - e) + log('Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' downloadWithSearcher(). Exception: ' + str(e)) return url def checkExist(self, searcher): @@ -1144,7 +1141,7 @@ def search(url, searchersList, isApi=None): if searcherFile == CleanExit: return searcher=searcherFile.replace('.py','') - print "Thread %s: Searching at %s" % (i, searcher) + log("Thread %s: Searching at %s" % (i, searcher)) result[searcherFile]=Searchers().searchWithSearcher(url, searcher) left_searchers.remove(searcherFile) q.task_done() @@ -1161,16 +1158,16 @@ def search(url, searchersList, isApi=None): for searcherFile in searchersList: queue.put(searcherFile) - print "Main Thread Waiting" + log("Main Thread Waiting") queue.join() for i in range(num_threads): queue.put(CleanExit) - print "Main Thread Waiting for Threads" + log("Main Thread Waiting for Threads") for w in workers: w.join() - print "Done" + log("Done") if not isApi: progressBar.update(0) @@ -1309,7 +1306,7 @@ def fetchData(url, referer=None): connection.close() return (result) except (urllib2.HTTPError, urllib2.URLError) as e: - print " fetchData(" + url + ") exception: " + str(e) + log(" fetchData(" + url + ") exception: " + str(e)) return @@ -1817,9 +1814,9 @@ def check_network_advancedsettings(): f.close() dialog.ok(Localization.localize('Upgrade advancedsettings.xml'), Localization.localize('Please, restart Kodi now!')) - print 'Restart Kodi' + log('Restart Kodi') else: - print 'UPDATE advancedsettings.xml disabled by user!' + log('UPDATE advancedsettings.xml disabled by user!') def get_download_dir(): from platform_pulsar import get_platform diff --git a/resources/scrapers/kinopoisk/LOGGER.py b/resources/scrapers/kinopoisk/LOGGER.py index 94ac243..5197d9d 100644 --- a/resources/scrapers/kinopoisk/LOGGER.py +++ b/resources/scrapers/kinopoisk/LOGGER.py @@ -2,6 +2,7 @@ # try: import xbmcaddon + from functions import log, debug __settings__ = xbmcaddon.Addon("plugin.video.torrenter") debug = __settings__.getSetting("debug") @@ -10,31 +11,19 @@ except: def Log(msg, force=False): - try: - print "[torrenter log] " + msg - except UnicodeEncodeError: - print "[torrenter log] " + msg.encode("utf-8", "ignore") + log(msg) def Debug(msg, force=False): if debug == 'true' or force: - try: - print "[torrenter] " + msg - except UnicodeEncodeError: - print "[torrenter] " + msg.encode("utf-8", "ignore") + debug(msg, True) def Info(msg, force=False): if debug == 'true' or force: - try: - print "[torrenter] " + msg - except UnicodeEncodeError: - print "[torrenter] " + msg.encode("utf-8", "ignore") + debug(msg, True) def Warn(msg, force=False): if debug == 'true' or force: - try: - print "[torrenter] " + msg - except UnicodeEncodeError: - print "[torrenter] " + msg.encode("utf-8", "ignore") \ No newline at end of file + debug(msg, True) \ No newline at end of file diff --git a/resources/scrapers/tmdbs.py b/resources/scrapers/tmdbs.py index 8a1d797..302c16f 100644 --- a/resources/scrapers/tmdbs.py +++ b/resources/scrapers/tmdbs.py @@ -4,6 +4,7 @@ import time import urllib from cache import Cache +from functions import log import tmdb @@ -154,9 +155,9 @@ class TmDb: movie_id = None for name in search: movies = tmdb.Movies(title=name, year=year, limit=True).get_ordered_matches() - print '********************************************************' + log('********************************************************') try: - print str(isAsciiString(movies[1]['title'])) + log(str(isAsciiString(movies[1]['title']))) except: pass @@ -320,7 +321,7 @@ def scoreMediaTitleMatch(mediaName, mediaAltTitle, mediaYear, title, original_ti def get_best(Data, search, year): - print '****** Finding TMDB: ' + str(search) + '; year ' + str(year) + log('****** Finding TMDB: ' + str(search) + '; year ' + str(year)) shows = [] itemIndex = -1 if len(search) == 2: @@ -349,7 +350,7 @@ def get_best(Data, search, year): release_date=str(show.get('release_date').split('-')[0]) else: release_date='0' - print (' ... %d: id="%s", name="%s", year="%s", score="%d".' % + log(' ... %d: id="%s", name="%s", year="%s", score="%d".' % (i, str(show['id']), show.get('title').encode('utf-8'), release_date, s['rate'])) if shows: diff --git a/resources/scrapers/tvdb.py b/resources/scrapers/tvdb.py index 0f70360..7d15673 100644 --- a/resources/scrapers/tvdb.py +++ b/resources/scrapers/tvdb.py @@ -10,6 +10,7 @@ import zipfile import xbmc from net import HTTP from cache import Cache +from functions import log class TvDb: @@ -82,7 +83,7 @@ class TvDb: # print url response = self.http.fetch(url, headers=self.headers, download=os.path.join(dirname, 'movie.zip'), timeout=20) if response.error: - print "ERRRRRROR! " + str(response.error) + log("ERRRRRROR! " + str(response.error)) self._movie_clear(dirname) return False, None @@ -411,7 +412,7 @@ def get_best(Data, search, year): shows.append({'rate': rate, 'id': id}) shows = sorted(shows, key=lambda x: x['rate'], reverse=True) - print '********************** TheTVDB ******************************' - print str(shows) + str(mediaName.encode('utf-8')) + log('********************** TheTVDB ******************************') + log(str(shows) + str(mediaName.encode('utf-8'))) if shows: return shows[0] \ No newline at end of file diff --git a/resources/utorrent/net.py b/resources/utorrent/net.py index ea32cd5..932bdc7 100644 --- a/resources/utorrent/net.py +++ b/resources/utorrent/net.py @@ -853,7 +853,7 @@ class Deluge: if port: self.url += ':' + str(port) self.url += url - print str(self.url) + log(str(self.url)) self.http = HTTP() def get_info(self):