download,next

This commit is contained in:
Marc Beninca 2025-03-17 14:53:47 +01:00
parent 1f046e4ba9
commit 5b091397d2
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -15,6 +15,7 @@
# … # …
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any from typing import Any
from rwx import Object from rwx import Object
from rwx.log import stream as log from rwx.log import stream as log
@ -64,7 +65,11 @@ class Tab(Object, ABC):
@staticmethod @staticmethod
def yt_dl(opt: dict) -> YoutubeDL: def yt_dl(opt: dict) -> YoutubeDL:
options = {**opt, "ignoreerrors": False, "quiet": False} options = {
**opt,
"ignoreerrors": False,
"quiet": False,
}
log.info(options) log.info(options)
return YoutubeDL(options) return YoutubeDL(options)
@ -95,9 +100,6 @@ class Video(Tab):
self.categories = info["categories"] self.categories = info["categories"]
self.tags = info["tags"] self.tags = info["tags"]
self.description = info["description"] self.description = info["description"]
# TODO formats
# TODO thumbnails
# TODO thumbnail
def download(self) -> None: def download(self) -> None:
Tab.yt_dl( Tab.yt_dl(
@ -132,7 +134,7 @@ class Videos(Tab):
super().__init__(channel_id) super().__init__(channel_id)
info = self.extract() info = self.extract()
self.title = info["title"] self.title = info["title"]
self.ids = [v["id"] for v in info["entries"]] self.ids = [v["id"] for v in reversed(info["entries"])]
self.videos = {} self.videos = {}
def get_url(self) -> str: def get_url(self) -> str:
@ -144,3 +146,21 @@ class Videos(Tab):
self.videos[video_id] = Video(video_id) self.videos[video_id] = Video(video_id)
done += 1 done += 1
log.info(done) log.info(done)
def next(self) -> str | None:
for video_id in self.ids:
if not Path(f"{video_id}.mp4").exists():
return video_id
return None
def download(video_id: str | None) -> None:
if video_id:
Tab.yt_dl(
{
"format": "bestvideo[ext=mp4]+bestaudio[ext=mp4]",
"outtmpl": "%(id)s.%(ext)s",
"writesubtitles": True,
"writethumbnail": True,
}
).download([f"{Tab.URL_ROOT}/watch?v={video_id}"])