Skip to content

Commit

Permalink
2.9.022
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Aug 12, 2024
1 parent c359e54 commit 1dcc282
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
<details><summary>List all subcommands</summary>

$ library
library (v2.9.021; 82 subcommands)
library (v2.9.022; 82 subcommands)

Create database subcommands:
╭─────────────────┬──────────────────────────────────────────╮
Expand Down
2 changes: 1 addition & 1 deletion tests/folders/test_rel_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
2 changes: 1 addition & 1 deletion tests/mediadb/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/mediadb/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/playback/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions xklb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__version__ = "2.9.021"

import xklb.__main__

if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions xklb/__main__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions xklb/lb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if __name__ == "__main__":
import xklb.__main__

xklb.__main__.library()
1 change: 1 addition & 0 deletions xklb/mediadb/db_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion xklb/mediadb/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def parse_args():
return args



def download(args=None) -> None:
if args:
sys.argv = ["lb", *args]
Expand Down
44 changes: 22 additions & 22 deletions xklb/mediadb/download_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 1dcc282

Please sign in to comment.