mirror of
https://github.com/jlengrand/tldw.git
synced 2026-03-10 08:51:17 +00:00
Playlists are now checked for
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
import sys
|
import sys
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
|
||||||
def get_playlist_videos(playlist_url):
|
def get_playlist_videos(playlist_url):
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'extract_flat': True,
|
'extract_flat': True, 'skip_download': True,
|
||||||
'skip_download': True,
|
'quiet': False
|
||||||
'quiet': True
|
|
||||||
}
|
}
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
try:
|
||||||
info = ydl.extract_info(playlist_url, download=False)
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
info = ydl.extract_info(playlist_url, download=False)
|
||||||
|
|
||||||
if 'entries' in info:
|
if 'entries' in info:
|
||||||
video_urls = [entry['url'] for entry in info['entries']]
|
video_urls = [entry['url'] for entry in info['entries']]
|
||||||
@@ -18,19 +19,39 @@ def get_playlist_videos(playlist_url):
|
|||||||
else:
|
else:
|
||||||
print("No videos found in the playlist.")
|
print("No videos found in the playlist.")
|
||||||
return [], None
|
return [], None
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
return [], None
|
||||||
|
|
||||||
|
|
||||||
def save_to_file(video_urls, filename):
|
def save_to_file(video_urls, filename):
|
||||||
with open(filename, 'w') as file:
|
with open(filename, 'w') as file:
|
||||||
file.write('\n'.join(video_urls))
|
file.write('\n'.join(video_urls))
|
||||||
print(f"Video URLs saved to {filename}")
|
print(f"Video URLs saved to {filename}")
|
||||||
|
|
||||||
|
|
||||||
|
def parse_playlist_url(url):
|
||||||
|
parsed_url = urlparse(url)
|
||||||
|
query_params = parse_qs(parsed_url.query)
|
||||||
|
|
||||||
|
if 'list' in query_params:
|
||||||
|
playlist_id = query_params['list'][0]
|
||||||
|
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}"
|
||||||
|
playlist_url = f"{base_url}?list={playlist_id}"
|
||||||
|
return playlist_url
|
||||||
|
else:
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Please provide the playlist URL as a command-line argument.")
|
print("Please provide the playlist URL as a command-line argument.")
|
||||||
|
print("""Example:\n\t python Get_Playlist_URLs.py "https://www.youtube.com/playlist?list=PLH15HpR5qRsWalnnt-9eYELxbEcYBPB6I" """)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
playlist_url = sys.argv[1]
|
playlist_url = sys.argv[1]
|
||||||
video_urls, playlist_title = get_playlist_videos(playlist_url)
|
parsed_playlist_url = parse_playlist_url(playlist_url)
|
||||||
|
video_urls, playlist_title = get_playlist_videos(parsed_playlist_url)
|
||||||
|
|
||||||
if video_urls:
|
if video_urls:
|
||||||
filename = f"{playlist_title}.txt"
|
filename = f"{playlist_title}.txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user