This commit is contained in:
Marc Beninca 2025-03-16 01:01:52 +01:00
parent a167190d6c
commit 02cf8f83e7
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

142
rwx/sw/youtube/__init__.py Normal file
View file

@ -0,0 +1,142 @@
import yt_dlp
# playlists
# …
# entries
# playlists / entries
# title
# id
# playlist
# entries
# playlist / entries
# …
# videos
# id
# channel
# channel_id
# title
# channel_follower_count
# description
# tags
# thumbnails
# uploader_id
# uploader
# entries
# videos / entries
# id
# title
# description truncated
# duration
# thumbnails
# view_count
# video
# id
# title
# formats
# thumbnails
# thumbnail
# description
#
# duration
# view_count
# categories
# tags
# fulltitle
def extract_playlist(playlist_id):
options = {
"quiet": False,
"extract_flat": True,
"force_generic_extractor": False,
"ignoreerrors": False,
}
url = f"https://youtube.com/playlist?list={playlist_id}"
print(f"""\
{options}
{url}
""")
with yt_dlp.YoutubeDL(options) as y:
return y.extract_info(url, download=False)
def extract_playlists(channel_id):
options = {
"quiet": False,
"extract_flat": True,
"force_generic_extractor": False,
"ignoreerrors": False,
"skip_download": True,
}
url = f"https://youtube.com/channel/{channel_id}/playlists"
print(f"""\
{options}
{url}
""")
with yt_dlp.YoutubeDL(options) as y:
return y.extract_info(url, download=False)
def download_video(video_id):
options = {
"format": "bestvideo[ext=mp4]+bestaudio[ext=mp4]",
"outtmpl": "%(id)s.%(ext)s",
"writesubtitles": True,
"writethumbnail": True,
"ignoreerrors": False,
}
url = f"https://youtu.be/{video_id}"
print(f"""\
{options}
{url}
""")
with yt_dlp.YoutubeDL(options) as y:
return y.download([url])
def extract_video(video_id):
options = {
"quiet": False,
"ignoreerrors": False,
}
url = f"https://youtu.be/{video_id}"
print(f"""\
{options}
{url}
""")
with yt_dlp.YoutubeDL(options) as y:
return y.extract_info(url, download=False)
def extract_videos(channel_id):
options = {
"quiet": False,
"extract_flat": True,
"force_generic_extractor": False,
"ignoreerrors": False,
}
url = f"https://youtube.com/channel/{channel_id}/videos"
print(f"""\
{options}
{url}
""")
with yt_dlp.YoutubeDL(options) as y:
return y.extract_info(url, download=False)