Diff
1diff --git a/handler/videos.go b/handler/videos.go
2index 645d523cd02643960993b327a8c98887f54db557..c2cc79d117b7445d698608f71b834fd047705d3e 100644
3--- a/handler/videos.go
4+++ b/handler/videos.go
5@@ -4,7 +4,6 @@ import (
6 "context"
7 "errors"
8 "fmt"
9- "math"
10 "strings"
11 "sync"
12 "time"
13@@ -50,6 +49,10 @@ func (h *handler) addVideosForChannel(ctx context.Context, parsedChannel *feedpa
14 }
15 }
16
17+ if len(videos) == 0 {
18+ return
19+ }
20+
21 err = h.youTubeClient.GetVideoDurations(ctx, videos)
22 if err != nil {
23 h.log.Error("Failed to get video durations", "call", "handler.getVideoDurations", "err", err)
24@@ -111,7 +114,7 @@ func (h *handler) SetVideoProgress(ctx context.Context, videoID string, progress
25 return nil, fmt.Errorf("%w: %v", ErrInvalidProgress, err.Error())
26 }
27
28- video, err := h.db.SetVideoProgress(ctx, videoID, int(math.Floor(progress.Seconds())))
29+ video, err := h.db.SetVideoProgress(ctx, videoID, int(progress.Seconds()))
30 if err != nil {
31 return nil, fmt.Errorf("%w: %v", ErrInvalidProgress, err.Error())
32 }
33diff --git a/lib/clients/youtube/get_durations.go b/lib/clients/youtube/get_durations.go
34index 716198e5a6b2e9b4acac11c77614fd85acd1637a..78e2c0b9680897c2fb981ead9299781956ae653c 100644
35--- a/lib/clients/youtube/get_durations.go
36+++ b/lib/clients/youtube/get_durations.go
37@@ -42,6 +42,10 @@ type APIContentDetails struct {
38 }
39
40 func (c *youTubeClient) GetVideoDurations(ctx context.Context, videos map[string]*models.Video) error {
41+ if len(videos) == 0 {
42+ return nil
43+ }
44+
45 ids := strings.Builder{}
46 for id := range videos {
47 ids.WriteString(id)
48diff --git a/models/video.go b/models/video.go
49index 2c188524c43ada991876ebcac5b33157716affef..61c559c180230305cced0a23d0afe97ae9925de6 100644
50--- a/models/video.go
51+++ b/models/video.go
52@@ -2,7 +2,6 @@ package models
53
54 import (
55 "fmt"
56- "math"
57 "time"
58
59 "github.com/dustin/go-humanize"
60@@ -31,7 +30,12 @@ type Video struct {
61
62 // ProgressPercentage returns the current progress of the video as an integer from 0-100
63 func (v Video) ProgressPercentage() int {
64- return int(math.Floor(100 * float64(v.ProgressSeconds) / float64(v.DurationSeconds)))
65+ return int(100 * float64(v.ProgressSeconds) / float64(v.DurationSeconds))
66+}
67+
68+// WatchURL returns the formatted YouTube watch URL including the timestamp pointing to the current progress
69+func (v Video) WatchURL() string {
70+ return fmt.Sprintf("https://youtube.com/watch?v=%s&t=%d", v.ID, v.ProgressSeconds)
71 }
72
73 // Duration returns the total duration of the video in the hh:mm:ss format
74diff --git a/pages/new_videos.templ b/pages/new_videos.templ
75index 9e94871806293a9a6a650f7b106f1b964d1c3b1e..449d4441ffab247c843d31ec0e01f94de782dd99 100644
76--- a/pages/new_videos.templ
77+++ b/pages/new_videos.templ
78@@ -19,7 +19,7 @@ templ ProgressBar(video models.Video) {
79 templ thumbnail(video models.Video) {
80 <a
81 target="blank"
82- href={ templ.SafeURL(fmt.Sprintf("https://youtube.com/watch?v=%s", video.ID)) }
83+ href={ templ.SafeURL(video.WatchURL()) }
84 style="display: block; overflow: hidden; position: relative"
85 if video.IsShort {
86 class="pillarbox"
87diff --git a/pages/new_videos_templ.go b/pages/new_videos_templ.go
88index 482bd65ac496e15fe3ea13c7a0a2508190b86edd..c2aa7f3673d58f68959f8133047a2c852f315780 100644
89--- a/pages/new_videos_templ.go
90+++ b/pages/new_videos_templ.go
91@@ -115,9 +115,9 @@ func thumbnail(video models.Video) templ.Component {
92 return templ_7745c5c3_Err
93 }
94 var templ_7745c5c3_Var6 templ.SafeURL
95- templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("https://youtube.com/watch?v=%s", video.ID)))
96+ templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(video.WatchURL()))
97 if templ_7745c5c3_Err != nil {
98- return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 22, Col: 79}
99+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 22, Col: 40}
100 }
101 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
102 if templ_7745c5c3_Err != nil {