mirror of
https://github.com/Xevion/glance.git
synced 2025-12-15 00:11:53 -06:00
Allow using alternative links for YT, HN and reddit
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -38,7 +39,7 @@ func parseYoutubeFeedTime(t string) time.Time {
|
||||
return parsedTime
|
||||
}
|
||||
|
||||
func FetchYoutubeChannelUploads(channelIds []string) (Videos, error) {
|
||||
func FetchYoutubeChannelUploads(channelIds []string, videoUrlTemplate string) (Videos, error) {
|
||||
requests := make([]*http.Request, 0, len(channelIds))
|
||||
|
||||
for i := range channelIds {
|
||||
@@ -75,10 +76,24 @@ func FetchYoutubeChannelUploads(channelIds []string) (Videos, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
var videoUrl string
|
||||
|
||||
if videoUrlTemplate == "" {
|
||||
videoUrl = video.Link.Href
|
||||
} else {
|
||||
parsedUrl, err := url.Parse(video.Link.Href)
|
||||
|
||||
if err == nil {
|
||||
videoUrl = strings.ReplaceAll(videoUrlTemplate, "{VIDEO-ID}", parsedUrl.Query().Get("v"))
|
||||
} else {
|
||||
videoUrl = "#"
|
||||
}
|
||||
}
|
||||
|
||||
videos = append(videos, Video{
|
||||
ThumbnailUrl: video.Group.Thumbnail.Url,
|
||||
Title: video.Title,
|
||||
Url: video.Link.Href,
|
||||
Url: videoUrl,
|
||||
Author: response.Channel,
|
||||
AuthorUrl: response.ChannelLink.Href + "/videos",
|
||||
TimePosted: parseYoutubeFeedTime(video.Published),
|
||||
|
||||
Reference in New Issue
Block a user