From 472635beab47a42f2a20f36bf000716669367aec Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 20 Jul 2015 19:31:37 +0300 Subject: [PATCH] keep_files ask --- Core.py | 23 ++++++---- Libtorrent.py | 20 +++++---- Localization.py | 2 + Player.py | 4 +- addon.xml | 2 +- changelog.txt | 8 +++- functions.py | 58 +++++++++++++++++++++----- resources/language/English/strings.xml | 3 ++ resources/language/Russian/strings.xml | 3 ++ resources/settings.xml | 4 +- 10 files changed, 94 insertions(+), 33 deletions(-) diff --git a/Core.py b/Core.py index c86339f..3d0faf8 100644 --- a/Core.py +++ b/Core.py @@ -138,7 +138,7 @@ class Core: self.drawItem('full_download', 'full_download', image=self.ROOT + '/icons/magnet.png') self.drawItem('test', 'test', image=self.ROOT + '/icons/magnet.png') - if 'true' == self.__settings__.getSetting("keep_files"): + if '0' != self.__settings__.getSetting("keep_files"): self.drawItem('< %s >' % self.localize('Clear Storage'), 'clearStorage', isFolder=True, image=self.ROOT + '/icons/clear.png') view_style('sectionMenu') @@ -1287,16 +1287,21 @@ class Core: xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True) def userStorage(self, params): - if self.__settings__.getSetting("keep_files")=='true' \ - and self.__settings__.getSetting("ask_dir")=='true': - try: - save_folder = urllib.unquote_plus(params.get('save_folder')) - except: - save_folder = '' + save=False + if self.__settings__.getSetting("keep_files")=='2': + dialog = xbmcgui.Dialog() + save = dialog.yesno(self.localize('Ask to save'), self.localize('Would you like to save this file?')) + if save: + self.userStorageDirectory = os.path.join(self.userStorageDirectory, 'Saved Files') + if self.__settings__.getSetting("keep_files")=='1' and\ + self.__settings__.getSetting("ask_dir")=='true' or\ + self.__settings__.getSetting("keep_files")=='2' and\ + self.__settings__.getSetting("ask_dir")=='true' and save: + save_folder = unquote(params.get('save_folder'), '') if len(save_folder)>0: - default=os.path.join(self.userStorageDirectory, save_folder) + default = os.path.join(self.userStorageDirectory, save_folder) else: - default=self.userStorageDirectory + default = self.userStorageDirectory keyboard = xbmc.Keyboard(default, self.localize('Save to path') + ':') keyboard.doModal() dirname = keyboard.getText() diff --git a/Libtorrent.py b/Libtorrent.py index 3659b61..041cb72 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -30,7 +30,7 @@ import xbmc import xbmcgui import xbmcvfs import Localization -from functions import file_decode, file_encode, isSubtitle, DownloadDB +from functions import file_decode, file_encode, isSubtitle, DownloadDB, log, debug from platform_pulsar import get_platform @@ -320,9 +320,12 @@ class Libtorrent: #tribler example never tested #self.session.set_severity_level(self.lt.alert.severity_levels.info) - #self.session.add_extension(self.lt.create_ut_pex_plugin) - #self.session.add_extension(self.lt.create_ut_metadata_plugin) - #self.session.add_extension(self.lt.create_metadata_plugin) + self.session.add_extension("ut_pex") + self.session.add_extension("lt_trackers") + self.session.add_extension("metadata_transfer") + self.session.add_extension("ut_metadata") + # Ban peers that sends bad data + self.session.add_extension("smart_ban") # Session settings session_settings = self.session.settings() @@ -372,7 +375,7 @@ class Libtorrent: if None == self.magnetLink: self.torrentHandle = self.session.add_torrent({'ti': self.torrentFileInfo, 'save_path': self.storageDirectory, - 'flags': 0x300, + #'flags': 0x300, # 'storage_mode': self.lt.storage_mode_t.storage_mode_allocate, }) else: @@ -421,8 +424,11 @@ class Libtorrent: def checkThread(self): if self.threadComplete == True: - print 'checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL' - self.session.remove_torrent(self.torrentHandle) + log('checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL') + try: + self.session.remove_torrent(self.torrentHandle) + except: + log('RuntimeError: invalid torrent handle used') self.session.stop_natpmp() self.session.stop_upnp() self.session.stop_lsd() diff --git a/Localization.py b/Localization.py index cfc04b6..8e80eaf 100644 --- a/Localization.py +++ b/Localization.py @@ -264,6 +264,8 @@ def localize(text): 'I deleted pre-installed ones, install them in Search Control Window!':'Теперь серчеры нужно устанавливать отдельно в Окне Управления Поиском!', 'Torrenter didn\'t find %s searcher':'Торрентер не нашел серчер трекера %s', 'Torrenter Tracker Install':'Установка трекеров в Torrenter', + 'Ask to save':'Спросить о сохранении', + 'Would you like to save this file?':'Хотите сохранить данный файл?', }, 'uk': { diff --git a/Player.py b/Player.py index 4aadff6..b713b13 100644 --- a/Player.py +++ b/Player.py @@ -129,7 +129,7 @@ class TorrentPlayer(xbmc.Player): torrentFilesDirectory = 'torrents' debug = __settings__.getSetting('debug') == 'true' subs_dl = __settings__.getSetting('subs_dl') == 'true' - seeding = __settings__.getSetting('keep_seeding') == 'true' and __settings__.getSetting('keep_files') == 'true' + seeding = __settings__.getSetting('keep_seeding') == 'true' and __settings__.getSetting('keep_files') == '1' seeding_status = False seeding_run = False ids_video = None @@ -171,7 +171,7 @@ class TorrentPlayer(xbmc.Player): self.torrent.stopSession() self.torrent.threadComplete = True self.torrent.checkThread() - if 'false' == self.__settings__.getSetting("keep_files"): + if '1' != self.__settings__.getSetting("keep_files") and 'Saved Files' not in self.userStorageDirectory: clearStorage(self.userStorageDirectory) else: if self.seeding_status: diff --git a/addon.xml b/addon.xml index 9d341c4..4263233 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + diff --git a/changelog.txt b/changelog.txt index 136e1f7..7a81166 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ -[B]Version 2.3.3[/B] +English changelog at http://bit.ly/1MfSVUP + +[B]Version 2.3.4[/B] +[+] Проигрыватель: Новая настройка - спрашивать о сохранении файла +[+] Списки Медиа: Исправлен TheMovieDB для python 2.6 + +[B]Version 2.3.3[/B] [+] Поиск: Настройка количества потоков при поиске [B]Version 2.3.2[/B] diff --git a/functions.py b/functions.py index b3589cd..40e3876 100644 --- a/functions.py +++ b/functions.py @@ -53,7 +53,6 @@ __language__ = __settings__.getLocalizedString ROOT = __settings__.getAddonInfo('path') # .decode('utf-8').encode(sys.getfilesystemencoding()) userStorageDirectory = __settings__.getSetting("storage") USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0" -torrentFilesDirectory = 'torrents' __addonpath__ = __settings__.getAddonInfo('path') icon = __addonpath__ + '/icon.png' debug = __settings__.getSetting("debug") @@ -62,22 +61,40 @@ __plugin__ = __settings__.getAddonInfo('name') + " v." + __version__ def clearStorage(userStorageDirectory): - try: - userStorageDirectory = userStorageDirectory.decode('utf-8') - except: - pass + userStorageDirectory = decode(userStorageDirectory) if xbmcvfs.exists(userStorageDirectory + os.sep): import shutil temp = userStorageDirectory.rstrip('Torrenter').rstrip('/\\') - torrents_temp, i = None, 0 - while not torrents_temp or xbmcvfs.exists(torrents_temp): + torrents_temp, saved_temp, i = None, None, '' + while not torrents_temp or os.path.exists(torrents_temp) or os.path.exists(saved_temp): torrents_temp = os.path.join(temp, 'torrents' + str(i)) + os.sep - i += 1 - shutil.move(os.path.join(userStorageDirectory, 'torrents'), torrents_temp) + saved_temp = os.path.join(temp, 'Saved Files' + str(i)) + os.sep + if i=='': + i=0 + else: + i += 1 + + torrents = os.path.join(userStorageDirectory, 'torrents') + saved = os.path.join(userStorageDirectory, 'Saved Files') + torrents_bool, saved_bool = False, False + + if os.path.exists(torrents): + torrents_bool = shutil.move(torrents, torrents_temp) + torrents_bool = True + + if os.path.exists(saved): + saved_bool = shutil.move(saved, saved_temp) + saved_bool = True + shutil.rmtree(userStorageDirectory, ignore_errors=True) xbmcvfs.mkdir(userStorageDirectory) - shutil.move(torrents_temp, os.path.join(userStorageDirectory, 'torrents')) + + if torrents_bool: + shutil.move(torrents_temp, torrents) + if saved_bool: + shutil.move(saved_temp, saved) + DownloadDB().clear() showMessage(Localization.localize('Storage'), Localization.localize('Storage was cleared'), forced=True) @@ -1832,4 +1849,23 @@ def noActiveSerachers(): Localization.localize('Would you like to install %s from "MyShows.me Kodi Repo" in Programs section?') % '',) if yes: xbmc.executebuiltin('Dialog.Close(all,true)') - xbmc.executebuiltin('XBMC.ActivateWindow(Addonbrowser,addons://search/%s)' % ('Torrenter Searcher')) \ No newline at end of file + xbmc.executebuiltin('XBMC.ActivateWindow(Addonbrowser,addons://search/%s)' % ('Torrenter Searcher')) + +def windows_check(): + import platform + """ + Checks if the current platform is Windows + :returns: True or False + :rtype: bool + """ + return platform.system() in ('Windows', 'Microsoft') + + +def vista_check(): + import platform + """ + Checks if the current platform is Windows Vista + :returns: True or False + :rtype: bool + """ + return platform.release() == "Vista" \ No newline at end of file diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 8de4d1a..eb8fc61 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -40,6 +40,9 @@ Custom search option phrase Encryption Search Thread Number + Delete files + Save files + Ask to save Interface P2P Network Advanced diff --git a/resources/language/Russian/strings.xml b/resources/language/Russian/strings.xml index 142e780..1f3555c 100644 --- a/resources/language/Russian/strings.xml +++ b/resources/language/Russian/strings.xml @@ -40,6 +40,9 @@ Дополнительная фраза в вариантах поиска Шифрование Количество параллельных потоков поиска + Удалять файлы + Сохранять файлы + Спросить о сохранении Интерфейс P2P Сеть Дополнительные diff --git a/resources/settings.xml b/resources/settings.xml index 5cb8a7d..038966b 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -16,9 +16,9 @@ - + - +