aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-03-27 03:14:29 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-03-27 03:14:29 +0000
commit89dd61507c1f21f144bdce412db1633c6073aee5 (patch)
treec2cf9a2901156751e799b0eeec834014494415dd /src
parent35c99e438ad753afa258c1341f9db957a6037467 (diff)
downloadyouload-89dd61507c1f21f144bdce412db1633c6073aee5.tar.gz
youload-89dd61507c1f21f144bdce412db1633c6073aee5.tar.bz2
youload-89dd61507c1f21f144bdce412db1633c6073aee5.zip
Still trying to get this to work
Diffstat (limited to 'src')
-rw-r--r--src/util.py31
-rw-r--r--src/view/app.py16
-rw-r--r--src/youload_cli.py28
3 files changed, 12 insertions, 63 deletions
diff --git a/src/util.py b/src/util.py
index fd14e2e..7b012a2 100644
--- a/src/util.py
+++ b/src/util.py
@@ -1,6 +1,8 @@
import os
-import av
+import stat
+import ffmpeg
from kivy.utils import platform
+from kivy.app import App
def get_default_download_dir() -> str:
if platform == "android":
@@ -9,30 +11,5 @@ def get_default_download_dir() -> str:
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)
+ ffmpeg.input(input_file).output(output_file).run()
diff --git a/src/view/app.py b/src/view/app.py
index 4d4d400..c1b04e0 100644
--- a/src/view/app.py
+++ b/src/view/app.py
@@ -135,19 +135,19 @@ class YouloadApp(App):
self.download_status.text = "Download complete"
except FileExistsError as e:
self.download_status.text = "Folder already exists"
- self.downloads_display.text = repr(e)
- self.downloads_display.text += "\n" + traceback.format_exc()
+ self.downloads_display.text = repr(e) + "\n" + traceback.format_exc()
+ print(self.downloads_display.text)
except KeyError as e:
self.download_status.text = "Error getting playlist"
- self.downloads_display.text = repr(e)
- self.downloads_display.text += "\n" + traceback.format_exc()
+ self.downloads_display.text = repr(e) + "\n" + traceback.format_exc()
+ print(self.downloads_display.text)
except AttributeError as e:
self.download_status.text = "Download type not supported"
- self.downloads_display.text = repr(e)
- self.downloads_display.text += "\n" + traceback.format_exc()
+ self.downloads_display.text = repr(e) + "\n" + traceback.format_exc()
+ print(self.downloads_display.text)
except Exception as e:
- self.downloads_display.text = repr(e)
- self.downloads_display.text += "\n" + traceback.format_exc()
+ self.downloads_display.text = repr(e) + "\n" + traceback.format_exc()
+ print(self.downloads_display.text)
self.submit.text = "Download"
self.is_downloading = False
diff --git a/src/youload_cli.py b/src/youload_cli.py
deleted file mode 100644
index da14dc8..0000000
--- a/src/youload_cli.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from youload_playlist import YouLoadPlayList
-import sys
-
-def main() -> None:
- if len(sys.argv) <= 1:
- print("Needs the url")
- return
-
- # Get playlist
- try:
- playlist = YouLoadPlayList(sys.argv[1])
- except KeyError:
- print("Error getting playlist")
- return
-
- playlist.prepare_for_download()
-
- # Download each video.
- for i in range(playlist.video_count):
- print(f"Downloading {i+1}/{playlist.video_count}")
- print(playlist.download_video(i) + "\n")
-
- print("Download complete")
-
-
-if __name__ == "__main__":
- main()
-