the custom fileserver is back
This commit is contained in:
parent
bd2ef69a7d
commit
3eaba322b2
3 changed files with 23 additions and 12 deletions
|
@ -12,7 +12,6 @@ bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
|||
live_channel_id = os.environ.get('DISCORDBOT_LIVE_CHANNEL_ID', 0)
|
||||
live_channel_update = os.environ.get('DISCORDBOT_LIVE_CHANNEL_UPDATE', 5)
|
||||
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
||||
vod_hostname = os.environ.get('VOD_HOSTNAME', 'vod.example.com')
|
||||
|
||||
# Discord API Intents
|
||||
intents = discord.Intents.all()
|
||||
|
@ -20,7 +19,7 @@ intents.members = True
|
|||
intents.guilds = True
|
||||
intents.messages = True
|
||||
intents.reactions = True
|
||||
#intents.presences = True
|
||||
intents.presences = True
|
||||
intents.message_content = True
|
||||
|
||||
# Discord client
|
||||
|
@ -135,10 +134,12 @@ async def query_database():
|
|||
scheduler.remove_job('announce_live_channel')
|
||||
|
||||
if rechead != {}:
|
||||
vod_filename = rechead['file']
|
||||
video_filename = rechead['video']
|
||||
thumb_filename = rechead['thumb']
|
||||
rechead = {}
|
||||
vod_url = f'https://{vod_hostname}/storage/{vod_filename}'
|
||||
offline_msg = f'Live stream is now offline. [Download VoD recording]({vod_url})'
|
||||
vod_url = f'https://{scheduler_hostname}/video/{video_filename}'
|
||||
thumb_url = f'https://{scheduler_hostname}/thumb/{thumb_filename}'
|
||||
offline_msg = f'Live stream is now offline. [Download VoD recording]({vod_url}) {thumb_url}'
|
||||
else:
|
||||
offline_msg = f'Live stream is now offline.'
|
||||
logger_discord.info(offline_msg)
|
||||
|
|
|
@ -6,6 +6,7 @@ import json
|
|||
import requests
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, jsonify, request
|
||||
from flask.helpers import send_file
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from core_client import Client
|
||||
from ffmpeg import FFmpeg, Progress
|
||||
|
@ -163,18 +164,20 @@ def exec_stream(stream_id, stream_name, stream_prio, stream_hls_url):
|
|||
# Execute recorder
|
||||
def exec_recorder(stream_id, stream_hls_url):
|
||||
global rechead
|
||||
current_datetime = datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
|
||||
current_datetime = datetime.now().strftime("%Y%m%d_%H%M%S-%f")
|
||||
video_file = current_datetime + ".mp4"
|
||||
thumb_file = current_datetime + ".png"
|
||||
if rechead != {}:
|
||||
logger_job.error('Recorder is already started. Refusing to start another job.')
|
||||
else:
|
||||
logger_job.warning(f'Recording {output_file} started.')
|
||||
logger_job.warning(f'Recording {video_file} started.')
|
||||
rechead = { 'id': stream_id,
|
||||
'video': video_file,
|
||||
'thumb': thumb_file }
|
||||
video_output = f'{rec_path}/live/{video_file}'
|
||||
thumb_output = f'{rec_path}/live/{thumb_file}'
|
||||
|
||||
# Record a mp4 file
|
||||
ffmpeg = (
|
||||
FFmpeg()
|
||||
.option("y")
|
||||
|
@ -182,23 +185,23 @@ def exec_recorder(stream_id, stream_hls_url):
|
|||
.output(video_output,
|
||||
{"codec:v": "copy", "codec:a": "copy", "bsf:a": "aac_adtstoasc"},
|
||||
))
|
||||
|
||||
@ffmpeg.on("progress")
|
||||
def on_progress(progress: Progress):
|
||||
print(progress)
|
||||
ffmpeg.execute()
|
||||
|
||||
ffmpeg = (
|
||||
# Generate thumbnail image from the recorded mp4 file
|
||||
ffmpeg_thumb = (
|
||||
FFmpeg()
|
||||
.input(video_output)
|
||||
.output(thumb_output,
|
||||
{"vf": "thumbnail", "frames:v": "1"})
|
||||
)
|
||||
ffmpeg.execute()
|
||||
ffmpeg_thumb.execute()
|
||||
|
||||
logger_job.warning(f'Recording {video_file} finished.')
|
||||
os.rename(f'{video_output}', f'{rec_path}/vod/{video_file}')
|
||||
os.rename(f'{thumb_output}', f'{rec_path}/thumb/{thumb_file}}')
|
||||
os.rename(f'{thumb_output}', f'{rec_path}/thumb/{thumb_file}')
|
||||
|
||||
rechead = {}
|
||||
|
||||
|
@ -285,5 +288,13 @@ def database_route():
|
|||
global database
|
||||
return jsonify(database)
|
||||
|
||||
@app.route("/video/<file_name>", methods=['GET'])
|
||||
def video_route(file_name):
|
||||
return send_file(f"./{rec_path}/video/{file_name}",mimetype='video/mp4')
|
||||
|
||||
@app.route("/thumb/<file_name>", methods=['GET'])
|
||||
def thumb_route(file_name):
|
||||
return send_file(f"./{rec_path}/thumb/{file_name}",mimetype='image/png')
|
||||
|
||||
def create_app():
|
||||
return app
|
||||
|
|
|
@ -9,4 +9,3 @@ SCHEDULER_API_HOSTNAME=tv.example.com
|
|||
DISCORDBOT_TOKEN=changeme
|
||||
DISCORDBOT_LIVE_CHANNEL_ID=0
|
||||
DISCORDBOT_LIVE_CHANNEL_UPDATE=5
|
||||
VOD_HOSTNAME=vod.example.com
|
||||
|
|
Loading…
Reference in a new issue