download,next
This commit is contained in:
parent
1f046e4ba9
commit
5b091397d2
1 changed files with 25 additions and 5 deletions
|
@ -15,6 +15,7 @@
|
|||
# …
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from rwx import Object
|
||||
from rwx.log import stream as log
|
||||
|
@ -64,7 +65,11 @@ class Tab(Object, ABC):
|
|||
|
||||
@staticmethod
|
||||
def yt_dl(opt: dict) -> YoutubeDL:
|
||||
options = {**opt, "ignoreerrors": False, "quiet": False}
|
||||
options = {
|
||||
**opt,
|
||||
"ignoreerrors": False,
|
||||
"quiet": False,
|
||||
}
|
||||
log.info(options)
|
||||
return YoutubeDL(options)
|
||||
|
||||
|
@ -95,9 +100,6 @@ class Video(Tab):
|
|||
self.categories = info["categories"]
|
||||
self.tags = info["tags"]
|
||||
self.description = info["description"]
|
||||
# TODO formats
|
||||
# TODO thumbnails
|
||||
# TODO thumbnail
|
||||
|
||||
def download(self) -> None:
|
||||
Tab.yt_dl(
|
||||
|
@ -132,7 +134,7 @@ class Videos(Tab):
|
|||
super().__init__(channel_id)
|
||||
info = self.extract()
|
||||
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 = {}
|
||||
|
||||
def get_url(self) -> str:
|
||||
|
@ -144,3 +146,21 @@ class Videos(Tab):
|
|||
self.videos[video_id] = Video(video_id)
|
||||
done += 1
|
||||
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}"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue