Skip to content

Commit c30911f

Browse files
committed
2.5.019
1 parent 9af7820 commit c30911f

File tree

6 files changed

+35
-32
lines changed

6 files changed

+35
-32
lines changed

.github/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
9595
<details><summary>List all subcommands</summary>
9696

9797
$ library
98-
xk media library subcommands (v2.5.018)
98+
xk media library subcommands (v2.5.019)
9999

100100
Create database subcommands:
101101
╭───────────────┬────────────────────────────────────────────────────╮

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/tests/data/Youtube/
12
/TODO
23
/.ruff_cache/
34
/__pypackages__/

tests/test_dl.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
from argparse import Namespace
22

3-
from xklb.tube_backend import download
3+
from xklb.lb import library as lb
44
from xklb.tube_extract import tube_add
55
from xklb.utils.db_utils import connect
66

7-
PLAYLIST_URL = "https://youtube.com/playlist?list=PLVoczRgDnXDLWV1UJ_tO70VT_ON0tuEdm"
8-
PLAYLIST_VIDEO_URL = "https://www.youtube.com/watch?v=QoXubRvB6tQ"
7+
URL = "https://www.youtube.com/watch?v=BaW_jenozKc"
8+
# PLAYLIST_URL = "https://youtube.com/playlist?list=PLVoczRgDnXDLWV1UJ_tO70VT_ON0tuEdm"
9+
# PLAYLIST_VIDEO_URL = "https://www.youtube.com/watch?v=QoXubRvB6tQ"
910
STORAGE_PREFIX = "tests/data/"
1011

1112
dl_db = ["tests/data/dl.db"]
12-
tube_db = ["tests/data/tube_dl.db"]
1313
# tube_add([*dl_db, PLAYLIST_URL])
1414

1515

1616
def test_yt():
17-
tube_add([*dl_db, PLAYLIST_URL])
17+
tube_add([*dl_db, URL])
18+
lb(
19+
[
20+
"dl",
21+
*dl_db,
22+
"--video",
23+
f"--prefix={STORAGE_PREFIX}",
24+
"--no-write-thumbnail", # TODO: test that yt-dlp option is forwarded
25+
"--force",
26+
"--subs",
27+
"-s",
28+
URL,
29+
]
30+
)
1831

19-
args = Namespace(
20-
database=dl_db[0],
21-
profile="video",
22-
extractor_config={},
23-
prefix=STORAGE_PREFIX,
24-
ext=None,
25-
ignore_errors=False,
26-
small=False,
27-
verbose=0,
28-
download_archive="test",
29-
subtitle_languages=None,
30-
subs=False,
31-
auto_subs=False,
32-
unk=["--no-write-thumbnail"],
33-
) # remember to add args to dl_extract if they need to be added here
32+
args = Namespace(database=dl_db[0], verbose=0)
3433
args.db = connect(args)
35-
download(args, {"path": PLAYLIST_VIDEO_URL, "extractor_config": "{}"})
36-
# lb(['dl', *dl_db, '--video', f'--prefix={STORAGE_PREFIX}', "--no-write-thumbnail", '--download-archive=test', '--force'])
34+
35+
captions = list(args.db.query("select * from captions"))
36+
assert {"media_id": 2, "time": 3, "text": "For more information contact [email protected]"} in captions

xklb/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.5.018"
1+
__version__ = "2.5.019"

xklb/db_media.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def add(args, entry):
185185

186186
tags = entry.pop("tags", None) or ""
187187
chapters = entry.pop("chapters", None) or []
188-
entry.pop("subtitles", None)
188+
subtitles = entry.pop("subtitles", None) or []
189189
entry.pop("description", None)
190190

191191
media_id = args.db.pop("select id from media where path = ?", [entry["path"]])
@@ -205,6 +205,8 @@ def add(args, entry):
205205
args.db["captions"].insert({"media_id": media_id, "time": 0, "text": tags}, alter=True)
206206
for chapter in chapters:
207207
args.db["captions"].insert({"media_id": media_id, **chapter}, alter=True)
208+
if len(subtitles) > 0:
209+
args.db["captions"].insert_all([{**d, "media_id": media_id} for d in subtitles], alter=True)
208210

209211

210212
def playlist_media_add(
@@ -246,7 +248,8 @@ def download_add(
246248
delete_unplayable=False,
247249
check_corrupt=False,
248250
)
249-
fs_tags = objects.dict_filter_bool(fs_extract.extract_metadata(fs_args, local_path), keep_0=False) or {}
251+
fs_tags = fs_extract.extract_metadata(fs_args, local_path)
252+
fs_tags = objects.dict_filter_bool(fs_tags, keep_0=False) or {}
250253
fs_extract.clean_up_temp_dirs()
251254
else:
252255
fs_tags = {"time_modified": consts.now()}

xklb/tube_backend.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def out_dir(p):
343343
"ignoreerrors": ignoreerrors,
344344
"extractor_args": {"youtube": {"skip": ["authcheck"]}},
345345
"logger": DictLogger(),
346-
"skip_download": bool(consts.PYTEST_RUNNING),
346+
"skip_download": False,
347347
"postprocessors": [{"key": "FFmpegMetadata"}],
348348
"restrictfilenames": True,
349349
"extract_flat": False,
@@ -355,7 +355,7 @@ def out_dir(p):
355355
"retries": 12,
356356
"retry_sleep_functions": {
357357
"extractor": lambda n: 0.2 * n,
358-
"http": lambda n: 0.1 * (2**n),
358+
"http": lambda n: 0.08 * (2**n),
359359
"fragment": lambda n: 0.04 * (2**n),
360360
},
361361
"outtmpl": {
@@ -400,14 +400,13 @@ def yt_cli_to_api(opts):
400400
if args.small:
401401
if match_filter_user_config is None:
402402
match_filters.append("duration >? 59 & duration <? 14399")
403-
ydl_opts[
404-
"format"
405-
] = "bestvideo[height<=576][filesize<2G]+bestaudio/best[height<=576][filesize<2G]/bestvideo[height<=576]+bestaudio/best[height<=576]/best"
403+
ydl_opts["format_sort"] = ["res:576"]
404+
ydl_opts["format"] = "bestvideo[filesize<2G]+bestaudio/best[filesize<2G]/bestvideo*+bestaudio/best"
406405

407406
if args.profile == DBType.audio:
408407
ydl_opts[
409408
"format"
410-
] = "bestaudio[ext=opus]/bestaudio[ext=webm]/bestaudio[ext=ogg]/bestaudio[ext=oga]/bestaudio/best"
409+
] = "bestaudio[ext=opus]/bestaudio[ext=mka]/bestaudio[ext=webm]/bestaudio[ext=ogg]/bestaudio[ext=oga]/bestaudio/best"
411410
if args.ext is None:
412411
args.ext = "opus"
413412
ydl_opts["postprocessors"].append({"key": "FFmpegExtractAudio", "preferredcodec": args.ext})

0 commit comments

Comments
 (0)