diff --git a/README.md b/README.md index af2ab4b..7655fc6 100644 --- a/README.md +++ b/README.md @@ -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 + - \ No newline at end of file diff --git a/rest_server.py b/rest_server.py index e4bded9..192f307 100644 --- a/rest_server.py +++ b/rest_server.py @@ -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() diff --git a/templates/success.html b/templates/success.html new file mode 100644 index 0000000..57d46dc --- /dev/null +++ b/templates/success.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block title %} Youtube 2 Podcast RSS {% endblock %} +{% block pageHeader %} Youtube 2 Podcast RSS {% endblock %} + + +{% block content %} +
Success
+Go To Podcast Page href +
+{% endblock %} + + + + diff --git a/yt2podcast/ytdl_handler.py b/yt2podcast/ytdl_handler.py new file mode 100644 index 0000000..3c7f948 --- /dev/null +++ b/yt2podcast/ytdl_handler.py @@ -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