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
@@ -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