Skip to content

Commit 672ab8d

Browse files
committed
refactor: Simplify tracking routine in playVideo function
1 parent 3f3cd97 commit 672ab8d

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

internal/player/playvideo.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func showResumeDialog(episodeNum int, timeSeconds int) (bool, error) {
146146
// )
147147
// }
148148

149+
// playVideo plays the video and manages interactions
149150
// playVideo plays the video and manages interactions
150151
func playVideo(
151152
videoURL string,
@@ -213,22 +214,8 @@ func playVideo(
213214
preloadNextEpisode(episodes, currentEpisodeIndex)
214215

215216
// Start tracking routine if tracker is available
216-
stopTracking := make(chan struct{})
217-
if tracker != nil {
218-
go func() {
219-
ticker := time.NewTicker(2 * time.Second)
220-
defer ticker.Stop()
221-
for {
222-
select {
223-
case <-ticker.C:
224-
updateTracking(tracker, socketPath, anilistID, currentEpisode, currentEpisodeNum, updater)
225-
case <-stopTracking:
226-
return
227-
}
228-
}
229-
}()
230-
defer close(stopTracking)
231-
}
217+
stopTracking := startTrackingRoutine(tracker, socketPath, anilistID, currentEpisode, currentEpisodeNum, updater)
218+
defer close(stopTracking)
232219

233220
// Handle user input for interactive controls
234221
return handleUserInput(
@@ -244,6 +231,7 @@ func playVideo(
244231
}
245232

246233

234+
247235
// getCurrentEpisode gets the current episode
248236
// func getCurrentEpisode(episodes []models.Episode, num int) (*models.Episode, error) {
249237
// if num < 1 || num > len(episodes) {

0 commit comments

Comments
 (0)