Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template_string, send_from_directory
|
| 2 |
+
import os
|
| 3 |
+
import glob
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
VIDEO_DIR = "/data"
|
| 8 |
+
|
| 9 |
+
def get_videos():
|
| 10 |
+
videos = []
|
| 11 |
+
if os.path.exists(VIDEO_DIR):
|
| 12 |
+
for ext in ['*.mp4', '*.mkv', '*.avi', '*.mov', '*.webm']:
|
| 13 |
+
videos.extend(glob.glob(os.path.join(VIDEO_DIR, ext)))
|
| 14 |
+
return sorted(videos)
|
| 15 |
+
|
| 16 |
+
HTML_TEMPLATE = """
|
| 17 |
+
<!DOCTYPE html>
|
| 18 |
+
<html>
|
| 19 |
+
<head>
|
| 20 |
+
<title>🎬 Premium Capcut Course</title>
|
| 21 |
+
<meta charset="utf-8">
|
| 22 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 23 |
+
<style>
|
| 24 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 25 |
+
body { font-family: system-ui, sans-serif; background: #0f0f1a; color: #fff; padding: 1rem; }
|
| 26 |
+
.header { background: linear-gradient(135deg, #1a1a2e, #16213e); padding: 1.5rem; text-align: center; border-bottom: 3px solid #00b4ff; }
|
| 27 |
+
.header h1 { color: #00b4ff; font-size: 2rem; }
|
| 28 |
+
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; display: flex; flex-wrap: wrap; gap: 1.5rem; }
|
| 29 |
+
.player-wrapper { flex: 3; min-width: 300px; background: #000; border-radius: 1rem; overflow: hidden; }
|
| 30 |
+
.player-wrapper video { width: 100%; height: auto; display: block; }
|
| 31 |
+
.playlist { flex: 1; min-width: 200px; background: #1a1a2e; border-radius: 1rem; padding: 1rem; max-height: 500px; overflow-y: auto; }
|
| 32 |
+
.playlist h3 { color: #00b4ff; margin-bottom: 1rem; }
|
| 33 |
+
.playlist button { display: block; width: 100%; padding: 0.75rem; margin-bottom: 0.5rem; background: #2a2a4e; color: #fff; border: none; border-radius: 0.5rem; cursor: pointer; text-align: left; font-size: 0.9rem; }
|
| 34 |
+
.playlist button:hover { background: #00b4ff; color: #000; }
|
| 35 |
+
.playlist button.active { background: #00b4ff; color: #000; }
|
| 36 |
+
.stats { text-align: center; padding: 1rem; color: #666; }
|
| 37 |
+
@media (max-width: 768px) { .container { flex-direction: column; } }
|
| 38 |
+
</style>
|
| 39 |
+
</head>
|
| 40 |
+
<body>
|
| 41 |
+
<div class="header">
|
| 42 |
+
<h1>🎬 Premium Capcut Editing Course</h1>
|
| 43 |
+
<p style="color: #888;">Master Video Editing Like a Pro</p>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="container">
|
| 47 |
+
<div class="player-wrapper">
|
| 48 |
+
<video id="videoPlayer" controls autoplay style="width:100%; height:auto;">
|
| 49 |
+
<source src="" type="video/mp4">
|
| 50 |
+
Your browser does not support the video tag.
|
| 51 |
+
</video>
|
| 52 |
+
</div>
|
| 53 |
+
<div class="playlist">
|
| 54 |
+
<h3>📚 Lectures</h3>
|
| 55 |
+
{% for video in videos %}
|
| 56 |
+
<button onclick="playVideo('{{ video }}')" class="{% if loop.first %}active{% endif %}">
|
| 57 |
+
▶️ {{ video|replace('/data/', '')|replace('.mp4', '') }}
|
| 58 |
+
</button>
|
| 59 |
+
{% endfor %}
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<div class="stats">📊 Total Videos: {{ videos|length }}</div>
|
| 64 |
+
|
| 65 |
+
<script>
|
| 66 |
+
function playVideo(path) {
|
| 67 |
+
const player = document.getElementById('videoPlayer');
|
| 68 |
+
player.querySelector('source').src = path;
|
| 69 |
+
player.load();
|
| 70 |
+
player.play();
|
| 71 |
+
|
| 72 |
+
// Highlight active
|
| 73 |
+
document.querySelectorAll('.playlist button').forEach(b => b.classList.remove('active'));
|
| 74 |
+
document.querySelectorAll('.playlist button').forEach(b => {
|
| 75 |
+
if (b.textContent.includes(path.replace('/data/', ''))) {
|
| 76 |
+
b.classList.add('active');
|
| 77 |
+
}
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
</script>
|
| 81 |
+
</body>
|
| 82 |
+
</html>
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
@app.route('/')
|
| 86 |
+
def index():
|
| 87 |
+
videos = get_videos()
|
| 88 |
+
return render_template_string(HTML_TEMPLATE, videos=videos)
|
| 89 |
+
|
| 90 |
+
@app.route('/data/<path:filename>')
|
| 91 |
+
def serve_video(filename):
|
| 92 |
+
return send_from_directory('/data', filename)
|
| 93 |
+
|
| 94 |
+
if __name__ == '__main__':
|
| 95 |
+
app.run(host='0.0.0.0', port=7860, debug=False)
|