]> Skullheadx's Git Forge - youtube-downloader.git/commitdiff
it works now
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 14 Oct 2024 02:34:55 +0000 (22:34 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 14 Oct 2024 02:34:55 +0000 (22:34 -0400)
thumbnail.jpg [deleted file]
ytdl/__init__.py
ytdl/classmodule.py [deleted file]
ytdl/funcmodule.py

diff --git a/thumbnail.jpg b/thumbnail.jpg
deleted file mode 100644 (file)
index 8f57b99..0000000
Binary files a/thumbnail.jpg and /dev/null differ
index ea9ae9e8e607b48cab640009c848e0a232d1d78f..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -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 (file)
index 31fea4f..0000000
+++ /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))
index 856ed9a1cedf7a07e40f850639aafd36627e8000..0720edd58e01c3e6ac76970fd19da1d8f34ffc34 100644 (file)
@@ -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)