Update run.py
Browse files
run.py
CHANGED
@@ -28,16 +28,55 @@ def downloader(video_url, audio_format, audio_name):
|
|
28 |
|
29 |
return final_output_path
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown("# YouTube Downloader 2.0")
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
download_button = gr.Button("Download")
|
41 |
download_button.click(downloader, inputs=[video_url, audio_format, audio_name], outputs=output)
|
|
|
|
|
|
|
42 |
|
43 |
demo.launch()
|
|
|
28 |
|
29 |
return final_output_path
|
30 |
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
changelog = """
|
35 |
+
### Changelog
|
36 |
+
|
37 |
+
#### v1.1.0 - 2024-05-16
|
38 |
+
|
39 |
+
##### Added
|
40 |
+
- **Directory Check**: Added a check to ensure the `audios` directory exists before attempting to save files to it.
|
41 |
+
- `os.makedirs('audios', exist_ok=True)`
|
42 |
+
|
43 |
+
##### Changed
|
44 |
+
- **Output Template Placeholder**: Updated `outtmpl` to use a temporary placeholder for the file extension.
|
45 |
+
- `outtmpl: f"audios/{audio_name}.%(ext)s"`
|
46 |
+
- **File Renaming**: Added logic to rename the temporary output file to the final desired name and extension.
|
47 |
+
- `temp_file = temp_output_path.replace('%(ext)s', audio_format)`
|
48 |
+
- `final_output_path = f"audios/{audio_name}.{audio_format}`
|
49 |
+
- `os.rename(temp_file, final_output_path)`
|
50 |
+
- **Return Correct Path**: The `downloader` function now returns the final output path to ensure Gradio can find and load the audio file correctly.
|
51 |
+
- `return final_output_path`
|
52 |
+
|
53 |
+
##### Fixed
|
54 |
+
- **File Not Found Error**: Resolved the issue where the file could not be found due to incorrect output path handling.
|
55 |
+
|
56 |
+
### Summary of Changes
|
57 |
+
|
58 |
+
1. **Ensured Directory Exists**: Added code to create the `audios` directory if it doesn't exist to prevent file saving errors.
|
59 |
+
2. **Output Path Handling**: Modified the output template to use a placeholder for the file extension, which yt-dlp will replace with the actual extension upon downloading.
|
60 |
+
3. **File Renaming Logic**: After downloading the audio, the code now renames the file to match the desired audio name and format.
|
61 |
+
4. **Correct File Path Return**: The correct file path is now returned from the `downloader` function, ensuring that the Gradio `gr.Audio` component can properly display and play the downloaded audio file.
|
62 |
+
|
63 |
+
These changes collectively ensure that the audio file is downloaded correctly, renamed appropriately, and made accessible to the Gradio interface for playback.
|
64 |
+
"""
|
65 |
+
|
66 |
+
|
67 |
with gr.Blocks() as demo:
|
68 |
gr.Markdown("# YouTube Downloader 2.0")
|
69 |
+
with gr.Row():
|
70 |
+
video_url = gr.Textbox(label="YouTube video link", default="https://youtu.be/yQBGdXGCUbA?si=7avvqH-6OOkGWqFm")
|
71 |
+
audio_name = gr.Textbox(label="Audio name of YouTube audio", default="killshot")
|
72 |
+
audio_format = gr.Radio(["wav", "flac", "mp3"], label="Select the output format", default=" wav")
|
73 |
+
with gr.Row():
|
74 |
+
output = gr.Audio(label="Output")
|
75 |
+
with gr.Row():
|
76 |
download_button = gr.Button("Download")
|
77 |
download_button.click(downloader, inputs=[video_url, audio_format, audio_name], outputs=output)
|
78 |
+
with gr.Group():
|
79 |
+
with gr.Row():
|
80 |
+
gr.Markdown(changelog)
|
81 |
|
82 |
demo.launch()
|