download video as attachment

This commit is contained in:
deflax 2024-01-19 00:43:51 +02:00
parent 87fa946046
commit da6fd931c1
2 changed files with 29 additions and 18 deletions

View file

@ -143,22 +143,23 @@ async def query_database():
thumb_filename = rechead['thumb']
# Reset the rechead
rechead = {}
await live_channel.send('Live stream is now offline.')
# Creating an embed
video_url = f'https://{scheduler_hostname}/video/{video_filename}'
thumb_url = f'https://{scheduler_hostname}/thumb/{thumb_filename}'
video_filename_no_extension = video_filename.split('.')[0]
watch_url = f'https://{scheduler_hostname}/watch/{video_filename_no_extension}'
img_url = f'https://{scheduler_hostname}/img'
thumb_url = f'https://{scheduler_hostname}/thumb/{thumb_filename}'
video_download_url = f'https://{scheduler_hostname}/video/{video_filename}'
video_filename_no_extension = video_filename.split('.')[0]
video_watch_url = f'https://{scheduler_hostname}/video/watch/{video_filename_no_extension}'
embed = discord.Embed(title=f'{rec_stream_name}',
url=f'{watch_url}',
colour=0x00b0f4,
timestamp=datetime.now())
embed.add_field(name="Download",
value=f"[{video_filename}]({video_url})",
value=f"[{video_filename}]({video_download_url})",
inline=True)
embed.add_field(name="Watch",
value=f'[plyr.js]({watch_url})',
value=f'[plyr.js]({video_watch_url})',
inline=True)
embed.set_image(url=thumb_url)
embed.set_thumbnail(url=f'{img_url}/logo-96.png')
@ -166,7 +167,7 @@ async def query_database():
icon_url=f'{img_url}/logo-96.png')
# Sending the embed to the channel
await live_channel.send(embed=embed)
logger_discord.info(f'{rec_stream_name} is now offline. VOD: {video_filename}')
logger_discord.info(f'{rec_stream_name} is now offline. VOD: {video_filename_no_extension}')
else:
logger_discord.info('Live stream is now offline.')

View file

@ -292,9 +292,10 @@ scheduler.start()
# Flask API
@app.route('/', methods=['GET'])
def root_route():
about_json = { 'about': 'deflax tv api' }
about_json = { 'about': 'DeflaxTV API' }
return jsonify(about_json)
# JSON data
@app.route('/playhead', methods=['GET'])
def playhead_route():
global playhead
@ -310,12 +311,13 @@ def database_route():
global database
return jsonify(database)
@app.route("/video/<file_name>", methods=['GET'])
def video_route(file_name):
reqfile = f'{rec_path}/vod/{file_name}'
# Images
@app.route("/img/<file_name>", methods=['GET'])
def img_route(file_name):
reqfile = f'./img/{file_name}'
if not os.path.exists(reqfile):
abort(404)
return send_file(reqfile, mimetype='video/mp4')
return send_file(reqfile, mimetype='image/png')
@app.route("/thumb/<file_name>", methods=['GET'])
def thumb_route(file_name):
@ -324,15 +326,23 @@ def thumb_route(file_name):
abort(404)
return send_file(reqfile, mimetype='image/png')
@app.route("/img/<file_name>", methods=['GET'])
def img_route(file_name):
reqfile = f'./img/{file_name}'
# Video
@app.route("/video/<file_name>", methods=['GET'])
def video_route(file_name):
reqfile = f'{rec_path}/vod/{file_name}'
if not os.path.exists(reqfile):
abort(404)
return send_file(reqfile, mimetype='image/png')
return send_file(reqfile, mimetype='video/mp4')
@app.route('/watch/<file_name_no_extension>')
def watch_route(file_name_no_extension):
@app.route("/video/download/<file_name>", methods=['GET'])
def video_download_route(file_name):
reqfile = f'{rec_path}/vod/{file_name}'
if not os.path.exists(reqfile):
abort(404)
return send_file(reqfile, as_attachment=True, download_name=file_name)
@app.route('/video/watch/<file_name_no_extension>', methods=['GET'])
def video_watch_route(file_name_no_extension):
file_name = file_name_no_extension + '.mp4'
reqfile = f'{rec_path}/vod/{file_name}'
if not os.path.exists(reqfile):