Flatten process_dir

This commit is contained in:
Labrys of Knossos 2019-01-06 11:09:11 -05:00
commit cb422a0cea

View file

@ -4,7 +4,7 @@ from __future__ import print_function, unicode_literals
import os
import beets
import beets.mediafile
import guessit
import requests
from six import text_type
@ -79,19 +79,7 @@ def clean_dir(path, section, subsection):
return clean_directory(path, files)
def process_dir(path, link):
folders = []
logger.info('Searching {0} for mediafiles to post-process ...'.format(path))
sync = [o for o in os.listdir(text_type(path)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
# 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(text_type(path)) if
os.path.isfile(os.path.join(path, o))]:
if len(sync) > 0:
break
if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']:
continue
try:
def move_file(mediafile, path, link):
logger.debug('Found file {0} in root directory {1}.'.format(os.path.split(mediafile)[1], path))
new_path = None
file_ext = os.path.splitext(mediafile)[1]
@ -144,6 +132,22 @@ def process_dir(path, link):
# link file to its new path
copy_link(mediafile, newfile, link)
def process_dir(path, link):
folders = []
logger.info('Searching {0} for mediafiles to post-process ...'.format(path))
sync = [o for o in os.listdir(text_type(path)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
# 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(text_type(path)) if
os.path.isfile(os.path.join(path, o))]:
if len(sync) > 0:
break
if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']:
continue
try:
move_file(mediafile, path, link)
except Exception as e:
logger.error('Failed to move {0} to its own directory: {1}'.format(os.path.split(mediafile)[1], e))