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

@ -187,70 +187,76 @@ INDEX_TEMPLATE = """
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ReviveTube by ReviveMii</title> <title>ReviveTube by ReviveMii</title>
<style> <style>
body { body {
font-family: 'Arial', sans-serif; font-family: 'Arial', sans-serif;
color: #fff; color: #fff;
background-color: #181818; background-color: #181818;
text-align: center; /* Zentriert den Text */ text-align: center; /* Zentriert den Text */
} }
h1 { h1 {
color: #ff0000; color: #ff0000;
font-size: 28px; font-size: 28px;
margin-bottom: 20px; margin-bottom: 20px;
} }
p, h2 { p, h2 {
font-size: 16px; font-size: 16px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.search-bar { .search-bar {
width: 300px; width: 300px;
padding: 10px; padding: 10px;
font-size: 16px; font-size: 16px;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 4px; border-radius: 4px;
display: block; /* Block-Level für zentrierten Abstand */ display: block; /* Block-Level für zentrierten Abstand */
margin: 0 auto; /* Zentriert das Eingabefeld */ margin: 0 auto; /* Zentriert das Eingabefeld */
} }
button { button {
padding: 10px 20px; padding: 10px 20px;
font-size: 16px; font-size: 16px;
background-color: #333333; background-color: #333333;
color: white; color: white;
border: none; border: none;
cursor: pointer; cursor: pointer;
border-radius: 4px; border-radius: 4px;
display: block; display: block;
margin: 10px auto; /* Zentriert den Button */ margin: 10px auto; /* Zentriert den Button */
} }
.video-item { .video-item {
margin-bottom: 20px; margin-bottom: 20px;
text-align: center; /* Zentriert jedes Video-Item */ text-align: center; /* Zentriert jedes Video-Item */
} }
.video-item img { .video-item img {
width: 320px; width: 320px;
height: 180px; height: 180px;
border-radius: 8px; border-radius: 8px;
} }
.video-item-title { .video-item-title {
color: #fff; color: #fff;
font-weight: bold; font-weight: bold;
font-size: 16px; font-size: 16px;
text-align: center; text-align: center;
} }
.video-item-uploader { .video-item-uploader {
color: #ccc; color: #ccc;
font-size: 14px; font-size: 14px;
text-align: center; text-align: center;
} }
.dark-mode { .video-item-duration {
background-color: #181818; color: #ccc;
color: #fff; font-size: 14px;
} text-align: center;
.dark-mode a { margin-top: 5px;
color: #1e90ff; }
} .dark-mode {
</style> background-color: #181818;
color: #fff;
}
.dark-mode a {
color: #1e90ff;
}
</style>
</head> </head>
<body class="dark-mode" id="page-body"> <body class="dark-mode" id="page-body">
<h1>ReviveTube by ReviveMii</h1> <h1>ReviveTube by ReviveMii</h1>
@ -268,6 +274,7 @@ INDEX_TEMPLATE = """
<img src="{{ video['thumbnail'] }}" alt="{{ video['title'] }}"> <img src="{{ video['thumbnail'] }}" alt="{{ video['title'] }}">
<div class="video-item-title">{{ video['title'] }}</div> <div class="video-item-title">{{ video['title'] }}</div>
<div class="video-item-uploader">By: {{ video['uploader'] }}</div> <div class="video-item-uploader">By: {{ video['uploader'] }}</div>
<div class="video-item-duration">Duration: {{ video['duration'] }}</div>
</a> </a>
</div> </div>
{% endfor %} {% endfor %}
@ -445,7 +452,7 @@ def get_video_comments(video_id, max_results=20):
} }
try: 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() response.raise_for_status()
data = response.json() data = response.json()
@ -506,30 +513,37 @@ def index():
results = None results = None
if query: if query:
response = requests.get(f"https://y.com.sb/api/v1/search?q={query}", timeout=3)
response = requests.get(f"{API_BASE_URL}search?q={query}", timeout=3)
try: try:
data = response.json() data = response.json()
except ValueError: except ValueError:
return "Fehler beim Parsen der API-Antwort.", 500 return "Fehler beim Parsen der API-Antwort.", 500
if response.status_code == 200 and isinstance(data, list): if response.status_code == 200 and isinstance(data, list):
results = [ results = [
{ {
"id": entry.get("videoId"), "id": entry.get("videoId"),
"title": entry.get("title"), "title": entry.get("title"),
"uploader": entry.get("author", "Unbekannt"), "uploader": entry.get("author", "Unbekannt"),
"thumbnail": f"/thumbnail/{entry['videoId']}", "thumbnail": f"/thumbnail/{entry['videoId']}",
"viewCount": entry.get("viewCountText", "Unbekannt"), "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 for entry in data
if entry.get("videoId") if entry.get("videoId")
] ]
else: else:
return "Keine Ergebnisse gefunden oder Fehler in der API-Antwort.", 404 return "Keine Ergebnisse gefunden oder Fehler in der API-Antwort.", 404
return render_template_string(INDEX_TEMPLATE, results=results) 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): def get_video_duration_from_file(video_path):
""" """
Holt die Dauer eines Videos aus der Datei (FLV oder MP4) mithilfe von ffprobe. Holt die Dauer eines Videos aus der Datei (FLV oder MP4) mithilfe von ffprobe.