]> Skullheadx's Git Forge - youtube-downloader.git/commitdiff
stuff
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 14 Oct 2024 01:48:57 +0000 (21:48 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 14 Oct 2024 01:48:57 +0000 (21:48 -0400)
dependencies.txt [deleted file]
requirements.txt [new file with mode: 0644]
thumbnail.jpg [new file with mode: 0644]
ytdl/funcmodule.py

diff --git a/dependencies.txt b/dependencies.txt
deleted file mode 100644 (file)
index 2fd322a..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-pytube
-ffmpeg-python
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..4b5e95b
--- /dev/null
@@ -0,0 +1,2 @@
+pytubefix~=8.0.0
+ffmpeg-python
diff --git a/thumbnail.jpg b/thumbnail.jpg
new file mode 100644 (file)
index 0000000..8f57b99
Binary files /dev/null and b/thumbnail.jpg differ
index 35b4cc33669fb823d5e00bf76e4434bbcb327256..856ed9a1cedf7a07e40f850639aafd36627e8000 100644 (file)
@@ -1,8 +1,9 @@
+import pytubefix.extract
+
 from .__init__ import *
-from pytube import YouTube, Playlist
-from pytube.exceptions import VideoUnavailable
+from pytubefix import YouTube, Playlist, extract
 import ffmpeg
-
+import requests
 
 
 def check_playlist(links):
@@ -14,29 +15,60 @@ def check_playlist(links):
             links.remove(link)
     return links
 
+
 def links_work(links):
     for link in links:
         YouTube(link).check_availability()
     return True
 
 
-def download_audio(links, target_abr="160kbps"):
-    print(links, ABR)
-    print('a')
+def get_audio_streams(links):
+    audio_streams = []
     for link in links:
         yt = YouTube(link)
-        # assert yt.includes_audio_track()
-        print(yt.streams.filter(only_audio=True))
-        print(yt.streams)
-
-
-
-
-
-
-
+        assert len(yt.streams.filter(only_audio=True)) > 0, "No available audio streams"
+        audio_streams.append(yt.streams.filter(only_audio=True).order_by("abr").last())
+    return audio_streams
 
 
+def get_metadata(links):
+    metadata = []
+    for link in links:
+        yt = YouTube(link)
+        metadata.append(
+            {
+                "title": yt.title,
+                "author": yt.author,
+                "thumbnail_url": yt.thumbnail_url,
+                "description": yt.description,
+                "publish_date": yt.publish_date,
+                "rating": yt.rating,
+                "views": yt.views
+            }
+        )
+    return metadata
+
+
+def download_audio_streams(audio_streams, metadata):
+    for audio_stream, md in zip(audio_streams, metadata):
+        audio_stream.download()
+        data = requests.get(md["thumbnail_url"]).content
+        f = open('thumbnail.jpg', 'wb')
+        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"]
@@ -52,7 +84,6 @@ def download_audio(links, target_abr="160kbps"):
 # print(links)
 
 
-
 #     # download links one by one
 #     for link in links:
 #         target_res = 0