diff --git a/.github/README.md b/.github/README.md index 8d22a150..3dd80410 100644 --- a/.github/README.md +++ b/.github/README.md @@ -97,7 +97,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
List all subcommands $ library - library (v2.9.021; 82 subcommands) + library (v2.9.022; 82 subcommands) Create database subcommands: ╭─────────────────┬──────────────────────────────────────────╮ diff --git a/tests/folders/test_rel_mv.py b/tests/folders/test_rel_mv.py index 954b37af..41dfaa81 100644 --- a/tests/folders/test_rel_mv.py +++ b/tests/folders/test_rel_mv.py @@ -4,8 +4,8 @@ from pyfakefs.fake_filesystem import OSType from tests.conftest import generate_file_tree_dict -from xklb.folders.rel_mv import gen_rel_path, relative_from_path, shortest_relative_from_path from xklb.__main__ import library as lb +from xklb.folders.rel_mv import gen_rel_path, relative_from_path, shortest_relative_from_path simple_file_tree = { "folder1": {"file1.txt": "1", "subfolder1": {"file2.txt": "2"}}, diff --git a/tests/mediadb/test_download.py b/tests/mediadb/test_download.py index df511d58..75ece014 100644 --- a/tests/mediadb/test_download.py +++ b/tests/mediadb/test_download.py @@ -3,8 +3,8 @@ import pytest from tests.utils import connect_db_args -from xklb.createdb.tube_add import tube_add from xklb.__main__ import library as lb +from xklb.createdb.tube_add import tube_add from xklb.utils import consts URL = "https://www.youtube.com/watch?v=BaW_jenozKc" diff --git a/tests/mediadb/test_live.py b/tests/mediadb/test_live.py index 5dbe24e1..52394e79 100644 --- a/tests/mediadb/test_live.py +++ b/tests/mediadb/test_live.py @@ -2,8 +2,8 @@ from unittest import skip from tests.utils import connect_db_args -from xklb.createdb.tube_add import tube_add from xklb.__main__ import library as lb +from xklb.createdb.tube_add import tube_add URL = "https://www.youtube.com/watch?v=W5ZLFBZkE34" STORAGE_PREFIX = "tests/data" diff --git a/tests/playback/test_media_player.py b/tests/playback/test_media_player.py index 30ecb438..59621916 100644 --- a/tests/playback/test_media_player.py +++ b/tests/playback/test_media_player.py @@ -7,8 +7,8 @@ from tests import utils from tests.utils import connect_db_args, v_db -from xklb.createdb.fs_add import fs_add from xklb.__main__ import library as lb +from xklb.createdb.fs_add import fs_add from xklb.mediadb import db_history, db_media from xklb.playback.media_player import MediaPrefetcher from xklb.utils import consts diff --git a/xklb/__init__.py b/xklb/__init__.py index 2ac626a7..7ec5399a 100644 --- a/xklb/__init__.py +++ b/xklb/__init__.py @@ -1,5 +1,3 @@ -__version__ = "2.9.021" - import xklb.__main__ if __name__ == "__main__": diff --git a/xklb/__main__.py b/xklb/__main__.py index 0aef540d..db3641e0 100644 --- a/xklb/__main__.py +++ b/xklb/__main__.py @@ -1,12 +1,12 @@ -import os -import argparse, importlib, sys, textwrap +import argparse, importlib, os, sys, textwrap from tabulate import tabulate -from xklb import __version__ from xklb.utils import argparse_utils, iterables from xklb.utils.log_utils import log +__version__ = "2.9.022" + progs = { "Create database subcommands": { "fs_add": "Add local media", diff --git a/xklb/lb.py b/xklb/lb.py index f7a58bb7..46e6b215 100644 --- a/xklb/lb.py +++ b/xklb/lb.py @@ -1,3 +1,4 @@ if __name__ == "__main__": import xklb.__main__ + xklb.__main__.library() diff --git a/xklb/mediadb/db_media.py b/xklb/mediadb/db_media.py index 0b234039..3951535a 100644 --- a/xklb/mediadb/db_media.py +++ b/xklb/mediadb/db_media.py @@ -349,6 +349,7 @@ def download_add( with args.db.conn: args.db.conn.execute("DELETE from media WHERE path = ?", [webpath]) + def natsort_media(args, media): from natsort import natsorted, ns, os_sorted diff --git a/xklb/mediadb/download.py b/xklb/mediadb/download.py index 0c3a9753..44bc9f5c 100644 --- a/xklb/mediadb/download.py +++ b/xklb/mediadb/download.py @@ -72,7 +72,6 @@ def parse_args(): return args - def download(args=None) -> None: if args: sys.argv = ["lb", *args] diff --git a/xklb/mediadb/download_status.py b/xklb/mediadb/download_status.py index 7101932f..fb935d25 100644 --- a/xklb/mediadb/download_status.py +++ b/xklb/mediadb/download_status.py @@ -36,39 +36,39 @@ def download_status() -> None: extractor_stats = defaultdict( lambda: { - 'retry_queued': 0, - 'never_attempted': 0, - 'downloaded_recently': 0, - 'failed_recently': 0, - 'retries_exceeded': 0, + "retry_queued": 0, + "never_attempted": 0, + "downloaded_recently": 0, + "failed_recently": 0, + "retries_exceeded": 0, } ) retry_delay = nums.human_to_seconds(args.retry_delay) for m in media: - extractor_key = m.get('extractor_key', 'Playlist-less media') + extractor_key = m.get("extractor_key", "Playlist-less media") - if 'download_attempts' in m and m['download_attempts'] > args.download_retries: - extractor_stats[extractor_key]['retries_exceeded'] += 1 - elif (m.get('time_downloaded') or 0) > 0 or ( - not m['path'].startswith('http') and m['webpath'].startswith('http') + if "download_attempts" in m and m["download_attempts"] > args.download_retries: + extractor_stats[extractor_key]["retries_exceeded"] += 1 + elif (m.get("time_downloaded") or 0) > 0 or ( + not m["path"].startswith("http") and m["webpath"].startswith("http") ): - if (m['time_downloaded'] + retry_delay) >= consts.APPLICATION_START: - extractor_stats[extractor_key]['downloaded_recently'] += 1 - elif m['path'].startswith('http'): - if 'time_modified' in m: - if m['time_modified'] > 0 and (m['time_modified'] + retry_delay) < consts.APPLICATION_START: - extractor_stats[extractor_key]['retry_queued'] += 1 - elif m['time_modified'] > 0 and (m['time_modified'] + retry_delay) >= consts.APPLICATION_START: - extractor_stats[extractor_key]['failed_recently'] += 1 + if (m["time_downloaded"] + retry_delay) >= consts.APPLICATION_START: + extractor_stats[extractor_key]["downloaded_recently"] += 1 + elif m["path"].startswith("http"): + if "time_modified" in m: + if m["time_modified"] > 0 and (m["time_modified"] + retry_delay) < consts.APPLICATION_START: + extractor_stats[extractor_key]["retry_queued"] += 1 + elif m["time_modified"] > 0 and (m["time_modified"] + retry_delay) >= consts.APPLICATION_START: + extractor_stats[extractor_key]["failed_recently"] += 1 else: # time_modified == 0 - extractor_stats[extractor_key]['never_attempted'] += 1 + extractor_stats[extractor_key]["never_attempted"] += 1 else: - extractor_stats[extractor_key]['never_attempted'] += 1 + extractor_stats[extractor_key]["never_attempted"] += 1 - media = [{'extractor_key': extractor_key, **d} for extractor_key, d in extractor_stats.items()] - media = sorted(media, key=lambda x: (-x['never_attempted'], -x['retry_queued'], x['extractor_key'])) + media = [{"extractor_key": extractor_key, **d} for extractor_key, d in extractor_stats.items()] + media = sorted(media, key=lambda x: (-x["never_attempted"], -x["retry_queued"], x["extractor_key"])) media_printer.media_printer(args, media, units="extractors")