From 85be52091e4b0a49fb8b45275ed7777eafdc0a88 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 14 Apr 2024 09:26:03 +0200 Subject: [PATCH] improved video.html added fix time duration fro livestreams --- templates/A.html | 28 +++++++++++++++++ templates/images.html | 1 + templates/results.html | 19 ++++++----- templates/videos.html | 71 +++++++++++++++++++++++++++++++----------- video.go | 13 +++++++- 5 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 templates/A.html diff --git a/templates/A.html b/templates/A.html new file mode 100644 index 0000000..9bc0178 --- /dev/null +++ b/templates/A.html @@ -0,0 +1,28 @@ +{% extends "results_layout.html" %} + +{% block body %} +

{{ lang_data.results.results }} {{ fetched }} {{ lang_data.results.seconds }}

+ {% if results %} + {% for result in results %} +
+ +
+

{{ result[1] }}

+

{{ result[3] }} • {{ result[2] }}

+

{{ result[5] }} | {{ result[4] }}

+
+
+
+ {% endfor %} + + {% else %} +
+ Your search '{{ q }}' came back with no results.
+ Try rephrasing your search term and/or recorrect any spelling mistakes. +
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/images.html b/templates/images.html index f3c072c..0eb14d2 100644 --- a/templates/images.html +++ b/templates/images.html @@ -52,6 +52,7 @@
+ {{ if .Results }}
diff --git a/templates/results.html b/templates/results.html index a19127c..4d188aa 100644 --- a/templates/results.html +++ b/templates/results.html @@ -53,15 +53,18 @@
- {{range .Results}} -
- {{.URL}} -

{{.Header}}

-

{{.Description}}

-
-
+ {{if .Results}} + {{range .Results}} +
+ {{.URL}} +

{{.Header}}

+

{{.Description}}

+
+
+ {{end}} + {{else}} +
No results found for '{{ .Query }}'. Try different keywords.
{{end}}
- diff --git a/templates/videos.html b/templates/videos.html index 47a4c94..f4fcc80 100644 --- a/templates/videos.html +++ b/templates/videos.html @@ -3,27 +3,62 @@ - Video Results + {{.Query}} - Ocásek -
-

Video Results

- {{ if .Results }} - {{ range .Results }} -
-

{{ .Title }}

- - {{ .Title }} - -

{{ .Views }} views | {{ .Duration }}

-

By {{ .Creator }}

-
- - {{ end }} - {{ else }} -

No results found. Try adjusting your search term.

- {{ end }} +
+

Ocásek

+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +

+ {{ if .Results }} + {{ range .Results }} +
+
+ +
+

{{ .Title }}

+

{{ .Views }} | {{ .Date }}

+

YouTube | {{ .Creator }}

+
+
+
+ {{ end }} + {{ else }} +
No results found for '{{ .Query }}'. Try different keywords.
> + {{ end }} diff --git a/video.go b/video.go index a068b8e..dc524d1 100644 --- a/video.go +++ b/video.go @@ -45,9 +45,11 @@ func formatViews(views int) string { case views >= 1_000_000_000: return fmt.Sprintf("%.1fB views", float64(views)/1_000_000_000) case views >= 1_000_000: - return fmt.Sprintf("%dM views", views/1_000_000) + return fmt.Sprintf("%.1fM views", float64(views)/1_000_000) case views >= 10_000: return fmt.Sprintf("%.1fK views", float64(views)/1_000) + case views == 1: + return fmt.Sprintf("%d view", views) default: return fmt.Sprintf("%d views", views) } @@ -55,9 +57,14 @@ func formatViews(views int) string { // formatDuration formats video duration as done in the Python code func formatDuration(seconds int) string { + if 0 > seconds { + return "Live" + } + hours := seconds / 3600 minutes := (seconds % 3600) / 60 seconds = seconds % 60 + if hours > 0 { return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds) } @@ -115,6 +122,10 @@ func handleVideoSearch(w http.ResponseWriter, query, safe, lang string, page int if item.Type == "channel" || item.Type == "playlist" { continue } + if item.UploadedDate == "" { + item.UploadedDate = "Now" + } + results = append(results, VideoResult{ Href: fmt.Sprintf("https://youtube.com%s", item.URL), Title: item.Title,