improved video.html added fix time duration fro livestreams
This commit is contained in:
parent
7c9aa30f10
commit
d6edd14f16
5 changed files with 105 additions and 27 deletions
28
templates/A.html
Normal file
28
templates/A.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends "results_layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<p class="fetched fetched_dif fetched_vid">{{ lang_data.results.results }} {{ fetched }} {{ lang_data.results.seconds }}</p>
|
||||
{% if results %}
|
||||
{% for result in results %}
|
||||
<div><div class="video__results">
|
||||
<div class="video__img__results">
|
||||
<a href="{{ result[0] }}"> <img src="{{ result[6] }}">
|
||||
<div class="duration">{{ result[7] }}</div>
|
||||
</img></a>
|
||||
</div>
|
||||
<div class="results video-results-margin">
|
||||
<a {% if settings.new_tab == "active" %} target="_blank" {% endif %} href="{{ result[0] }}"><h3 class="video_title" href="{{ result[0] }}">{{ result[1] }}</h3></a>
|
||||
<p class="stats">{{ result[3] }} • {{ result[2] }}</p>
|
||||
<p class="publish__info">{{ result[5] }} <span class="pipe">|</span> {{ result[4] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="no-results-found">
|
||||
Your search '{{ q }}' came back with no results.<br>
|
||||
Try rephrasing your search term and/or recorrect any spelling mistakes.
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -52,6 +52,7 @@
|
|||
<button class="results-save" type="submit">Apply settings</button>
|
||||
</form>
|
||||
<div class="search-results">
|
||||
<!-- Results go here -->
|
||||
{{ if .Results }}
|
||||
<div class="images images_viewer_hidden">
|
||||
<!-- Image Viewer Placeholder - Adapt as necessary -->
|
||||
|
|
|
@ -53,15 +53,18 @@
|
|||
</form>
|
||||
<div class="results">
|
||||
<!-- Results go here -->
|
||||
{{range .Results}}
|
||||
<div class="result_item">
|
||||
<a href="{{.URL}}">{{.URL}}</a>
|
||||
<a href="{{.URL}}"><h3>{{.Header}}</h3></a>
|
||||
<p>{{.Description}}</p>
|
||||
</div>
|
||||
<br>
|
||||
{{if .Results}}
|
||||
{{range .Results}}
|
||||
<div class="result_item">
|
||||
<a href="{{.URL}}">{{.URL}}</a>
|
||||
<a href="{{.URL}}"><h3>{{.Header}}</h3></a>
|
||||
<p>{{.Description}}</p>
|
||||
</div>
|
||||
<br>
|
||||
{{end}}
|
||||
{{else}}
|
||||
<div class="no-results">No results found for '{{ .Query }}'. Try different keywords.</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<!-- Additional features and formatting based on inspiration.html -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,27 +3,62 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Video Results</title>
|
||||
<title>{{.Query}} - Ocásek</title>
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<h1>Video Results</h1>
|
||||
{{ if .Results }}
|
||||
{{ range .Results }}
|
||||
<div class="video-result">
|
||||
<h2>{{ .Title }}</h2>
|
||||
<a href="{{ .Href }}" target="_blank">
|
||||
<img src="{{ .Image }}" alt="{{ .Title }}" style="width:100%;max-width:600px;">
|
||||
</a>
|
||||
<p>{{ .Views }} views | {{ .Duration }}</p>
|
||||
<p>By {{ .Creator }}</p>
|
||||
</div>
|
||||
<!-- Removed the break as it's not directly supported in Go templates. If you want only the first result, adjust in Go code instead -->
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
<p>No results found. Try adjusting your search term.</p>
|
||||
{{ end }}
|
||||
<form action="/search" id="prev-next-form" class="results-search-container" method="GET" autocomplete="off">
|
||||
<h1 class="logomobile"><a class="no-decoration" href="./">Ocásek</a></h1>
|
||||
<div class="wrapper-results">
|
||||
<input type="text" name="q" value="{{ .Query }}" id="search-input" placeholder="Type to search..." />
|
||||
<button id="search-wrapper-ico" class="material-icons-round" name="t" value="video">search</button>
|
||||
<input type="submit" class="hide" name="t" value="video" />
|
||||
</div>
|
||||
<div class="sub-search-button-wrapper">
|
||||
<div class="search-container-results-btn">
|
||||
<button id="sub-search-wrapper-ico" class="material-icons-round clickable" name="t" value="text">search</button>
|
||||
<button name="t" value="text" class="clickable">Web</button>
|
||||
</div>
|
||||
<div class="search-container-results-btn">
|
||||
<button id="sub-search-wrapper-ico" class="material-icons-round clickable" name="t" value="image">image</button>
|
||||
<button name="t" value="image" class="clickable">Images</button>
|
||||
</div>
|
||||
<div class="search-container-results-btn">
|
||||
<button id="sub-search-wrapper-ico" class="material-icons-round clickable search-active" name="t" value="video">movie</button>
|
||||
<button name="t" value="video" class="clickable search-active">Videos</button>
|
||||
</div>
|
||||
<div class="search-container-results-btn">
|
||||
<button id="sub-search-wrapper-ico" class="material-icons-round clickable" name="t" value="reddit">forum</button>
|
||||
<button name="t" value="forum" class="clickable">Forums</button>
|
||||
</div>
|
||||
<div class="search-container-results-btn">
|
||||
<button id="sub-search-wrapper-ico" class="material-icons-round clickable" name="t" value="torrent">share</button>
|
||||
<button name="t" value="torrent" class="clickable">Torrents</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- Results go here -->
|
||||
<p class="fetched fetched_dif fetched_vid"><!-- { fetched } --></p>
|
||||
{{ if .Results }}
|
||||
{{ range .Results }}
|
||||
<div>
|
||||
<div class="video__results">
|
||||
<div class="video__img__results">
|
||||
<a href="{{ .Href }}"> <img src="{{ .Image }}">
|
||||
<div class="duration">{{ .Duration }}</div>
|
||||
</img></a>
|
||||
</div>
|
||||
<div class="results video-results-margin">
|
||||
<h3 class="video_title" href="{{ .Href }}">{{ .Title }}</h3></a>
|
||||
<p class="stats">{{ .Views }} <span class="pipe">|</span> {{ .Date }}</p>
|
||||
<p class="publish__info">YouTube <span class="pipe">|</span> {{ .Creator }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
<div class="no-results">No results found for '{{ .Query }}'. Try different keywords.</div>>
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
||||
|
|
13
video.go
13
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue