use ytdl library to download mp3
This commit is contained in:
parent
69ceb30c4e
commit
4ecce63c83
@ -19,3 +19,7 @@ https://youtubedl-material.stoplight.io/docs/youtubedl-material/YXBpOjE2NDIyMjY-
|
||||
## Update Docker Services
|
||||
- https://hub.docker.com/r/tzahi12345/youtubedl-material/tags
|
||||
- https://github.com/PodcastGenerator/PodcastGenerator/releases
|
||||
|
||||
ToDos:
|
||||
- introduce proper Logging
|
||||
-
|
@ -11,7 +11,8 @@ from werkzeug.security import check_password_hash
|
||||
# from werkzeug.utils import redirect
|
||||
|
||||
import config_parser
|
||||
from yt2podcast.ytdownloader import call_youtubedl
|
||||
# from yt2podcast.ytdownloader import call_youtubedl
|
||||
from yt2podcast.ytdl_handler import call_youtubedl
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
auth = HTTPBasicAuth()
|
||||
|
14
templates/success.html
Normal file
14
templates/success.html
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %} Youtube 2 Podcast RSS {% endblock %}
|
||||
{% block pageHeader %} Youtube 2 Podcast RSS {% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<p>Success</p>
|
||||
<p>Go To Podcast Page href
|
||||
<link href="https://podcasts.swaghausen.de/" /> </p>
|
||||
{% endblock %}
|
||||
|
||||
<!--{%for _ in range(10) %}-->
|
||||
<!-- <p>x</p>-->
|
||||
<!--{% endfor %}-->
|
39
yt2podcast/ytdl_handler.py
Normal file
39
yt2podcast/ytdl_handler.py
Normal file
@ -0,0 +1,39 @@
|
||||
import youtube_dl
|
||||
# from threading import Thread
|
||||
import threading
|
||||
|
||||
from flask import render_template
|
||||
|
||||
|
||||
def call_youtubedl(url):
|
||||
print(url)
|
||||
download_audio(url, "first_test")
|
||||
# thread = Thread(args=(, ))
|
||||
thread = threading.Thread(target=download_audio, args=(url, "first_test"), daemon=True)
|
||||
thread.start()
|
||||
thread.join()
|
||||
# data = "test"
|
||||
# return render_template('success.html', passed_data=data)
|
||||
|
||||
# print("thread finished...exiting")
|
||||
|
||||
def download_audio(url, name):
|
||||
ydl_opts = {
|
||||
'format': 'bestaudio/best',
|
||||
'outtmpl': f'/output/{name}.mp3', # Template for output names
|
||||
'noplaylist': True, # Download only the video, if the URL refers to a video and a playlist
|
||||
'continue_dl': True, # Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'mp3',
|
||||
'preferredquality': '192', }]
|
||||
}
|
||||
try:
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.cache.remove()
|
||||
info_dict = ydl.extract_info(url, download=False)
|
||||
ydl.prepare_filename(info_dict)
|
||||
ydl.download([url])
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
Loading…
x
Reference in New Issue
Block a user