From cfb218f299522a36a07308bb4e7b741c305541ad Mon Sep 17 00:00:00 2001 From: Marinho Date: Mon, 12 Feb 2024 17:04:00 +0000 Subject: [PATCH] chg: feat: add imbd support --- api/bludv.go | 20 ++++++++++++++++---- api/comando_torrents.go | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/api/bludv.go b/api/bludv.go index 74986d7..8382f4d 100644 --- a/api/bludv.go +++ b/api/bludv.go @@ -80,10 +80,10 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - if len(indexedTorrents) == 0 { - w.WriteHeader(http.StatusNotFound) - } - json.NewEncoder(w).Encode(indexedTorrents) + json.NewEncoder(w).Encode(Response{ + Results: indexedTorrents, + Count: len(indexedTorrents), + }) } func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) { @@ -146,6 +146,17 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTo size = append(size, findSizesFromText(text)...) }) + // find any link from imdb + imdbLink := "" + article.Find("div.content a").Each(func(i int, s *goquery.Selection) { + link, _ := s.Attr("href") + re := regexp.MustCompile(`https://www.imdb.com/title/(tt\d+)`) + matches := re.FindStringSubmatch(link) + if len(matches) > 0 { + imdbLink = matches[0] + } + }) + size = stableUniq(size) var chanIndexedTorrent = make(chan IndexedTorrent) @@ -193,6 +204,7 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTo OriginalTitle: title, Details: link, Year: year, + IMDB: imdbLink, Audio: magnetAudio, MagnetLink: magnetLink, Date: date, diff --git a/api/comando_torrents.go b/api/comando_torrents.go index 08e5923..580c81c 100644 --- a/api/comando_torrents.go +++ b/api/comando_torrents.go @@ -97,10 +97,10 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request) } w.Header().Set("Content-Type", "application/json") - if len(indexedTorrents) == 0 { - w.WriteHeader(http.StatusNotFound) - } - json.NewEncoder(w).Encode(indexedTorrents) + json.NewEncoder(w).Encode(Response{ + Results: indexedTorrents, + Count: len(indexedTorrents), + }) } func getTorrents(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) { @@ -163,6 +163,17 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent size = append(size, findSizesFromText(text)...) }) + // find any link from imdb + imdbLink := "" + article.Find("div.content a").Each(func(i int, s *goquery.Selection) { + link, _ := s.Attr("href") + re := regexp.MustCompile(`https://www.imdb.com/title/(tt\d+)`) + matches := re.FindStringSubmatch(link) + if len(matches) > 0 { + imdbLink = matches[0] + } + }) + size = stableUniq(size) var chanIndexedTorrent = make(chan IndexedTorrent) @@ -210,6 +221,7 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent OriginalTitle: title, Details: link, Year: year, + IMDB: imdbLink, Audio: magnetAudio, MagnetLink: magnetLink, Date: date,