From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Mon, 14 Oct 2024 02:34:55 +0000 (-0400) Subject: it works now X-Git-Url: http://git.skullheadx.com/tech/openbsd_html_css/static/gitweb.css?a=commitdiff_plain;h=6d1ae576d8c62ff4dbfe4001dc857457e5f817cb;p=youtube-downloader.git it works now --- diff --git a/thumbnail.jpg b/thumbnail.jpg deleted file mode 100644 index 8f57b99..0000000 Binary files a/thumbnail.jpg and /dev/null differ diff --git a/ytdl/__init__.py b/ytdl/__init__.py index ea9ae9e..8b13789 100644 --- a/ytdl/__init__.py +++ b/ytdl/__init__.py @@ -1,4 +1 @@ -modes = ["-d", "-a", "-v", "-av"] - -ABR = ["160kbps", "128kbps", "70kbps", "50kbps", "48kbps"] diff --git a/ytdl/classmodule.py b/ytdl/classmodule.py deleted file mode 100644 index 31fea4f..0000000 --- a/ytdl/classmodule.py +++ /dev/null @@ -1,6 +0,0 @@ -class MyClass(): - def __init__(self, name): - self.name = name - - def say_name(self): - print('name is {}'.format(self.name)) diff --git a/ytdl/funcmodule.py b/ytdl/funcmodule.py index 856ed9a..0720edd 100644 --- a/ytdl/funcmodule.py +++ b/ytdl/funcmodule.py @@ -1,10 +1,8 @@ -import pytubefix.extract - -from .__init__ import * from pytubefix import YouTube, Playlist, extract import ffmpeg import requests - +import subprocess +import os def check_playlist(links): for link in links: @@ -38,9 +36,8 @@ def get_metadata(links): metadata.append( { "title": yt.title, - "author": yt.author, + "artist": yt.author, "thumbnail_url": yt.thumbnail_url, - "description": yt.description, "publish_date": yt.publish_date, "rating": yt.rating, "views": yt.views @@ -57,87 +54,22 @@ def download_audio_streams(audio_streams, metadata): f.write(data) f.close() - audio = ffmpeg.input(audio_stream.default_filename) - thumb = ffmpeg.input("thumbnail.jpg") - ( - ffmpeg - .output( - audio, thumb, - audio_stream.title + ".mp4", - author=md["author"], year=md["publish_date"], description=md["description"] - ) - .overwrite_output() - .run() - ) - -# RES = ["1440p", "1080p", "720p", "480p", "360p", "240p", "144p"] -# ABR = ["160kbps", "128kbps", "70kbps", "50kbps", "48kbps"] -# target_res = 0 -# target_abr=0 - -# get list of links from file -# links = [] -# with open('links.txt', 'r') as f: -# links = f.read().split('\n') -# if links[-1] == "": -# links = links[:-1] -# print(links) - - -# # download links one by one -# for link in links: -# target_res = 0 -# target_abr = 0 -# video_success = True -# audio_success = True - -# try: -# yt = YouTube(link) -# yt.streams - -# except VideoUnavailable: -# print(f'Video {link} is unavaialable, skipping.') -# failed_download.add(((yt.title, link))) -# else: -# video_streams = [] -# while len(video_streams) == 0: -# video_streams = yt.streams.filter(file_extension='mp4', res=RES[target_res]) # find available streams -# if target_res + 1 < len(RES): -# target_res = target_res + 1 -# else: -# video_success = False -# break -# if not video_success: -# print(f"Unable to find video stream for {yt.title}") -# failed_download.add(((yt.title, link))) - -# break -# vstream = video_streams[0] - -# # audio -# audio_streams = [] -# while len(audio_streams) == 0: -# audio_streams = yt.streams.filter(only_audio=True, abr=ABR[target_abr]) # find available streams - -# if target_abr + 1 < len(RES): -# target_abr = target_abr + 1 -# else: -# audio_success = False -# break -# if not audio_success: -# print(f"Unable to find audio stream for {yt.title}") -# failed_download.add(((yt.title, link))) - -# break -# astream = audio_streams[0] - -# vstream.download(output_path="downloaded/video_only") -# astream.download(output_path="downloaded/audio_only") - -# input_video = ffmpeg.input(f"downloaded/video_only/{vstream.default_filename}") -# input_audio = ffmpeg.input(f"downloaded/audio_only/{astream.default_filename}") + command = [ + 'ffmpeg', + '-i', audio_stream.default_filename, + '-i', "thumbnail.jpg", + '-map', '0', + '-map', '1', + '-metadata', f'title={audio_stream.title}', + '-metadata', f'artist={md["artist"]}', + '-metadata', f'date={md["publish_date"]}', + "downloads/" + audio_stream.title + ".mp4", + '-y' + ] + if "downloads" not in [i.name for i in os.scandir()]: + os.mkdir("downloads") + subprocess.run(command) + os.remove("thumbnail.jpg") + os.remove(audio_stream.default_filename) -# ffmpeg.concat(input_video, input_audio, v=1, a=1).output(f'downloaded/{yt.title}.mp4').run() -# print("Failed Downloading:") -# print(failed_download)