download video as attachment
This commit is contained in:
parent
87fa946046
commit
da6fd931c1
2 changed files with 29 additions and 18 deletions
|
@ -143,22 +143,23 @@ async def query_database():
|
||||||
thumb_filename = rechead['thumb']
|
thumb_filename = rechead['thumb']
|
||||||
# Reset the rechead
|
# Reset the rechead
|
||||||
rechead = {}
|
rechead = {}
|
||||||
|
await live_channel.send('Live stream is now offline.')
|
||||||
|
|
||||||
# Creating an embed
|
# 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'
|
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}',
|
embed = discord.Embed(title=f'{rec_stream_name}',
|
||||||
url=f'{watch_url}',
|
url=f'{watch_url}',
|
||||||
colour=0x00b0f4,
|
colour=0x00b0f4,
|
||||||
timestamp=datetime.now())
|
timestamp=datetime.now())
|
||||||
embed.add_field(name="Download",
|
embed.add_field(name="Download",
|
||||||
value=f"[{video_filename}]({video_url})",
|
value=f"[{video_filename}]({video_download_url})",
|
||||||
inline=True)
|
inline=True)
|
||||||
embed.add_field(name="Watch",
|
embed.add_field(name="Watch",
|
||||||
value=f'[plyr.js]({watch_url})',
|
value=f'[plyr.js]({video_watch_url})',
|
||||||
inline=True)
|
inline=True)
|
||||||
embed.set_image(url=thumb_url)
|
embed.set_image(url=thumb_url)
|
||||||
embed.set_thumbnail(url=f'{img_url}/logo-96.png')
|
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')
|
icon_url=f'{img_url}/logo-96.png')
|
||||||
# Sending the embed to the channel
|
# Sending the embed to the channel
|
||||||
await live_channel.send(embed=embed)
|
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:
|
else:
|
||||||
logger_discord.info('Live stream is now offline.')
|
logger_discord.info('Live stream is now offline.')
|
||||||
|
|
||||||
|
|
|
@ -292,9 +292,10 @@ scheduler.start()
|
||||||
# Flask API
|
# Flask API
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
def root_route():
|
def root_route():
|
||||||
about_json = { 'about': 'deflax tv api' }
|
about_json = { 'about': 'DeflaxTV API' }
|
||||||
return jsonify(about_json)
|
return jsonify(about_json)
|
||||||
|
|
||||||
|
# JSON data
|
||||||
@app.route('/playhead', methods=['GET'])
|
@app.route('/playhead', methods=['GET'])
|
||||||
def playhead_route():
|
def playhead_route():
|
||||||
global playhead
|
global playhead
|
||||||
|
@ -310,12 +311,13 @@ def database_route():
|
||||||
global database
|
global database
|
||||||
return jsonify(database)
|
return jsonify(database)
|
||||||
|
|
||||||
@app.route("/video/<file_name>", methods=['GET'])
|
# Images
|
||||||
def video_route(file_name):
|
@app.route("/img/<file_name>", methods=['GET'])
|
||||||
reqfile = f'{rec_path}/vod/{file_name}'
|
def img_route(file_name):
|
||||||
|
reqfile = f'./img/{file_name}'
|
||||||
if not os.path.exists(reqfile):
|
if not os.path.exists(reqfile):
|
||||||
abort(404)
|
abort(404)
|
||||||
return send_file(reqfile, mimetype='video/mp4')
|
return send_file(reqfile, mimetype='image/png')
|
||||||
|
|
||||||
@app.route("/thumb/<file_name>", methods=['GET'])
|
@app.route("/thumb/<file_name>", methods=['GET'])
|
||||||
def thumb_route(file_name):
|
def thumb_route(file_name):
|
||||||
|
@ -324,15 +326,23 @@ def thumb_route(file_name):
|
||||||
abort(404)
|
abort(404)
|
||||||
return send_file(reqfile, mimetype='image/png')
|
return send_file(reqfile, mimetype='image/png')
|
||||||
|
|
||||||
@app.route("/img/<file_name>", methods=['GET'])
|
# Video
|
||||||
def img_route(file_name):
|
@app.route("/video/<file_name>", methods=['GET'])
|
||||||
reqfile = f'./img/{file_name}'
|
def video_route(file_name):
|
||||||
|
reqfile = f'{rec_path}/vod/{file_name}'
|
||||||
if not os.path.exists(reqfile):
|
if not os.path.exists(reqfile):
|
||||||
abort(404)
|
abort(404)
|
||||||
return send_file(reqfile, mimetype='image/png')
|
return send_file(reqfile, mimetype='video/mp4')
|
||||||
|
|
||||||
@app.route('/watch/<file_name_no_extension>')
|
@app.route("/video/download/<file_name>", methods=['GET'])
|
||||||
def watch_route(file_name_no_extension):
|
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'
|
file_name = file_name_no_extension + '.mp4'
|
||||||
reqfile = f'{rec_path}/vod/{file_name}'
|
reqfile = f'{rec_path}/vod/{file_name}'
|
||||||
if not os.path.exists(reqfile):
|
if not os.path.exists(reqfile):
|
||||||
|
|
Loading…
Reference in a new issue