From f27620092d16676b77e92ae409c15e71d246f025 Mon Sep 17 00:00:00 2001 From: Dylan Garrett Date: Sun, 6 Jun 2021 15:51:04 -0700 Subject: Allow setting scan dir from terminal --- lib/books.py | 6 +++--- roka.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/books.py b/lib/books.py index 1c4b4a5..84754f6 100644 --- a/lib/books.py +++ b/lib/books.py @@ -86,7 +86,7 @@ class Books: now = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S") print('%s %s' % (now, msg)) - def scan_books(self): + def scan_books(self, audiobook_path=None): ''' Discover audiobooks under :root_path: and populate books object @@ -94,7 +94,7 @@ class Books: (existing content is not re-hashed) ''' ex = self._get_path_hash_dict() - dirs = self._get_dirs(APP.config['ROOT_PATH']) + dirs = self._get_dirs(audiobook_path or APP.config['ROOT_PATH']) books = dict() for path in dirs: @@ -145,7 +145,7 @@ class Books: # previous conditions met, we've found at least one track is_book = True - self._log(f) + self._log(os.path.join(path, f)) # hash track (used as a key) and update folder hash file_hash = hashlib.md5() diff --git a/roka.py b/roka.py index aafc3a3..809cf3c 100755 --- a/roka.py +++ b/roka.py @@ -72,11 +72,11 @@ def my_render_template( app, ) -def generate(static_path, base_url): +def generate(static_path, base_url, audiobook_dirs): static_index_path = os.path.join(static_path, 'index.html') books = Books() - books.scan_books() + books.scan_books(audiobook_dirs) # TODO avoid writing and reading cache books.write_cache() books = read_cache(json_path) @@ -115,6 +115,9 @@ if __name__ == '__main__': parser.add_argument('--base_url', dest='base_url', type=str, action='store', help='Base URL to use in static files', required=False) + parser.add_argument('--scan_dir', dest='scan_dir', type=str, action='store', + help='Directory to scan for audiobooks', + required=False) args = parser.parse_args() if args.static_path and not args.base_url or args.base_url and not args.static_path: @@ -122,9 +125,9 @@ if __name__ == '__main__': if args.scan: books = Books() - books.scan_books() + books.scan_books(args.scan_dir) books.write_cache() elif args.static_path: - generate(args.static_path, args.base_url) + generate(args.static_path, args.base_url, args.scan_dir) else: app.run(host='127.0.0.1', port='8085', threaded=True) -- cgit v1.2.3-54-g00ecf