Skip to content

Commit

Permalink
fix: ignore deleted videos in a playlist
Browse files Browse the repository at this point in the history
This fixes #17
  • Loading branch information
TheTipo01 committed Aug 3, 2023
1 parent b3de2db commit 654ed37
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions youtube/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ func (y *YouTube) GetPlaylist(id string) []Video {
result := make([]Video, 0, len(response.Items))
ids := make([]string, 0, len(response.Items))
for _, item := range response.Items {
result = append(result, Video{
ID: item.Snippet.ResourceId.VideoId,
Title: item.Snippet.Title,
Thumbnail: getBestThumbnail(item.Snippet.Thumbnails),
Duration: 0,
})

ids = append(ids, item.Snippet.ResourceId.VideoId)
thumbnail := getBestThumbnail(item.Snippet.Thumbnails)

// Check if the video is available and not deleted
if thumbnail != "" && item.Snippet.Description != "This video is unavailable." && item.Snippet.Title != "Deleted video" {
result = append(result, Video{
ID: item.Snippet.ResourceId.VideoId,
Title: item.Snippet.Title,
Thumbnail: thumbnail,
Duration: 0,
})

ids = append(ids, item.Snippet.ResourceId.VideoId)
}
}

durations := y.getVideosDurations(ids...)
Expand Down

0 comments on commit 654ed37

Please sign in to comment.