From 9b02be1ebdaeccdef9150a7ec897bdfb99662eee Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sat, 21 Sep 2019 11:03:25 -0400 Subject: [PATCH] add indication if path is stored in db --- video_metadata/static/file_listing.js | 5 ++++- video_metadata/static/style.css | 1 + video_metadata/views/file_listing.py | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/video_metadata/static/file_listing.js b/video_metadata/static/file_listing.js index 20eca89..10fe9a5 100644 --- a/video_metadata/static/file_listing.js +++ b/video_metadata/static/file_listing.js @@ -17,7 +17,10 @@ function addContents(node, json) { if (json.is_dir) a.classList.add('folder'); else - a.classList.add('file'); + if (json.in_db) + a.classList.add('file_stored'); + else + a.classList.add('file'); a.appendChild(document.createTextNode(json.base_name)); li.appendChild(a); diff --git a/video_metadata/static/style.css b/video_metadata/static/style.css index ef15c0b..7e4cd28 100644 --- a/video_metadata/static/style.css +++ b/video_metadata/static/style.css @@ -25,3 +25,4 @@ input.danger { color: #cc2f2e; } .content li { list-style: ' - '; } .folder { background: lightblue; } .file { background: orange; } +.file_stored { background: lightgreen; } diff --git a/video_metadata/views/file_listing.py b/video_metadata/views/file_listing.py index b84085a..24b65be 100644 --- a/video_metadata/views/file_listing.py +++ b/video_metadata/views/file_listing.py @@ -5,7 +5,7 @@ import re from flask import Blueprint, current_app, escape, flash, render_template from flask import jsonify -from .. import util +from .. import db, util VIDEO_EXTENSIONS = ['.avi', '.m4v', '.mkv', '.mp4', '.mpg'] @@ -18,6 +18,7 @@ class path_entry: rel_path = '' # NOTE: fs path relative to config['MOVIE_DIR'] file_extension = '' is_dir = False + in_db = False @bp.route('/folder_contents/') @@ -52,6 +53,7 @@ def getFolderJSON(subpath = ''): 'rel_path': pe.rel_path, 'file_extension': pe.file_extension, 'is_dir': pe.is_dir, + 'in_db': pe.in_db, }) return jsonify(errors=errors, paths=paths) @@ -70,7 +72,14 @@ def getPathInfo(entry): if ext in VIDEO_EXTENSIONS: pe.file_extension = ext + # check if the path is already stored in db + cur = db.get_db().cursor() + cur.execute('SELECT COUNT(*) FROM movie_paths WHERE movie_path = ?', + (pe.rel_path, ) + ) + pe.in_db = cur.fetchone()[0] > 0 else: return None return pe return None +