Skip to content

Commit 2ba47b7

Browse files
committed
feat ✨: hotfix proxying invidious apicalls, refacto search functions
Signed-off-by: Victor Hang <[email protected]>
1 parent 8b0f3f4 commit 2ba47b7

7 files changed

+178
-153
lines changed

.goreleaser.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ builds:
1616
- arm64
1717
- arm
1818
ldflags:
19-
- -s -w -X github.com/Banh-Canh/ytui/cmd.version=v{{.Version}}
19+
- -s -w -X github.com/Banh-Canh/ytui/cmd.version=v{{- .Version }}
2020
archives:
2121
- format: tar.gz
2222
# this name template makes the OS and Arch compatible with the results of `uname`.

cmd/query_history.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ will be stored in there.`,
5151
os.Exit(0)
5252
}
5353
utils.Logger.Info("Videos found in history.", zap.Int("video_count", len(result)))
54-
selectedVideo, err := youtube.YoutubeResultMenu(result)
54+
selectedVideo, err := youtube.YoutubeResultMenu(result, viper.GetString("invidious.proxy"))
5555
if err != nil {
5656
utils.Logger.Info("FZF menu closed.")
5757
os.Exit(0)

cmd/query_search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Press enter to run any of the videos.`,
5858
}
5959

6060
utils.Logger.Info("Videos found.", zap.Int("video_count", len(*result)))
61-
selectedVideo, err := youtube.YoutubeResultMenu(*result)
61+
selectedVideo, err := youtube.YoutubeResultMenu(*result, viper.GetString("invidious.proxy"))
6262
if err != nil {
6363
utils.Logger.Info("FZF menu closed.")
6464
os.Exit(0)

cmd/query_subscribed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ It will also only pick from the 50 most relevants subscribed channels in your Yo
7070
}
7171
}
7272
utils.Logger.Info("Retrieved videos from subscribed channels.", zap.Int("video_count", len(*result)))
73-
selectedVideo, err := youtube.YoutubeResultMenu(*result)
73+
selectedVideo, err := youtube.YoutubeResultMenu(*result, viper.GetString("invidious.proxy"))
7474
if err != nil {
7575
utils.Logger.Info("FZF menu closed.")
7676
os.Exit(0)

cmd/show_suscribed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ It will also only pick from the 50 most relevants subscribed channels in your Yo
6666
channelList = viper.GetStringSlice("channels.subscribed")
6767
utils.Logger.Info("Retrieved local subscribed channels.", zap.Int("channel_count", len(channelList)))
6868
}
69-
channels, err := youtube.GetAllChannelsInfo(channelList)
69+
channels, err := youtube.GetAllChannelsInfo(channelList, viper.GetString("invidious.proxy"))
7070
if err != nil {
7171
utils.Logger.Fatal("Failed to get all channels data.", zap.Error(err))
7272
os.Exit(1)

pkg/youtube/fzf.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func fetchDescriptionsInBackground(
1717
videoData []SearchResultItem,
1818
descriptionCache map[string]string,
1919
cacheLock *sync.RWMutex,
20+
proxyURLString string,
2021
) {
2122
go func() {
2223
for {
@@ -40,7 +41,7 @@ func fetchDescriptionsInBackground(
4041
}
4142

4243
// Fetch the video description with retries
43-
if err := fetchAndCacheDescription(video, descriptionCache, cacheLock); err != nil {
44+
if err := fetchAndCacheDescription(video, descriptionCache, cacheLock, proxyURLString); err != nil {
4445
utils.Logger.Error("Failed to fetch description.", zap.Error(err))
4546
continue
4647
}
@@ -73,9 +74,14 @@ func cleanDescription(description string) string {
7374
}
7475

7576
// Fetches a single video description and stores it in cache.
76-
func fetchAndCacheDescription(video SearchResultItem, descriptionCache map[string]string, cacheLock *sync.RWMutex) error {
77+
func fetchAndCacheDescription(
78+
video SearchResultItem,
79+
descriptionCache map[string]string,
80+
cacheLock *sync.RWMutex,
81+
proxyURLString string,
82+
) error {
7783
for {
78-
videoInfo, err := SearchVideoInfo(video.VideoID)
84+
videoInfo, err := SearchVideoInfo(video.VideoID, proxyURLString)
7985
if err != nil {
8086
utils.Logger.Info("Fetching description failed. Retrying...", zap.String("videoTitle", video.Title), zap.Error(err))
8187
}
@@ -139,13 +145,13 @@ func getVideoPreview(video SearchResultItem, descriptionCache map[string]string,
139145
}
140146

141147
// Handles the interactive menu for video selection. Powered by fzf-like
142-
func YoutubeResultMenu(videoData []SearchResultItem) (SearchResultItem, error) {
148+
func YoutubeResultMenu(videoData []SearchResultItem, proxyURLString string) (SearchResultItem, error) {
143149
// Cache to store video descriptions
144150
descriptionCache := make(map[string]string)
145151
cacheLock := sync.RWMutex{} // For thread-safe cache access
146152

147153
// Start background fetching of descriptions
148-
fetchDescriptionsInBackground(videoData, descriptionCache, &cacheLock)
154+
fetchDescriptionsInBackground(videoData, descriptionCache, &cacheLock, proxyURLString)
149155

150156
utils.Logger.Info("Opening search menu.")
151157
idx, err := fuzzyfinder.Find(

0 commit comments

Comments
 (0)