Bugs fixing + moving folders configuration in pigeonhole/config.py and

integrate subliminal when a file is moved.
This commit is contained in:
Fred Pauchet 2012-07-26 20:03:47 +02:00
parent 7d1b908875
commit be8c9476b7
3 changed files with 41 additions and 13 deletions

View File

@ -1,15 +1,19 @@
# -*- coding: UTF8 -*-
# Configuration file
### Defines the folder to watch and the destination folder
ROOT_FOLDER = r'/home/fred/Videos/Series'
DL_FOLDER = r'/home/fred/Téléchargements/complete'
### If a folder only contains these types of files, we can delete it.
useless_files_extensions = ('srr', 'nfo', 'sfv')
useless_files_extensions = ('srr', 'nfo', 'sfv', 'nzb')
### Consider only files with these extensions
shows_extensions = ('avi', 'mkv')
shows_extensions = ('avi', 'mkv', 'mp4')
### Dictionary for special filename contents
shows_dict = {
'wc' : 'white collar',
'tbbt' : 'the big bang theory',
'beingerica' : 'being erica',
}
}

View File

@ -19,10 +19,13 @@ class Show(object):
self.path = path
self.name = os.path.basename(path)
def directory(self):
return os.path.dirname(self.path)
self.url = queryShow(self.name)
#self.url = queryShow(self.name)
self.seasons = [Season(self, os.path.join(path, x)) for x in os.listdir(path) if os.path.isdir(os.path.join(path, x))]
#self.seasons = [Season(self, os.path.join(path, x)) for x in os.listdir(path) if os.path.isdir(os.path.join(path, x))]
def __str__(self):
return self.name
@ -84,4 +87,4 @@ class Folder(object):
self.name = os.path.basename(self.directory)
def __str__(self):
return self.name + ' [' + self.directory + ']'
return self.name + ' [' + self.directory + ']'

View File

@ -16,45 +16,55 @@ class PigeonHole(object):
matches = None
def __init__(self, root, downloaddir):
print "Building pigeon hole with %s and %s" % (root, downloaddir)
self.structure = Structure(root)
self.downloadDir = downloaddir
self.rootShows = root
self.directories = os.listdir(self.rootShows)
self.series = list()
self.movedFiles = list()
def walk(self):
""" Walks through the downloaded folders and yields .avi and .mkv files """
for root, dirs, files in os.walk(self.downloadDir):
for filename in files:
if filename.endswith(config.shows_extensions):
yield Show(os.path.join(root, filename), filename)
yield Show(os.path.join(root, filename))
def walk2(self, foldername, extensions):
for root, dirs, files in os.walk(foldername):
for filename in files:
if not filename.endswith(extensions):
print "%s doesn't end with %s" % (filename, extensions)
yield os.path.join(root, filename)
def process(self):
""" Parses the directories within the 'rootShows' folder and stores them as shows in a list. """
self.series = [ Folder(os.path.join(self.rootShows, x)) for x in self.directories]
for show in self.series:
print show
for path in self.walk():
self.moveToFolder(path)
def moveToFolder(self, show):
""" Moves a specific show to its right folder. """
print "Trying to find %s" % (show)
destinationfile = self.findFolder(show)
if destinationfile is not None:
self.move(show.path, destinationfile)
self.movedFiles.append(destinationfile)
if self.isDeletable(show.directory):
print '\tDeleting ' + show.directory
shutil.rmtree(show.directory)
if self.isDeletable(show.directory()):
print '\tDeleting ' + show.directory()
shutil.rmtree(show.directory())
else:
for key in config.shows_dict:
@ -72,6 +82,7 @@ class PigeonHole(object):
for s in self.series:
if s.name.lower() in result:
print "Association found %s %s" % (s.directory, show.name)
return os.path.join(s.directory, show.name)
@ -85,7 +96,10 @@ class PigeonHole(object):
ie. .nfo, .srr or .sfv files.
"""
if foldername is None:
return False
return Show(os.path.join(root, filename))
print "Foldername value is %s" % (foldername)
if foldername == self.downloadDir or foldername == self.rootShows:
return False
@ -100,6 +114,12 @@ class PigeonHole(object):
return False
def getSubtitles(self):
import subprocess
for file in self.movedFiles:
### subliminal -l en The.Big.Bang.Theory.S05E18.HDTV.x264-LOL.mp4
subprocess.call(["subliminal", "-l", "fr", file])
def __str__(self):
return 'PigeonHole module'
@ -107,7 +127,8 @@ class PigeonHole(object):
return 'PigeonHole'
if __name__ == "__main__":
pHole = PigeonHole(r'C:\test', r'C:\temp')
pHole = PigeonHole(config.ROOT_FOLDER, config.DL_FOLDER)
pHole.process()
pHole.structure.writeUrls()
pHole.getSubtitles()
#pHole.structure.writeUrls()