First work session with OpenCode and OpenRouter
This commit is contained in:
1 parent
91a973dde2
commit
a3f55a8c35
17 files changed
+1035
-123
No files matched your search
@@ -29,5 +29,5 @@ def upload():
|
||||
["media_id", "media_playback_option", "media_playback_option_weight"],
|
||||
[new_id, "-fs", 1]
|
||||
)
|
||||
|
||||
|
||||
return redirect("/")
|
||||
@@ -29,11 +29,11 @@
|
||||
<div class="row">
|
||||
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="/upload/photo">Upload a Static Image</a>
|
||||
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="/configure/stream">Configure a Stream</a>
|
||||
<button class="col-sm-4 btn btn-secondary p-3 my-1">Upload a Slideshow of Images</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button class="col-sm-4 btn btn-secondary p-3 my-1">Upload a Video</button>
|
||||
<button class="col-sm-4 btn btn-secondary p-3 my-1">Get Video from YouTube</button>
|
||||
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="{{ url_for('youtube_download.request_download') }}">Get Video from YouTube</a>
|
||||
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="{{ url_for('youtube_download.list_jobs') }}">YouTube Download Jobs</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video Commander</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../static/style.css">
|
||||
<script src="../static/script.js"></script>
|
||||
<script>
|
||||
function prepUpload() {
|
||||
uploadFiles('submit', 'fileToUpload', 'progressContainer', 'progress', '/upload/slideshow', {
|
||||
'name': document.getElementById('buttonName').value
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="text-center">Upload a Slideshow of Photos</h1>
|
||||
<hr>
|
||||
<div class="alert alert-info text-center" role="alert">
|
||||
Upload a slideshow of photos, you'll be able to order the photos on the next screen
|
||||
</div>
|
||||
<form>
|
||||
<div id="progressContainer" class="progress" role="progressbar", aria-label="Upload Progress" aria-valuemin="0"
|
||||
aria-valuemin="0", aria-valuemax="100" >
|
||||
<div id="progress" class="progress-bar" style="width: 0%;">0%</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="fileToUpload">File to Upload</label>
|
||||
<input type="file" class="form-control" name="file" id="fileToUpload" multiple/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="buttonName">Button Name</label>
|
||||
<input type="text" class="form-control" name="buttonName" id="buttonName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="photoTime">How long to show each photo?</label>
|
||||
<input type="number" class="form-control" name="photoTime" id="photoTime" />
|
||||
</div>
|
||||
<button id="submit" class="btn btn-primary form-control" onclick="prepUpload()">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,48 +0,0 @@
|
||||
from flask import Blueprint, request, render_template, jsonify, current_app
|
||||
from utilities.tools import get_db
|
||||
from werkzeug.utils import secure_filename
|
||||
import os
|
||||
|
||||
upload_photo_bp = Blueprint('upload_slideshow', __name__, url_prefix='/upload', template_folder='.')
|
||||
|
||||
@upload_photo_bp.route('/slideshow', methods=['GET', 'POST'])
|
||||
def get_page():
|
||||
if request.method == "GET":
|
||||
return render_get(), 200
|
||||
elif request.method == "POST":
|
||||
return upload()
|
||||
|
||||
def render_get():
|
||||
return render_template('upload_slideshow.html')
|
||||
|
||||
def upload():
|
||||
if not request.files['files[]']:
|
||||
return jsonify({
|
||||
'status': 'FAILED',
|
||||
'error': '/upload/slideshow requires 1 or more photos'
|
||||
}), 400
|
||||
|
||||
# TODO Button name data exists
|
||||
# TODO Button name already exists validation
|
||||
# TODO File input validation
|
||||
print(request.files['files[]'])
|
||||
|
||||
file = request.files['files[]']
|
||||
|
||||
if file:
|
||||
folder_path = os.path.join(current_app.config["config"]["upload_location"], request.form["name"])
|
||||
if not os.path.exists(folder_path):
|
||||
os.makedirs(folder_path)
|
||||
|
||||
filename = secure_filename(file.filename)
|
||||
file.save(os.path.join(folder_path, filename))
|
||||
|
||||
get_db().insert(
|
||||
"media",
|
||||
["media_name", "media_uri"],
|
||||
[request.form["name"], os.path.join(folder_path, filename)]
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
'status': 'SUCCESS'
|
||||
}), 200
|
||||
@@ -0,0 +1,67 @@
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from flask import Blueprint, request, render_template, redirect, url_for
|
||||
from utilities.tools import get_db
|
||||
|
||||
|
||||
youtube_download_bp = Blueprint('youtube_download', __name__, url_prefix='/youtube', template_folder='.')
|
||||
|
||||
|
||||
@youtube_download_bp.route('/download', methods=['GET', 'POST'])
|
||||
def request_download():
|
||||
media_name = ''
|
||||
youtube_url = ''
|
||||
error = None
|
||||
if request.method == 'POST':
|
||||
media_name = request.form.get('media_name', '').strip()
|
||||
youtube_url = request.form.get('youtube_url', '').strip()
|
||||
if not media_name:
|
||||
error = 'Please enter a name for the media item.'
|
||||
elif not valid_youtube_url(youtube_url):
|
||||
error = 'Please enter a valid YouTube video URL (youtube.com or youtu.be).'
|
||||
else:
|
||||
get_db().insert(
|
||||
'youtube_download_job',
|
||||
['youtube_download_job_url', 'youtube_download_job_media_name'],
|
||||
[youtube_url, media_name]
|
||||
)
|
||||
return redirect(url_for('youtube_download.list_jobs'), code=303)
|
||||
|
||||
return render_template(
|
||||
'youtube_request.html', media_name=media_name, youtube_url=youtube_url, error=error
|
||||
), 400 if error else 200
|
||||
|
||||
|
||||
def valid_youtube_url(value):
|
||||
try:
|
||||
parsed = urlsplit(value)
|
||||
return (
|
||||
parsed.scheme in ('http', 'https')
|
||||
and parsed.hostname in ('youtube.com', 'www.youtube.com', 'm.youtube.com',
|
||||
'music.youtube.com', 'youtu.be', 'www.youtu.be')
|
||||
and not parsed.username and not parsed.password
|
||||
and parsed.port in (None, 80, 443)
|
||||
and bool(parsed.path.strip('/'))
|
||||
and not any(character.isspace() for character in value)
|
||||
)
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
@youtube_download_bp.route('/jobs')
|
||||
def list_jobs():
|
||||
show_completed = request.args.get('show_completed') == '1'
|
||||
columns = [
|
||||
'youtube_download_job_id', 'youtube_download_job_media_name',
|
||||
'youtube_download_job_url', 'youtube_download_job_status',
|
||||
'youtube_download_job_retry_count'
|
||||
]
|
||||
query = 'SELECT ' + ', '.join(columns) + ' FROM youtube_download_job'
|
||||
parameters = []
|
||||
if not show_completed:
|
||||
query += ' WHERE youtube_download_job_status != ?'
|
||||
parameters.append('downloaded')
|
||||
query += ' ORDER BY youtube_download_job_id'
|
||||
rows = get_db().query(query, parameters)[1]
|
||||
jobs = [dict(zip(columns, row)) for row in rows]
|
||||
return render_template('youtube_jobs.html', jobs=jobs, show_completed=show_completed)
|
||||
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>YouTube Download Jobs - Sanctuary Commander</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="text-center">YouTube Download Jobs</h1>
|
||||
<hr>
|
||||
<nav class="mb-3" aria-label="Page navigation">
|
||||
<a class="btn btn-secondary" href="{{ url_for('home.root_route') }}">Home</a>
|
||||
<a class="btn btn-primary" href="{{ url_for('youtube_download.request_download') }}">Request a Video</a>
|
||||
</nav>
|
||||
<p>Pending, downloading, and failed jobs are always shown. Refresh this page to see updated statuses.</p>
|
||||
<form action="{{ url_for('youtube_download.list_jobs') }}" method="GET" class="mb-3">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" name="show_completed" id="show_completed" value="1" {% if show_completed %}checked{% endif %}>
|
||||
<label class="form-check-label" for="show_completed">Include completed jobs</label>
|
||||
</div>
|
||||
<button class="btn btn-secondary" type="submit">Update List</button>
|
||||
</form>
|
||||
{% if jobs %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr><th scope="col">Job</th><th scope="col">Media Name</th><th scope="col">YouTube URL</th><th scope="col">Status</th><th scope="col">Failed Attempts</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for job in jobs %}
|
||||
<tr>
|
||||
<td>{{ job.youtube_download_job_id }}</td>
|
||||
<td>{{ job.youtube_download_job_media_name or '(Video title will be used)' }}</td>
|
||||
<td class="text-break">{{ job.youtube_download_job_url }}</td>
|
||||
<td>{{ job.youtube_download_job_status }}</td>
|
||||
<td>{{ job.youtube_download_job_retry_count }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p role="status">No download jobs to show.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Request a YouTube Video - Sanctuary Commander</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="text-center">Request a YouTube Video</h1>
|
||||
<hr>
|
||||
<nav class="mb-3" aria-label="Page navigation">
|
||||
<a class="btn btn-secondary" href="{{ url_for('home.root_route') }}">Home</a>
|
||||
<a class="btn btn-secondary" href="{{ url_for('youtube_download.list_jobs') }}">View Download Jobs</a>
|
||||
</nav>
|
||||
<div class="alert alert-info" role="status">
|
||||
Queue a video for download to local storage. Downloads are processed by the separate YouTube worker.
|
||||
</div>
|
||||
{% if error %}
|
||||
<div class="alert alert-danger" role="alert">{{ error }}</div>
|
||||
{% endif %}
|
||||
<form action="{{ url_for('youtube_download.request_download') }}" method="POST">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="media_name">Media Name</label>
|
||||
<input type="text" class="form-control" name="media_name" id="media_name" value="{{ media_name }}" required>
|
||||
<div class="form-text">The name to display when the downloaded video is ready to play.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="youtube_url">YouTube Video URL</label>
|
||||
<input type="url" class="form-control" name="youtube_url" id="youtube_url" value="{{ youtube_url }}" placeholder="https://www.youtube.com/watch?v=..." required>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Queue Download</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user