aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-03-26 23:39:20 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-03-26 23:39:20 +0000
commit90e334f026130263125f640f89638cdb947b7ce2 (patch)
treee62a44f53586ffd9efba35885cd9e5d0cfb1d91f
parentce899d7f51975e6ac86d9350a9e90205f21914dd (diff)
downloadyouload-90e334f026130263125f640f89638cdb947b7ce2.tar.gz
youload-90e334f026130263125f640f89638cdb947b7ce2.tar.bz2
youload-90e334f026130263125f640f89638cdb947b7ce2.zip
Trying libav
-rw-r--r--buildozer.spec2
-rw-r--r--requirements.txt2
-rw-r--r--src/model/youload_playlist.py4
-rw-r--r--src/util.py29
4 files changed, 33 insertions, 4 deletions
diff --git a/buildozer.spec b/buildozer.spec
index 015b518..78466eb 100644
--- a/buildozer.spec
+++ b/buildozer.spec
@@ -37,7 +37,7 @@ version = 1.2
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
-requirements = python3,kivy,pytube,future,ffmpeg,ffmpeg-python
+requirements = python3,kivy,pytube,av
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
diff --git a/requirements.txt b/requirements.txt
index 8769e6d..b46cbf0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
kivy
pytube
-ffmpeg-python
+av
diff --git a/src/model/youload_playlist.py b/src/model/youload_playlist.py
index 1856c64..9189522 100644
--- a/src/model/youload_playlist.py
+++ b/src/model/youload_playlist.py
@@ -1,6 +1,6 @@
from pytube import Playlist
-import ffmpeg
import os
+import util
def make_alpha_numeric(string: str) -> str:
return "".join(char for char in string if char.isalnum())
@@ -54,7 +54,7 @@ class YouLoadPlayList:
# To mp3.
file_path_mp3 = file_path[:-4] + ".mp3"
- ffmpeg.input(file_path).output(file_path_mp3).run()
+ util.convert_mp4_to_mp3(file_path, file_path_mp3)
# Remove mp4 file.
os.remove(file_path)
diff --git a/src/util.py b/src/util.py
index 4b82c77..fd14e2e 100644
--- a/src/util.py
+++ b/src/util.py
@@ -1,4 +1,5 @@
import os
+import av
from kivy.utils import platform
def get_default_download_dir() -> str:
@@ -7,3 +8,31 @@ def get_default_download_dir() -> str:
else:
from pathlib import Path
return os.path.join(str(Path.home()), "Downloads")
+
+# Chatgpt code (:
+# I use av instead of ffmpeg so I can run it on android.
+def convert_mp4_to_mp3(input_file: str, output_file: str) -> None:
+ # Open the input video file
+ with av.open(input_file) as container:
+ # Find the audio stream
+ audio_stream = next(
+ (stream for stream in container.streams if stream.type == 'audio'),
+ None
+ )
+
+ if audio_stream is None:
+ raise ValueError("No audio stream found in the input file")
+
+ # Open an output file for writing
+ with av.open(output_file, 'w') as output_container:
+ # Create an audio stream in the output container
+ output_audio_stream = output_container.add_stream('mp3')
+
+ # Iterate through frames, decode audio, and encode into the output stream
+ for frame in container.decode(audio_stream):
+ # Encode the frame into the output stream
+ output_packet = output_audio_stream.encode(frame)
+
+ # Write the encoded packet to the output file
+ if output_packet:
+ output_container.mux(output_packet)