From 49d123594b501eae60c55d43d5d7d9a8a588c623 Mon Sep 17 00:00:00 2001 From: DiMartinoX Date: Sun, 11 Jan 2015 20:17:11 +0300 Subject: [PATCH] moveout some minor functions from Core --- .idea/workspace.xml | 957 +++++++++++++++++++++++++++++++++++++------- Core.py | 103 +---- functions.py | 42 ++ 3 files changed, 847 insertions(+), 255 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cdba472..9798d38 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,12 +3,7 @@ - - - - - @@ -43,11 +38,12 @@ - - + + + @@ -68,24 +64,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -94,7 +88,7 @@ - + @@ -114,8 +108,8 @@ - - + + @@ -135,10 +129,10 @@ - + - + @@ -155,22 +149,132 @@ - - - - - - - - - - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -211,8 +315,8 @@ @@ -249,7 +353,6 @@ - @@ -328,6 +431,7 @@ + @@ -527,7 +631,11 @@ 1420904827834 1420904827834 - @@ -566,12 +674,12 @@ - + - + @@ -592,21 +700,207 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + @@ -627,24 +921,262 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -696,6 +1228,7 @@ + @@ -716,24 +1249,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -785,6 +1316,7 @@ + @@ -805,24 +1337,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -875,7 +1405,6 @@ - @@ -902,14 +1431,6 @@ - - - - - - - - @@ -929,6 +1450,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -949,37 +1493,142 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + @@ -1000,24 +1649,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/Core.py b/Core.py index 7558f0f..a69b8e3 100644 --- a/Core.py +++ b/Core.py @@ -1038,7 +1038,7 @@ class Core: #print str(contentList) - dirList, contentListNew = self.cutFolder(contentList, tdir) + dirList, contentListNew = cutFolder(contentList, tdir) for title in dirList: self.drawItem(title, 'openTorrent', url, isFolder=True, action2=title) @@ -1175,7 +1175,6 @@ class Core: torrentFilesDirectory=self.torrentFilesDirectory) self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) if silent != 'true': - contentId = 0 if external: myshows_setting = xbmcaddon.Addon(id='plugin.video.myshows') myshows_lang = myshows_setting.getLocalizedString @@ -1195,7 +1194,7 @@ class Core: re.I | re.DOTALL): myshows_items.append(title) myshows_files.append('plugin://plugin.video.torrenter/?action=playTorrent&url=' + identifier) - if len(myshows_items) > 1: myshows_items = self.cutFileNames(myshows_items) + if len(myshows_items) > 1: myshows_items = cutFileNames(myshows_items) myshows_items.append(unicode(myshows_lang(30400))) myshows_files.append('') dialog = xbmcgui.Dialog() @@ -1214,7 +1213,7 @@ class Core: contentList.append((self.unescape(fileTitle), str(filedict.get('ind')))) contentList = sorted(contentList, key=lambda x: x[0]) - dirList, contentListNew = self.cutFolder(contentList, tdir) + dirList, contentListNew = cutFolder(contentList, tdir) for title in dirList: self.drawItem(title, 'openTorrent', url, image=thumbnail, isFolder=True, action2=title) @@ -1244,102 +1243,6 @@ class Core: url = self.__settings__.getSetting("lastTorrent") self.downloadFilesList({'url': url, 'ind': params.get("url")}) - def cutFolder(self, contentList, tdir=None): - dirList, contentListNew = [], [] - - if len(contentList) > 1: - common_folder = contentList[0][0] - if '\\' in common_folder: - common_folder = common_folder.split('\\')[0] - elif '/' in common_folder: - common_folder = common_folder.split('/')[0] - - common = True - for fileTitle, contentId in contentList: - if common_folder not in fileTitle: - print 'no common' - common = False - break - - #print common_folder - for fileTitle, contentId in contentList: - dir = None - if common: - fileTitle = fileTitle[len(common_folder) + 1:] - - #print fileTitle - - if '\\' in fileTitle: - dir = fileTitle.split('\\')[0] - elif '/' in fileTitle: - dir = fileTitle.split('/')[0] - elif not tdir: - contentListNew.append((fileTitle, contentId)) - - if tdir and dir == tdir: - contentListNew.append((fileTitle[len(dir) + 1:], contentId)) - - if not tdir and dir and dir not in dirList: - dirList.append(dir) - - return dirList, contentListNew - else: - return dirList, contentList - - def cutFileNames(self, l): - from difflib import Differ - - d = Differ() - i = -1 - m = self.getDirList(None, l) - if len(m) < 2: return l - text1 = str(m[0]) - text2 = str(m[1]) - - seps = ['.|:| ', '.|:|x', ' |:|x', ' |:|-', '_|:|', ] - for s in seps: - sep_file = str(s).split('|:|')[0] - result = list(d.compare(text1.split(sep_file), text2.split(sep_file))) - if len(result) > 5: - break - - print list(d.compare(text1.split(sep_file), text2.split(sep_file))) - - start = '' - end = '' - - for res in result: - if str(res).startswith('-') or str(res).startswith('+') or str(res).startswith('.?'): - break - start = start + str(res).strip() + sep_file - result.reverse() - for res in result: - if str(res).startswith('-') or str(res).startswith('+') or str(res).startswith('?'): - break - end = sep_file + str(res).strip() + end - - newl = l - l = [] - for fl in newl: - if fl[0:len(start)] == start: fl = fl[len(start):] - if fl[len(fl) - len(end):] == end: fl = fl[0:len(fl) - len(end)] - #fl=fl[len(start):len(fl)-len(end)] только это вместо 2 сверху - l.append(fl) - return l - - def getDirList(self, path, newl=None): - l = [] - try: - if not newl: newl = os.listdir(path) - except: - if not newl: newl = os.listdir(path.decode('utf-8').encode('cp1251')) - for fl in newl: - match = re.match('.avi|.mp4|.mkV|.flv|.mov|.vob|.wmv|.ogm|.asx|.mpg|mpeg|.avc|.vp3|.fli|.flc|.m4v', - fl[int(len(fl)) - 4:len(fl)], re.I) - if match: - l.append(fl) - return l - def openSection(self, params={}): get = params.get url = urllib.unquote_plus(get("url")) diff --git a/functions.py b/functions.py index 31887f6..ed7a7a5 100644 --- a/functions.py +++ b/functions.py @@ -567,6 +567,48 @@ def sortext(filelist): return result +def cutFolder(contentList, tdir=None): + dirList, contentListNew = [], [] + + if len(contentList) > 1: + common_folder = contentList[0][0] + if '\\' in common_folder: + common_folder = common_folder.split('\\')[0] + elif '/' in common_folder: + common_folder = common_folder.split('/')[0] + + common = True + for fileTitle, contentId in contentList: + if common_folder not in fileTitle: + print 'no common' + common = False + break + + #print common_folder + for fileTitle, contentId in contentList: + dir = None + if common: + fileTitle = fileTitle[len(common_folder) + 1:] + + #print fileTitle + + if '\\' in fileTitle: + dir = fileTitle.split('\\')[0] + elif '/' in fileTitle: + dir = fileTitle.split('/')[0] + elif not tdir: + contentListNew.append((fileTitle, contentId)) + + if tdir and dir == tdir: + contentListNew.append((fileTitle[len(dir) + 1:], contentId)) + + if not tdir and dir and dir not in dirList: + dirList.append(dir) + + return dirList, contentListNew + else: + return dirList, contentList + def sweetpair(l): from difflib import SequenceMatcher