mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Manual run handles non utf-8 characters.
This commit is contained in:
parent
0268718074
commit
0aac86548a
1 changed files with 38 additions and 36 deletions
|
@ -483,52 +483,54 @@ def getDirs(section, subsection):
|
||||||
# search for single files and move them into their own folder for post-processing
|
# search for single files and move them into their own folder for post-processing
|
||||||
for mediafile in [ os.path.join(path, o) for o in os.listdir(path) if
|
for mediafile in [ os.path.join(path, o) for o in os.listdir(path) if
|
||||||
os.path.isfile(os.path.join(path, o)) ]:
|
os.path.isfile(os.path.join(path, o)) ]:
|
||||||
logger.debug("Found file %s in root directory %s." % (mediafile, path))
|
|
||||||
newPath = None
|
|
||||||
fileExt = os.path.splitext(os.path.basename(mediafile))[1]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if fileExt in nzbtomedia.AUDIOCONTAINER:
|
logger.debug("Found file %s in root directory %s." % (sanitizeName(os.path.split(mediafile)[1]), path))
|
||||||
f = beets.mediafile.MediaFile(mediafile)
|
newPath = None
|
||||||
|
fileExt = os.path.splitext(os.path.basename(mediafile))[1]
|
||||||
|
try:
|
||||||
|
if fileExt in nzbtomedia.AUDIOCONTAINER:
|
||||||
|
f = beets.mediafile.MediaFile(mediafile)
|
||||||
|
|
||||||
# get artist and album info
|
# get artist and album info
|
||||||
artist = f.artist
|
artist = f.artist
|
||||||
album = f.album
|
album = f.album
|
||||||
|
|
||||||
# create new path
|
# create new path
|
||||||
newPath = os.path.join(path, "%s - %s" % (sanitizeName(artist), sanitizeName(album)))
|
newPath = os.path.join(path, "%s - %s" % (sanitizeName(artist), sanitizeName(album)))
|
||||||
elif fileExt in nzbtomedia.MEDIACONTAINER:
|
elif fileExt in nzbtomedia.MEDIACONTAINER:
|
||||||
f = guessit.guess_video_info(mediafile)
|
f = guessit.guess_video_info(mediafile)
|
||||||
|
|
||||||
# get title
|
# get title
|
||||||
title = None
|
title = None
|
||||||
try:
|
try:
|
||||||
title = f['series']
|
title = f['series']
|
||||||
except:
|
except:
|
||||||
title = f['title']
|
title = f['title']
|
||||||
|
|
||||||
if not title:
|
if not title:
|
||||||
title = os.path.splitext(os.path.basename(mediafile))[0]
|
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||||
|
|
||||||
|
newPath = os.path.join(path, sanitizeName(title))
|
||||||
|
except Exception, e:
|
||||||
|
logger.error("Exception parsing name for media file: %s: %s" % (sanitizeName(os.path.split(mediafile)[1]), e))
|
||||||
|
|
||||||
|
if not newPath:
|
||||||
|
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||||
newPath = os.path.join(path, sanitizeName(title))
|
newPath = os.path.join(path, sanitizeName(title))
|
||||||
except Exception, e:
|
|
||||||
logger.error("Exception parsing name for media file: %s: %s" % (mediafile, e))
|
|
||||||
|
|
||||||
if not newPath:
|
# Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe).
|
||||||
title = os.path.splitext(os.path.basename(mediafile))[0]
|
if os.path.isfile(newPath):
|
||||||
newPath = os.path.join(path, sanitizeName(title))
|
newPath2 = os.path.join(os.path.join(os.path.split(newPath)[0], 'new'), os.path.split(newPath)[1])
|
||||||
|
newPath = newPath2
|
||||||
|
|
||||||
# Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe).
|
# create new path if it does not exist
|
||||||
if os.path.isfile(newPath):
|
if not os.path.exists(newPath):
|
||||||
newPath2 = os.path.join(os.path.join(os.path.split(newPath)[0], 'new'), os.path.split(newPath)[1])
|
makeDir(newPath)
|
||||||
newPath = newPath2
|
|
||||||
|
|
||||||
# create new path if it does not exist
|
# move file to its new path
|
||||||
if not os.path.exists(newPath):
|
copy_link(mediafile, os.path.join(newPath, os.path.split(mediafile)[1]), 'hard')
|
||||||
makeDir(newPath)
|
except:
|
||||||
|
logger.error("Failed to move %s to its own directory" % (sanitizeName(os.path.split(mediafile)[1])))
|
||||||
# move file to its new path
|
|
||||||
copy_link(mediafile, os.path.join(newPath, os.path.split(mediafile)[1]), 'hard')
|
|
||||||
|
|
||||||
removeEmptyFolders(path, removeRoot=False)
|
removeEmptyFolders(path, removeRoot=False)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue