|
|
|
|
@ -9,7 +9,6 @@ from .. import util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VIDEO_EXTENSIONS = ['.avi', '.m4v', '.mkv', '.mp4', '.mpg'] |
|
|
|
|
MAX_RECURSE_DEPTH = 5 |
|
|
|
|
bp = Blueprint('file_listing', __name__, url_prefix='/file_listing') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,8 +18,6 @@ class path_entry:
|
|
|
|
|
rel_path = '' # NOTE: fs path relative to config['MOVIE_DIR'] |
|
|
|
|
file_extension = '' |
|
|
|
|
is_dir = False |
|
|
|
|
depth = 0 |
|
|
|
|
contents = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/folder_contents/') |
|
|
|
|
@ -35,8 +32,7 @@ def getBaseFolderContents():
|
|
|
|
|
def getFolderJSON(subpath = ''): |
|
|
|
|
video_path = current_app.config['MOVIE_DIR'] |
|
|
|
|
full_path = os.path.join(video_path, subpath) |
|
|
|
|
errors = [] |
|
|
|
|
paths = [] |
|
|
|
|
errors, paths = [], [] |
|
|
|
|
|
|
|
|
|
current_app.logger.debug('video_path: {}'.format(video_path)) |
|
|
|
|
current_app.logger.debug('subpath: {}'.format(subpath)) |
|
|
|
|
@ -49,10 +45,7 @@ def getFolderJSON(subpath = ''):
|
|
|
|
|
errors.append('path is not a directory: {}'.format(full_path)) |
|
|
|
|
else: |
|
|
|
|
for entry in os.scandir(full_path): |
|
|
|
|
# TODO: remove 'getPathInfo()' when finished with async file listing |
|
|
|
|
# make sure to continue to test for '.' and symlinks |
|
|
|
|
# TODO: add errors to json, 'flash()' won't trigger on this function since it's async |
|
|
|
|
pe = getPathInfo(entry, MAX_RECURSE_DEPTH) |
|
|
|
|
pe = getPathInfo(entry) |
|
|
|
|
if pe: |
|
|
|
|
paths.append({ |
|
|
|
|
'base_name': pe.base_name, |
|
|
|
|
@ -64,14 +57,13 @@ def getFolderJSON(subpath = ''):
|
|
|
|
|
return jsonify(errors=errors, paths=paths) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPathInfo(entry, depth=0): |
|
|
|
|
def getPathInfo(entry): |
|
|
|
|
if not entry.name.startswith('.') and not entry.is_symlink(): |
|
|
|
|
video_path = current_app.config['MOVIE_DIR'] |
|
|
|
|
pe = path_entry() |
|
|
|
|
pe.base_name = entry.name |
|
|
|
|
pe.rel_path = re.sub(video_path, '', entry.path) |
|
|
|
|
pe.is_dir = entry.is_dir() |
|
|
|
|
pe.depth = depth |
|
|
|
|
|
|
|
|
|
if entry.is_file(): |
|
|
|
|
ext = os.path.splitext(entry)[1] |
|
|
|
|
@ -80,12 +72,5 @@ def getPathInfo(entry, depth=0):
|
|
|
|
|
pe.file_extension = ext |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
elif entry.is_dir() and depth < MAX_RECURSE_DEPTH: |
|
|
|
|
for e in os.scandir(entry): |
|
|
|
|
p = getPathInfo(e, depth + 1) |
|
|
|
|
if p: |
|
|
|
|
pe.contents.append(p) |
|
|
|
|
|
|
|
|
|
return pe |
|
|
|
|
|
|
|
|
|
return None |
|
|
|
|
|