Video Duration added

This commit is contained in:
TheErrorExe 2024-12-26 16:13:59 +01:00 committed by GitHub
parent 894bea28c1
commit cefd4ed7d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -243,6 +243,12 @@ INDEX_TEMPLATE = """
font-size: 14px;
text-align: center;
}
.video-item-duration {
color: #ccc;
font-size: 14px;
text-align: center;
margin-top: 5px;
}
.dark-mode {
background-color: #181818;
color: #fff;
@ -268,6 +274,7 @@ INDEX_TEMPLATE = """
<img src="{{ video['thumbnail'] }}" alt="{{ video['title'] }}">
<div class="video-item-title">{{ video['title'] }}</div>
<div class="video-item-uploader">By: {{ video['uploader'] }}</div>
<div class="video-item-duration">Duration: {{ video['duration'] }}</div>
</a>
</div>
{% endfor %}
@ -445,7 +452,7 @@ def get_video_comments(video_id, max_results=20):
}
try:
response = requests.get("https://www.googleapis.com/youtube/v3/commentThreads", params=params, timeout=1)
response = requests.get("https://www.googleapis.com/youtube/v3/commentThreads", params=params, timeout=3)
response.raise_for_status()
data = response.json()
@ -506,8 +513,7 @@ def index():
results = None
if query:
response = requests.get(f"{API_BASE_URL}search?q={query}", timeout=3)
response = requests.get(f"https://y.com.sb/api/v1/search?q={query}", timeout=3)
try:
data = response.json()
except ValueError:
@ -521,7 +527,8 @@ def index():
"uploader": entry.get("author", "Unbekannt"),
"thumbnail": f"/thumbnail/{entry['videoId']}",
"viewCount": entry.get("viewCountText", "Unbekannt"),
"published": entry.get("publishedText", "Unbekannt")
"published": entry.get("publishedText", "Unbekannt"),
"duration": format_duration(entry.get("lengthSeconds", 0)) # Video Dauer formatiert
}
for entry in data
if entry.get("videoId")
@ -530,6 +537,13 @@ def index():
return "Keine Ergebnisse gefunden oder Fehler in der API-Antwort.", 404
return render_template_string(INDEX_TEMPLATE, results=results)
def format_duration(seconds):
"""Formatiert die Dauer von Sekunden in Minuten:Sekunden."""
minutes = seconds // 60
seconds = seconds % 60
return f"{minutes}:{str(seconds).zfill(2)}"
def get_video_duration_from_file(video_path):
"""
Holt die Dauer eines Videos aus der Datei (FLV oder MP4) mithilfe von ffprobe.