Did some formatting changes to make it more readable

This commit is contained in:
2017-03-05 00:50:08 +01:00
parent 9a04584b02
commit 4d854a0f80

View File

@@ -3,7 +3,7 @@
# @Author: KevinMidboe # @Author: KevinMidboe
# @Date: 2017-03-04 16:50:09 # @Date: 2017-03-04 16:50:09
# @Last Modified by: KevinMidboe # @Last Modified by: KevinMidboe
# @Last Modified time: 2017-03-04 22:15:21 # @Last Modified time: 2017-03-05 00:49:03
import os, sqlite3, re import os, sqlite3, re
from fuzzywuzzy import process from fuzzywuzzy import process
@@ -15,9 +15,6 @@ dbPath = 'shows.db'
mediaExtensions = ['mkv', 'mp4', 'avi'] mediaExtensions = ['mkv', 'mp4', 'avi']
subExtensions = ['srt'] subExtensions = ['srt']
def XOR(list1, list2):
return set(list1) ^ set(list2)
def getFuzzyName(query): def getFuzzyName(query):
return process.extractOne(query, getShowNames().keys()) return process.extractOne(query, getShowNames().keys())
@@ -50,12 +47,18 @@ def getShowNames():
conn.close() conn.close()
return returnList return returnList
def XOR(list1, list2):
return set(list1) ^ set(list2)
def getNewFolderContents(): def getNewFolderContents():
showNames = getShowNames().keys() showNames = getShowNames().keys()
folderContents = filter( lambda f: not f.startswith('.'), os.listdir(showDir)) folderContents = filter( lambda f: not f.startswith('.'), os.listdir(showDir))
return XOR(folderContents, showNames) return XOR(folderContents, showNames)
def checkForSingleEpisodes(folderItem): def checkForSingleEpisodes(folderItem):
showName, hit = getFuzzyName(folderItem) showName, hit = getFuzzyName(folderItem)
episodeMatch = re.findall(re.sub(' ', '.', showName)+'\.S[0-9]{1,2}E[0-9]{1,2}\.', folderItem) episodeMatch = re.findall(re.sub(' ', '.', showName)+'\.S[0-9]{1,2}E[0-9]{1,2}\.', folderItem)
@@ -63,6 +66,8 @@ def checkForSingleEpisodes(folderItem):
if episodeMatch: if episodeMatch:
return True return True
def getByIdentifier(folderItem, identifier): def getByIdentifier(folderItem, identifier):
itemMatch = re.findall(identifier + '[0-9]{1,2}', folderItem) itemMatch = re.findall(identifier + '[0-9]{1,2}', folderItem)
item = re.sub(identifier, '', itemMatch[0]) item = re.sub(identifier, '', itemMatch[0])
@@ -84,7 +89,6 @@ def getItemChildren(folder):
return media_items, subtitles, trash return media_items, subtitles, trash
def getEpisodeInfo(folderItem): def getEpisodeInfo(folderItem):
showName, hit = getFuzzyName(folderItem) showName, hit = getFuzzyName(folderItem)
season = getByIdentifier(folderItem, 'S') season = getByIdentifier(folderItem, 'S')
@@ -105,6 +109,7 @@ def getEpisodeInfo(folderItem):
return episodeInfo return episodeInfo
def main(): def main():
for item in getNewFolderContents(): for item in getNewFolderContents():
if checkForSingleEpisodes(item): if checkForSingleEpisodes(item):