Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d6cfb8668 | |||
| d9141c8df7 | |||
| e5dea934f1 | |||
| 455f734c8a | |||
| 6eba15d52a | |||
| a999f065da | |||
|
|
20b054f331 | ||
| 782f9d6b3f | |||
| 0b21e3b1e7 | |||
| 27ab075da1 | |||
| f4476024da | |||
|
|
472fedc565 | ||
|
|
6525b5b2b0 | ||
|
|
5bdd2cdd85 | ||
| 0f359ba44e | |||
|
|
bc53fbab1a |
9
.github/workflows/pipeline.dockerfile
vendored
9
.github/workflows/pipeline.dockerfile
vendored
@@ -1,22 +1,23 @@
|
||||
#####################################################
|
||||
### Copy platform specific binary
|
||||
FROM bash as copy-binary
|
||||
FROM bash AS copy-binary
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
RUN echo "Target Platform = ${TARGETPLATFORM}"
|
||||
|
||||
COPY dist .
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then cp torrentindexer_linux_amd64_linux_amd64_v1/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/386" ]; then cp torrentindexer_linux_386_linux_386/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then cp torrentindexer_linux_arm64_linux_arm64/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/386" ]; then cp torrentindexer_linux_386_linux_386_sse2/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then cp torrentindexer_linux_arm64_linux_arm64_v8.0/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/arm/v6" ]; then cp torrentindexer_linux_arm_linux_arm_6/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then cp torrentindexer_linux_arm_linux_arm_7/torrent-indexer /torrent-indexer; fi
|
||||
RUN if [ "$TARGETPLATFORM" = "linux/riscv64" ]; then cp torrentindexer_linux_riscv64_linux_riscv64_rva20u64/torrent-indexer /torrent-indexer; fi
|
||||
RUN chmod +x /torrent-indexer
|
||||
|
||||
|
||||
#####################################################
|
||||
### Build Final Image
|
||||
FROM alpine as release
|
||||
FROM alpine AS release
|
||||
LABEL maintainer="felipevm97@gmail.com"
|
||||
|
||||
COPY --from=copy-binary /torrent-indexer /app/
|
||||
|
||||
8
.github/workflows/pipeline.yml
vendored
8
.github/workflows/pipeline.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
go-lint:
|
||||
name: Lint Go code
|
||||
runs-on: ubuntu-latest
|
||||
container: golang:1.22
|
||||
container: golang:1.24
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
go:
|
||||
name: Test Go code
|
||||
runs-on: ubuntu-latest
|
||||
container: golang:1.22
|
||||
container: golang:1.24
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
@@ -60,7 +60,7 @@ jobs:
|
||||
name: Build binaries
|
||||
needs: [go, go-lint]
|
||||
runs-on: ubuntu-latest
|
||||
container: goreleaser/goreleaser:v1.25.1
|
||||
container: goreleaser/goreleaser:v2.11.1
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
@@ -153,6 +153,6 @@ jobs:
|
||||
with:
|
||||
context: .
|
||||
file: .github/workflows/pipeline.dockerfile
|
||||
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
|
||||
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
@@ -1,10 +1,11 @@
|
||||
# GoReleaser config
|
||||
project_name: torrent-indexer
|
||||
version: 2
|
||||
|
||||
builds:
|
||||
- id: torrentindexer_linux_amd64
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
@@ -17,7 +18,7 @@ builds:
|
||||
|
||||
- id: torrentindexer_linux_386
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- PKG_CONFIG_PATH=/i386/lib/pkgconfig
|
||||
goos:
|
||||
- linux
|
||||
@@ -31,7 +32,7 @@ builds:
|
||||
|
||||
- id: torrentindexer_linux_arm
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- CC=arm-linux-gnueabi-gcc
|
||||
- CXX=arm-linux-gnueabi-g++
|
||||
- PKG_CONFIG_PATH=/arm/lib/pkgconfig
|
||||
@@ -51,7 +52,7 @@ builds:
|
||||
|
||||
- id: torrentindexer_linux_arm64
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
- CXX=aarch64-linux-gnu-g++
|
||||
- PKG_CONFIG_PATH=/arm64/lib/pkgconfig
|
||||
@@ -64,10 +65,26 @@ builds:
|
||||
ldflags:
|
||||
- "-extldflags '-static'"
|
||||
- -s -w -X github.com/felipemarinho97/torrent-indexer/consts.gitSha={{.ShortCommit}} -X github.com/felipemarinho97/torrent-indexer/consts.gitTag={{.Version}}
|
||||
|
||||
- id: torrentindexer_linux_riscv64
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
- CC=riscv64-linux-gnu-gcc
|
||||
- CXX=riscv64-linux-gnu-g++
|
||||
- PKG_CONFIG_PATH=/riscv64/lib/pkgconfig
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- riscv64
|
||||
flags:
|
||||
- -tags=netgo
|
||||
ldflags:
|
||||
- "-extldflags '-static'"
|
||||
- -s -w -X github.com/felipemarinho97/torrent-indexer/consts.gitSha={{.ShortCommit}} -X github.com/felipemarinho97/torrent-indexer/consts.gitTag={{.Version}}
|
||||
|
||||
- id: torrentindexer_windows_386
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- CC=i686-w64-mingw32-gcc
|
||||
- CXX=i686-w64-mingw32-g++
|
||||
- PKG_CONFIG_PATH=/mingw32/lib/pkgconfig
|
||||
@@ -83,7 +100,7 @@ builds:
|
||||
|
||||
- id: torrentindexer_windows_amd64
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- CC=x86_64-w64-mingw32-gcc
|
||||
- CXX=x86_64-w64-mingw32-g++
|
||||
- PKG_CONFIG_PATH=/mingw64/lib/pkgconfig
|
||||
@@ -99,7 +116,7 @@ builds:
|
||||
|
||||
- id: torrentindexer_darwin_amd64
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
- CGO_ENABLED=0
|
||||
- CC=o64-clang
|
||||
- CXX=o64-clang++
|
||||
- PKG_CONFIG_PATH=/darwin/lib/pkgconfig
|
||||
@@ -115,13 +132,13 @@ builds:
|
||||
archives:
|
||||
- format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
formats: zip
|
||||
|
||||
checksum:
|
||||
name_template: "{{ .ProjectName }}_checksums.txt"
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-SNAPSHOT"
|
||||
version_template: "{{ .Tag }}-SNAPSHOT"
|
||||
|
||||
release:
|
||||
draft: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.22 as builder
|
||||
FROM golang:1.24 AS builder
|
||||
|
||||
WORKDIR /go/src/app
|
||||
COPY . .
|
||||
|
||||
95
README.md
95
README.md
@@ -1,5 +1,7 @@
|
||||
# torrent-indexer
|
||||
|
||||
[](https://discord.gg/7wqNywmpQW)
|
||||
|
||||
This is a simple torrent indexer that can be used to index torrents from HTML pages. It is written in Golang and uses Redis as a cache.
|
||||
|
||||
## Test it
|
||||
@@ -11,6 +13,9 @@ Visit [https://torrent-indexer.darklyn.org/](https://torrent-indexer.darklyn.org
|
||||
- [comando-torrents](https://comando.la/)
|
||||
- [bludv](https://bludvfilmes.tv/)
|
||||
- [torrent-dos-filmes](https://torrentdosfilmes.se/)
|
||||
- [starck-filmes](https://www.starckfilmes.online/)
|
||||
- [comandohds](https://comandohds.org/)
|
||||
- [rede-torrent](https://redetorrent.com/)
|
||||
|
||||
## Deploy
|
||||
|
||||
@@ -113,10 +118,96 @@ search:
|
||||
# json engine n/a
|
||||
```
|
||||
|
||||
If you have more tips on how to integrate with other torrent API clients like Prowlarr, please open a PR.
|
||||
## Integrating with Prowlarr
|
||||
|
||||
You can integrate this indexer with Prowlarr by adding a custom definition. See [Adding a custom YML definition](https://wiki.servarr.com/prowlarr/indexers#adding-a-custom-yml-definition).
|
||||
|
||||
```yaml
|
||||
---
|
||||
id: torrent-indexer
|
||||
name: Torrent Indexer
|
||||
description: "Indexing Brazilian Torrent websites into structured data. github.com/felipemarinho97/torrent-indexer"
|
||||
language: pt-BR
|
||||
type: public
|
||||
encoding: UTF-8
|
||||
links:
|
||||
- http://localhost:8080/
|
||||
|
||||
caps:
|
||||
categories:
|
||||
Movies: Movies
|
||||
TV: TV
|
||||
|
||||
modes:
|
||||
search: [q]
|
||||
tv-search: [q, season]
|
||||
movie-search: [q]
|
||||
|
||||
settings:
|
||||
- name: indexer
|
||||
type: select
|
||||
label: Indexer
|
||||
default: bludv
|
||||
options:
|
||||
bludv: BLUDV
|
||||
comando_torrents: Comando Torrents
|
||||
torrent-dos-filmes: Torrent dos Filmes
|
||||
comandohds: Comando HDs
|
||||
starck-filmes: Starck Filmes
|
||||
rede_torrent: Rede Torrent
|
||||
|
||||
search:
|
||||
paths:
|
||||
- path: "/indexers/{{ .Config.indexer }}"
|
||||
response:
|
||||
type: json
|
||||
inputs:
|
||||
filter_results: "true"
|
||||
q: "{{ .Keywords }}"
|
||||
keywordsfilters:
|
||||
- name: tolower
|
||||
- name: re_replace
|
||||
args: ["(?i)(S0)(\\d{1,2})$", "temporada $2"]
|
||||
- name: re_replace
|
||||
args: ["(?i)(S)(\\d{1,3})$", "temporada $2"]
|
||||
|
||||
rows:
|
||||
selector: $.results
|
||||
count:
|
||||
selector: $.count
|
||||
|
||||
fields:
|
||||
download:
|
||||
selector: magnet_link
|
||||
title:
|
||||
selector: title
|
||||
description:
|
||||
selector: original_title
|
||||
details:
|
||||
selector: details
|
||||
infohash:
|
||||
selector: info_hash
|
||||
date:
|
||||
selector: date
|
||||
size:
|
||||
selector: size
|
||||
seeders:
|
||||
selector: seed_count
|
||||
leechers:
|
||||
selector: leech_count
|
||||
imdb:
|
||||
selector: imdb
|
||||
category_is_tv_show:
|
||||
selector: title
|
||||
filters:
|
||||
- name: regexp
|
||||
args: "\\b(S\\d+(?:E\\d+)?)\\b"
|
||||
category:
|
||||
text: "{{ if .Result.category_is_tv_show }}TV{{ else }}Movies{{ end }}"
|
||||
```
|
||||
|
||||
# Warning
|
||||
|
||||
The instance running at [https://torrent-indexer.darklyn.org/](https://torrent-indexer.darklyn.org/) is my personal instance and it is not guaranteed to be up all the time. Also, for better availability, I recommend deploying your own instance because the Cloudflare protection may block requests from indexed sites if too many requests are made in a short period of time from the same IP.
|
||||
|
||||
If I notice that the instance is being used a lot, I may block requests from Jackett to avoid overloading the server without prior notice.
|
||||
If I notice that the instance is being used a lot, I may block requests from Jackett to avoid overloading the server without prior notice.
|
||||
|
||||
127
api/bludv.go
127
api/bludv.go
@@ -6,12 +6,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/hbollon/go-edlib"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
@@ -20,15 +18,19 @@ import (
|
||||
)
|
||||
|
||||
var bludv = IndexerMeta{
|
||||
URL: "https://bludv.xyz/",
|
||||
SearchURL: "?s=",
|
||||
Label: "bludv",
|
||||
URL: "https://bludv.xyz/",
|
||||
SearchURL: "?s=",
|
||||
PagePattern: "page/%s",
|
||||
}
|
||||
|
||||
func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := bludv
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues("bludv").Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues("bludv").Inc()
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
@@ -38,11 +40,11 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := bludv.URL
|
||||
url := metadata.URL
|
||||
if page != "" {
|
||||
url = fmt.Sprintf("%spage/%s", url, page)
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
} else {
|
||||
url = fmt.Sprintf("%s%s%s", url, bludv.SearchURL, q)
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
@@ -53,7 +55,7 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
@@ -66,7 +68,7 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,57 +79,21 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
var itChan = make(chan []schema.IndexedTorrent)
|
||||
var errChan = make(chan error)
|
||||
indexedTorrents := []schema.IndexedTorrent{}
|
||||
for _, link := range links {
|
||||
go func(link string) {
|
||||
torrents, err := getTorrentsBluDV(ctx, i, link)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
errChan <- err
|
||||
}
|
||||
itChan <- torrents
|
||||
}(link)
|
||||
}
|
||||
|
||||
for i := 0; i < len(links); i++ {
|
||||
select {
|
||||
case torrents := <-itChan:
|
||||
indexedTorrents = append(indexedTorrents, torrents...)
|
||||
case err := <-errChan:
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i, it := range indexedTorrents {
|
||||
jLower := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s %s", it.Title, it.OriginalTitle)), ".", " ")
|
||||
qLower := strings.ToLower(q)
|
||||
splitLength := 2
|
||||
indexedTorrents[i].Similarity = edlib.JaccardSimilarity(jLower, qLower, splitLength)
|
||||
}
|
||||
|
||||
// remove the ones with zero similarity
|
||||
if len(indexedTorrents) > 20 && r.URL.Query().Get("filter_results") != "" && r.URL.Query().Get("q") != "" {
|
||||
indexedTorrents = utils.Filter(indexedTorrents, func(it schema.IndexedTorrent) bool {
|
||||
return it.Similarity > 0
|
||||
})
|
||||
}
|
||||
|
||||
// sort by similarity
|
||||
slices.SortFunc(indexedTorrents, func(i, j schema.IndexedTorrent) int {
|
||||
return int((j.Similarity - i.Similarity) * 1000)
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrentsBluDV(ctx, i, link)
|
||||
})
|
||||
|
||||
// send to search index
|
||||
go func() {
|
||||
_ = i.search.IndexTorrents(indexedTorrents)
|
||||
}()
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: indexedTorrents,
|
||||
Count: len(indexedTorrents),
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -152,6 +118,30 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]schema.In
|
||||
magnetLinks = append(magnetLinks, magnetLink)
|
||||
})
|
||||
|
||||
adwareLinks := textContent.Find("a[href^=\"https://www.seuvideo.xyz\"]")
|
||||
adwareLinks.Each(func(_ int, s *goquery.Selection) {
|
||||
href, _ := s.Attr("href")
|
||||
// extract querysting "id" from url
|
||||
parsedUrl, err := url.Parse(href)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
magnetLink := parsedUrl.Query().Get("id")
|
||||
magnetLinkDecoded, err := utils.DecodeAdLink(magnetLink)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to decode ad link \"%s\": %v\n", href, err)
|
||||
return
|
||||
}
|
||||
|
||||
// if decoded magnet link is indeed a magnet link, append it
|
||||
if strings.HasPrefix(magnetLinkDecoded, "magnet:") {
|
||||
magnetLinks = append(magnetLinks, magnetLinkDecoded)
|
||||
} else if !strings.Contains(magnetLinkDecoded, "watch.brplayer") {
|
||||
fmt.Printf("WARN: link \"%s\" decoding resulted in non-magnet link: %s\n", href, magnetLinkDecoded)
|
||||
}
|
||||
})
|
||||
|
||||
var audio []schema.Audio
|
||||
var year string
|
||||
var size []string
|
||||
@@ -192,7 +182,7 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]schema.In
|
||||
}
|
||||
})
|
||||
|
||||
size = stableUniq(size)
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
@@ -207,19 +197,7 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]schema.In
|
||||
releaseTitle := magnet.DisplayName
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
magnetAudio := []schema.Audio{}
|
||||
if strings.Contains(strings.ToLower(releaseTitle), "dual") || strings.Contains(strings.ToLower(releaseTitle), "dublado") {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
} else if len(audio) > 1 {
|
||||
// remove portuguese audio, and append to magnetAudio
|
||||
for _, a := range audio {
|
||||
if a != schema.AudioPortuguese {
|
||||
magnetAudio = append(magnetAudio, a)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
}
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
@@ -233,9 +211,14 @@ func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]schema.In
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: appendAudioISO639_2Code(releaseTitle, magnetAudio),
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -18,12 +15,13 @@ import (
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
goscrape "github.com/felipemarinho97/torrent-indexer/scrape"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
"github.com/hbollon/go-edlib"
|
||||
)
|
||||
|
||||
var comando = IndexerMeta{
|
||||
URL: "https://comando.la/",
|
||||
SearchURL: "?s=",
|
||||
Label: "comando",
|
||||
URL: "https://comando.la/",
|
||||
SearchURL: "?s=",
|
||||
PagePattern: "page/%s",
|
||||
}
|
||||
|
||||
var replacer = strings.NewReplacer(
|
||||
@@ -43,9 +41,11 @@ var replacer = strings.NewReplacer(
|
||||
|
||||
func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := comando
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues("comando").Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues("comando").Inc()
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
@@ -55,11 +55,11 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := comando.URL
|
||||
url := metadata.URL
|
||||
if q != "" {
|
||||
url = fmt.Sprintf("%s%s%s", url, comando.SearchURL, q)
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
} else if page != "" {
|
||||
url = fmt.Sprintf("%spage/%s", url, page)
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
@@ -70,7 +70,7 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
@@ -82,7 +82,7 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,57 +93,21 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
var itChan = make(chan []schema.IndexedTorrent)
|
||||
var errChan = make(chan error)
|
||||
indexedTorrents := []schema.IndexedTorrent{}
|
||||
for _, link := range links {
|
||||
go func(link string) {
|
||||
torrents, err := getTorrents(ctx, i, link)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
errChan <- err
|
||||
}
|
||||
itChan <- torrents
|
||||
}(link)
|
||||
}
|
||||
|
||||
for i := 0; i < len(links); i++ {
|
||||
select {
|
||||
case torrents := <-itChan:
|
||||
indexedTorrents = append(indexedTorrents, torrents...)
|
||||
case err := <-errChan:
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i, it := range indexedTorrents {
|
||||
jLower := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s %s", it.Title, it.OriginalTitle)), ".", " ")
|
||||
qLower := strings.ToLower(q)
|
||||
splitLength := 2
|
||||
indexedTorrents[i].Similarity = edlib.JaccardSimilarity(jLower, qLower, splitLength)
|
||||
}
|
||||
|
||||
// remove the ones with zero similarity
|
||||
if len(indexedTorrents) > 20 && r.URL.Query().Get("filter_results") != "" && r.URL.Query().Get("q") != "" {
|
||||
indexedTorrents = utils.Filter(indexedTorrents, func(it schema.IndexedTorrent) bool {
|
||||
return it.Similarity > 0
|
||||
})
|
||||
}
|
||||
|
||||
// sort by similarity
|
||||
slices.SortFunc(indexedTorrents, func(i, j schema.IndexedTorrent) int {
|
||||
return int((j.Similarity - i.Similarity) * 1000)
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrents(ctx, i, link)
|
||||
})
|
||||
|
||||
// send to search index
|
||||
go func() {
|
||||
_ = i.search.IndexTorrents(indexedTorrents)
|
||||
}()
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: indexedTorrents,
|
||||
Count: len(indexedTorrents),
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -215,7 +179,7 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]schema.Indexed
|
||||
}
|
||||
})
|
||||
|
||||
size = stableUniq(size)
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
@@ -230,19 +194,7 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]schema.Indexed
|
||||
releaseTitle := magnet.DisplayName
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
magnetAudio := []schema.Audio{}
|
||||
if strings.Contains(strings.ToLower(releaseTitle), "dual") || strings.Contains(strings.ToLower(releaseTitle), "dublado") {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
} else if len(audio) > 1 {
|
||||
// remove portuguese audio, and append to magnetAudio
|
||||
for _, a := range audio {
|
||||
if a != schema.AudioPortuguese {
|
||||
magnetAudio = append(magnetAudio, a)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
}
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
@@ -256,9 +208,14 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]schema.Indexed
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: appendAudioISO639_2Code(releaseTitle, magnetAudio),
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
@@ -284,19 +241,6 @@ func getTorrents(ctx context.Context, i *Indexer, link string) ([]schema.Indexed
|
||||
return indexedTorrents, nil
|
||||
}
|
||||
|
||||
func getIMDBLink(link string) (string, error) {
|
||||
var imdbLink string
|
||||
re := regexp.MustCompile(`https://www.imdb.com(/[a-z]{2})?/title/(tt\d+)/?`)
|
||||
|
||||
matches := re.FindStringSubmatch(link)
|
||||
if len(matches) > 0 {
|
||||
imdbLink = matches[0]
|
||||
} else {
|
||||
return "", fmt.Errorf("no imdb link found")
|
||||
}
|
||||
return imdbLink, nil
|
||||
}
|
||||
|
||||
func parseLocalizedDate(datePublished string) (time.Time, error) {
|
||||
re := regexp.MustCompile(`(\d{1,2}) de (\w+) de (\d{4})`)
|
||||
matches := re.FindStringSubmatch(datePublished)
|
||||
@@ -318,88 +262,6 @@ func parseLocalizedDate(datePublished string) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
func stableUniq(s []string) []string {
|
||||
var uniq []map[string]interface{}
|
||||
m := make(map[string]map[string]interface{})
|
||||
for i, v := range s {
|
||||
m[v] = map[string]interface{}{
|
||||
"v": v,
|
||||
"i": i,
|
||||
}
|
||||
}
|
||||
// to order by index
|
||||
for _, v := range m {
|
||||
uniq = append(uniq, v)
|
||||
}
|
||||
|
||||
// sort by index
|
||||
for i := 0; i < len(uniq); i++ {
|
||||
for j := i + 1; j < len(uniq); j++ {
|
||||
if uniq[i]["i"].(int) > uniq[j]["i"].(int) {
|
||||
uniq[i], uniq[j] = uniq[j], uniq[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get only values
|
||||
var uniqValues []string
|
||||
for _, v := range uniq {
|
||||
uniqValues = append(uniqValues, v["v"].(string))
|
||||
}
|
||||
|
||||
return uniqValues
|
||||
}
|
||||
|
||||
func findYearFromText(text string, title string) (year string) {
|
||||
re := regexp.MustCompile(`Lançamento: (.*)`)
|
||||
yearMatch := re.FindStringSubmatch(text)
|
||||
if len(yearMatch) > 0 {
|
||||
year = yearMatch[1]
|
||||
}
|
||||
|
||||
if year == "" {
|
||||
re = regexp.MustCompile(`\((\d{4})\)`)
|
||||
yearMatch := re.FindStringSubmatch(title)
|
||||
if len(yearMatch) > 0 {
|
||||
year = yearMatch[1]
|
||||
}
|
||||
}
|
||||
return year
|
||||
}
|
||||
|
||||
func findAudioFromText(text string) []schema.Audio {
|
||||
var audio []schema.Audio
|
||||
re := regexp.MustCompile(`(.udio|Idioma):.?(.*)`)
|
||||
audioMatch := re.FindStringSubmatch(text)
|
||||
if len(audioMatch) > 0 {
|
||||
sep := getSeparator(audioMatch[2])
|
||||
langs_raw := strings.Split(audioMatch[2], sep)
|
||||
for _, lang := range langs_raw {
|
||||
lang = strings.TrimSpace(lang)
|
||||
a := schema.GetAudioFromString(lang)
|
||||
if a != nil {
|
||||
audio = append(audio, *a)
|
||||
} else {
|
||||
fmt.Println("unknown language:", lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
return audio
|
||||
}
|
||||
|
||||
func findSizesFromText(text string) []string {
|
||||
var sizes []string
|
||||
// everything that ends with GB or MB, using ',' or '.' as decimal separator
|
||||
re := regexp.MustCompile(`(\d+[\.,]?\d+) ?(GB|MB)`)
|
||||
sizesMatch := re.FindAllStringSubmatch(text, -1)
|
||||
if len(sizesMatch) > 0 {
|
||||
for _, size := range sizesMatch {
|
||||
sizes = append(sizes, size[0])
|
||||
}
|
||||
}
|
||||
return sizes
|
||||
}
|
||||
|
||||
func processTitle(title string, a []schema.Audio) string {
|
||||
// remove ' - Donwload' from title
|
||||
title = strings.Replace(title, " – Download", "", -1)
|
||||
@@ -412,58 +274,3 @@ func processTitle(title string, a []schema.Audio) string {
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
func appendAudioISO639_2Code(title string, a []schema.Audio) string {
|
||||
if len(a) > 0 {
|
||||
audio := []string{}
|
||||
for _, lang := range a {
|
||||
audio = append(audio, lang.String())
|
||||
}
|
||||
title = fmt.Sprintf("%s (%s)", title, strings.Join(audio, ", "))
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
func getSeparator(s string) string {
|
||||
if strings.Contains(s, "|") {
|
||||
return "|"
|
||||
} else if strings.Contains(s, ",") {
|
||||
return ","
|
||||
}
|
||||
return " "
|
||||
}
|
||||
|
||||
func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Document, error) {
|
||||
// try to get from redis first
|
||||
docCache, err := i.redis.Get(ctx, link)
|
||||
if err == nil {
|
||||
i.metrics.CacheHits.WithLabelValues("document_body").Inc()
|
||||
fmt.Printf("returning from long-lived cache: %s\n", link)
|
||||
return goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(docCache)))
|
||||
}
|
||||
defer i.metrics.CacheMisses.WithLabelValues("document_body").Inc()
|
||||
|
||||
resp, err := i.requester.GetDocument(ctx, link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
body, err := io.ReadAll(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set cache
|
||||
err = i.redis.Set(ctx, link, body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(body)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
@@ -4,81 +4,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
)
|
||||
|
||||
func Test_findAudioFromText(t *testing.T) {
|
||||
type args struct {
|
||||
text string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []schema.Audio
|
||||
}{
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Áudio: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Idioma: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Audio: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: `
|
||||
»INFORMAÇÕES«
|
||||
Título Traduzido: O Cangaceiro do Futuro
|
||||
Título Original: O Cangaceiro do Futuro
|
||||
IMDb: 7,1
|
||||
Gênero:Comédia
|
||||
Lançamento: 2022
|
||||
Qualidade: WEB-DL
|
||||
Áudio: Português
|
||||
Legenda: S/L
|
||||
Formato: MKV
|
||||
Tamanho: 5.77 GB | 9.60 GB
|
||||
Duração: 30 Min./Ep.
|
||||
Qualidade de Áudio: 10
|
||||
Qualidade de Vídeo: 10
|
||||
Servidor Via: Torrent
|
||||
`,
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := findAudioFromText(tt.args.text); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("findAudioFromText() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_parseLocalizedDate(t *testing.T) {
|
||||
type args struct {
|
||||
datePublished string
|
||||
@@ -119,74 +46,3 @@ func Test_parseLocalizedDate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getIMDBLink(t *testing.T) {
|
||||
type args struct {
|
||||
link string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should return imdb link",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
{
|
||||
name: "should return error when link is invalid",
|
||||
args: args{
|
||||
link: "https://www.google.com",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getIMDBLink(tt.args.link)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getIMDBLink() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("getIMDBLink() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
226
api/comandohds.go
Normal file
226
api/comandohds.go
Normal file
@@ -0,0 +1,226 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
goscrape "github.com/felipemarinho97/torrent-indexer/scrape"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
var comandohds = IndexerMeta{
|
||||
Label: "comandohds",
|
||||
URL: "https://comandohds.org/",
|
||||
SearchURL: "?s=",
|
||||
PagePattern: "page/%s",
|
||||
}
|
||||
|
||||
var title_re = regexp.MustCompile(`^[(Filme)|(Série)\s]+`)
|
||||
|
||||
func (i *Indexer) HandlerComandoHDsIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := comandohds
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
// supported query params: q, page, filter_results
|
||||
q := r.URL.Query().Get("q")
|
||||
page := r.URL.Query().Get("page")
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := metadata.URL
|
||||
if q != "" {
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
} else if page != "" {
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
resp, err := i.requester.GetDocument(ctx, url)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
var links []string
|
||||
doc.Find(".post").Each(func(i int, s *goquery.Selection) {
|
||||
link, _ := s.Find("div.title > a").Attr("href")
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrentsComandoHDs(ctx, i, link)
|
||||
})
|
||||
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getTorrentsComandoHDs(ctx context.Context, i *Indexer, link string) ([]schema.IndexedTorrent, error) {
|
||||
var indexedTorrents []schema.IndexedTorrent
|
||||
doc, err := getDocument(ctx, i, link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
article := doc.Find("article")
|
||||
title := title_re.ReplaceAllString(article.Find(".main_title > h1").Text(), "")
|
||||
textContent := article.Find("div.content")
|
||||
date := getPublishedDateFromMeta(doc)
|
||||
magnets := textContent.Find("a[href^=\"magnet\"]")
|
||||
var magnetLinks []string
|
||||
magnets.Each(func(i int, s *goquery.Selection) {
|
||||
magnetLink, _ := s.Attr("href")
|
||||
magnetLinks = append(magnetLinks, magnetLink)
|
||||
})
|
||||
|
||||
var audio []schema.Audio
|
||||
var year string
|
||||
var size []string
|
||||
article.Find("div.content p").Each(func(i int, s *goquery.Selection) {
|
||||
// pattern:
|
||||
// »INFORMAÇÕES«
|
||||
// Titulo Traduzido: O Guerreiro Banido
|
||||
// Titulo Original: 天龍八部之喬峰傳
|
||||
// <picture />: 5.7
|
||||
// Ano de Lançamento: 2023
|
||||
// Gênero: Ação
|
||||
// Formato: MKV
|
||||
// Qualidade: WEB-DL
|
||||
// Idioma: Português | Inglês
|
||||
// Legenda: Português
|
||||
// Tamanho: – GB
|
||||
// Qualidade Áudio e Vídeo: 10
|
||||
// Duração: 130 Min
|
||||
// Servidor: Torrent
|
||||
text := s.Text()
|
||||
|
||||
audio = append(audio, findAudioFromText(text)...)
|
||||
y := findYearFromText(text, title)
|
||||
if y != "" {
|
||||
year = y
|
||||
}
|
||||
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")
|
||||
_imdbLink, err := getIMDBLink(link)
|
||||
if err == nil {
|
||||
imdbLink = _imdbLink
|
||||
}
|
||||
})
|
||||
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
// for each magnet link, create a new indexed torrent
|
||||
for it, magnetLink := range magnetLinks {
|
||||
it := it
|
||||
go func(it int, magnetLink string) {
|
||||
magnet, err := magnet.ParseMagnetUri(magnetLink)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
releaseTitle := strings.TrimSpace(magnet.DisplayName)
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
for i, tracker := range trackers {
|
||||
trackers[i] = strings.TrimSpace(tracker)
|
||||
}
|
||||
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
title := processTitle(title, magnetAudio)
|
||||
|
||||
// if the number of sizes is equal to the number of magnets, then assign the size to each indexed torrent in order
|
||||
var mySize string
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
IMDB: imdbLink,
|
||||
Audio: magnetAudio,
|
||||
MagnetLink: magnetLink,
|
||||
Date: date,
|
||||
InfoHash: infoHash,
|
||||
Trackers: trackers,
|
||||
LeechCount: peer,
|
||||
SeedCount: seed,
|
||||
Size: mySize,
|
||||
}
|
||||
chanIndexedTorrent <- ixt
|
||||
}(it, magnetLink)
|
||||
}
|
||||
|
||||
for i := 0; i < len(magnetLinks); i++ {
|
||||
it := <-chanIndexedTorrent
|
||||
indexedTorrents = append(indexedTorrents, it)
|
||||
}
|
||||
|
||||
return indexedTorrents, nil
|
||||
}
|
||||
227
api/common.go
Normal file
227
api/common.go
Normal file
@@ -0,0 +1,227 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
)
|
||||
|
||||
// getDocument retrieves a document from the cache or makes a request to get it.
|
||||
// It first checks the Redis cache for the document body.
|
||||
func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Document, error) {
|
||||
// try to get from redis first
|
||||
docCache, err := i.redis.Get(ctx, link)
|
||||
if err == nil {
|
||||
i.metrics.CacheHits.WithLabelValues("document_body").Inc()
|
||||
fmt.Printf("returning from long-lived cache: %s\n", link)
|
||||
return goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(docCache)))
|
||||
}
|
||||
defer i.metrics.CacheMisses.WithLabelValues("document_body").Inc()
|
||||
|
||||
resp, err := i.requester.GetDocument(ctx, link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
body, err := io.ReadAll(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set cache
|
||||
err = i.redis.Set(ctx, link, body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(body)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func getPublishedDateFromMeta(document *goquery.Document) time.Time {
|
||||
var date time.Time
|
||||
//<meta property="article:published_time" content="2019-08-23T13:20:57+00:00">
|
||||
datePublished := strings.TrimSpace(document.Find("meta[property=\"article:published_time\"]").AttrOr("content", ""))
|
||||
|
||||
if datePublished != "" {
|
||||
date, _ = time.Parse(time.RFC3339, datePublished)
|
||||
}
|
||||
|
||||
return date
|
||||
}
|
||||
|
||||
type datePattern struct {
|
||||
regex *regexp.Regexp
|
||||
layout string
|
||||
}
|
||||
|
||||
var datePatterns = []datePattern{
|
||||
{regexp.MustCompile(`\d{4}-\d{2}-\d{2}`), "2006-01-02"},
|
||||
{regexp.MustCompile(`\d{2}-\d{2}-\d{4}`), "02-01-2006"},
|
||||
{regexp.MustCompile(`\d{2}/\d{2}/\d{4}`), "02/01/2006"},
|
||||
}
|
||||
|
||||
// getPublishedDateFromRawString extracts the date from a raw string using predefined patterns.
|
||||
func getPublishedDateFromRawString(dateStr string) time.Time {
|
||||
for _, p := range datePatterns {
|
||||
match := p.regex.FindString(dateStr)
|
||||
|
||||
if match != "" {
|
||||
date, err := time.Parse(p.layout, match)
|
||||
if err == nil {
|
||||
return date.UTC()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
// getSeparator returns the separator used in the string.
|
||||
// It checks for common separators like "|", ",", "/", and " e "
|
||||
func getSeparator(s string) string {
|
||||
if strings.Contains(s, "|") {
|
||||
return "|"
|
||||
} else if strings.Contains(s, ",") {
|
||||
return ","
|
||||
} else if strings.Contains(s, "/") {
|
||||
return "/"
|
||||
} else if strings.Contains(s, " e ") {
|
||||
return " e "
|
||||
}
|
||||
return " "
|
||||
}
|
||||
|
||||
// findAudioFromText extracts audio languages from a given text.
|
||||
// It looks for patterns like "Áudio: Português, Inglês" or "Idioma: Português, Inglês"
|
||||
func findAudioFromText(text string) []schema.Audio {
|
||||
var audio []schema.Audio
|
||||
re := regexp.MustCompile(`(.udio|Idioma):.?(.*)`)
|
||||
audioMatch := re.FindStringSubmatch(text)
|
||||
if len(audioMatch) > 0 {
|
||||
sep := getSeparator(audioMatch[2])
|
||||
langs_raw := strings.Split(audioMatch[2], sep)
|
||||
for _, lang := range langs_raw {
|
||||
lang = strings.TrimSpace(lang)
|
||||
a := schema.GetAudioFromString(lang)
|
||||
if a != nil {
|
||||
audio = append(audio, *a)
|
||||
} else {
|
||||
fmt.Println("unknown language:", lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
return audio
|
||||
}
|
||||
|
||||
// findYearFromText extracts the year from a given text.
|
||||
// It looks for patterns like "Lançamento: 2001" in the title.
|
||||
func findYearFromText(text string, title string) (year string) {
|
||||
re := regexp.MustCompile(`Lançamento: (.*)`)
|
||||
yearMatch := re.FindStringSubmatch(text)
|
||||
if len(yearMatch) > 0 {
|
||||
year = yearMatch[1]
|
||||
}
|
||||
|
||||
if year == "" {
|
||||
re = regexp.MustCompile(`\((\d{4})\)`)
|
||||
yearMatch := re.FindStringSubmatch(title)
|
||||
if len(yearMatch) > 0 {
|
||||
year = yearMatch[1]
|
||||
}
|
||||
}
|
||||
return strings.TrimSpace(year)
|
||||
}
|
||||
|
||||
// findSizesFromText extracts sizes from a given text.
|
||||
// It looks for patterns like "Tamanho: 1.26 GB" or "Tamanho: 700 MB".
|
||||
func findSizesFromText(text string) []string {
|
||||
var sizes []string
|
||||
// everything that ends with GB or MB, using ',' or '.' as decimal separator
|
||||
re := regexp.MustCompile(`(\d+[\.,]?\d+) ?(GB|MB)`)
|
||||
sizesMatch := re.FindAllStringSubmatch(text, -1)
|
||||
if len(sizesMatch) > 0 {
|
||||
for _, size := range sizesMatch {
|
||||
sizes = append(sizes, size[0])
|
||||
}
|
||||
}
|
||||
return sizes
|
||||
}
|
||||
|
||||
// getIMDBLink extracts the IMDB link from a given link.
|
||||
// It looks for patterns like "https://www.imdb.com/title/tt1234567/".
|
||||
// Returns an error if no valid IMDB link is found.
|
||||
func getIMDBLink(link string) (string, error) {
|
||||
var imdbLink string
|
||||
re := regexp.MustCompile(`https://www.imdb.com(/[a-z]{2})?/title/(tt\d+)/?`)
|
||||
|
||||
matches := re.FindStringSubmatch(link)
|
||||
if len(matches) > 0 {
|
||||
imdbLink = matches[0]
|
||||
} else {
|
||||
return "", fmt.Errorf("no imdb link found")
|
||||
}
|
||||
return imdbLink, nil
|
||||
}
|
||||
|
||||
// appendAudioISO639_2Code appends the audio languages to the title in ISO 639-2 code format.
|
||||
// It formats the title to include the audio languages in parentheses.
|
||||
// Example: "Movie Title (eng, por)"
|
||||
func appendAudioISO639_2Code(title string, a []schema.Audio) string {
|
||||
if len(a) > 0 {
|
||||
audio := []string{}
|
||||
for _, lang := range a {
|
||||
audio = append(audio, lang.String())
|
||||
}
|
||||
title = fmt.Sprintf("%s (%s)", title, strings.Join(audio, ", "))
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
// getAudioFromTitle extracts audio languages from the release title.
|
||||
// It checks for common patterns like "nacional", "dual", or "dublado"
|
||||
func getAudioFromTitle(releaseTitle string, audioFromContent []schema.Audio) []schema.Audio {
|
||||
magnetAudio := []schema.Audio{}
|
||||
isNacional := strings.Contains(strings.ToLower(releaseTitle), "nacional")
|
||||
if isNacional {
|
||||
magnetAudio = append(magnetAudio, schema.AudioPortuguese)
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(releaseTitle), "dual") || strings.Contains(strings.ToLower(releaseTitle), "dublado") {
|
||||
magnetAudio = append(magnetAudio, audioFromContent...)
|
||||
// if Portuguese audio is not in the audio slice, append it
|
||||
if !slices.Contains(magnetAudio, schema.AudioPortuguese) {
|
||||
magnetAudio = append(magnetAudio, schema.AudioPortuguese)
|
||||
}
|
||||
} else if len(audioFromContent) > 1 {
|
||||
// remove portuguese audio, and append to magnetAudio
|
||||
for _, a := range audioFromContent {
|
||||
if a != schema.AudioPortuguese {
|
||||
magnetAudio = append(magnetAudio, a)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
magnetAudio = append(magnetAudio, audioFromContent...)
|
||||
}
|
||||
|
||||
// order and uniq the audio slice
|
||||
slices.SortFunc(magnetAudio, func(a, b schema.Audio) int {
|
||||
return strings.Compare(a.String(), b.String())
|
||||
})
|
||||
magnetAudio = slices.Compact(magnetAudio)
|
||||
|
||||
return magnetAudio
|
||||
}
|
||||
241
api/common_test.go
Normal file
241
api/common_test.go
Normal file
@@ -0,0 +1,241 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
)
|
||||
|
||||
func Test_getPublishedDateFromRawString(t *testing.T) {
|
||||
type args struct {
|
||||
dateStr string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want time.Time
|
||||
}{
|
||||
{
|
||||
name: "should parse date in format 2025-01-01",
|
||||
args: args{
|
||||
dateStr: "2025-01-01",
|
||||
},
|
||||
want: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
name: "should parse date in format 01-01-2025",
|
||||
args: args{
|
||||
dateStr: "01-01-2025",
|
||||
},
|
||||
want: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
name: "should parse date in format 01/01/2025",
|
||||
args: args{
|
||||
dateStr: "01/01/2025",
|
||||
},
|
||||
want: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
name: "should parse date from starck-filmes link",
|
||||
args: args{
|
||||
dateStr: "https://www.starckfilmes.online/catalog/jogos-de-seducao-2025-18-07-2025/",
|
||||
},
|
||||
want: time.Date(2025, 7, 18, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := getPublishedDateFromRawString(tt.args.dateStr); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("getPublishedDateFromRawString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_findAudioFromText(t *testing.T) {
|
||||
type args struct {
|
||||
text string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []schema.Audio
|
||||
}{
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Áudio: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Idioma: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese",
|
||||
args: args{
|
||||
text: "Audio: Português",
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese - comando_torrents",
|
||||
args: args{
|
||||
text: `
|
||||
»INFORMAÇÕES«
|
||||
Título Traduzido: O Cangaceiro do Futuro
|
||||
Título Original: O Cangaceiro do Futuro
|
||||
IMDb: 7,1
|
||||
Gênero:Comédia
|
||||
Lançamento: 2022
|
||||
Qualidade: WEB-DL
|
||||
Áudio: Português
|
||||
Legenda: S/L
|
||||
Formato: MKV
|
||||
Tamanho: 5.77 GB | 9.60 GB
|
||||
Duração: 30 Min./Ep.
|
||||
Qualidade de Áudio: 10
|
||||
Qualidade de Vídeo: 10
|
||||
Servidor Via: Torrent
|
||||
`,
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese - rede torrent",
|
||||
args: args{
|
||||
text: `
|
||||
Filme Bicho de Sete Cabeças Torrent
|
||||
Título Original: Bicho de Sete Cabeças
|
||||
Lançamento: 2001
|
||||
Gêneros: Drama / Nacional
|
||||
Idioma: Português
|
||||
Qualidade: 720p / BluRay
|
||||
Duração: 1h 14 Minutos
|
||||
Formato: Mp4
|
||||
Vídeo: 10 e Áudio: 10
|
||||
Legendas: Português
|
||||
Nota do Imdb: 7.7
|
||||
Tamanho: 1.26 GB
|
||||
`,
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should return audio in portuguese - rede torrent 2",
|
||||
args: args{
|
||||
text: `
|
||||
Filme Branca de Neve e o Caçador Torrent / Assistir Online
|
||||
Título Original: Snow White and the Huntsman
|
||||
Lançamento: 2012
|
||||
Gêneros: Ação / Aventura / Fantasia
|
||||
Idioma: Português / Inglês
|
||||
Duração: 126 Minutos
|
||||
Formato: Mkv / Mp4
|
||||
Vídeo: 10 e Áudio: 10
|
||||
Legendas: Sim
|
||||
Tamanho: 2.69 GB / 1.95 GB / 1.0 GB
|
||||
`,
|
||||
},
|
||||
want: []schema.Audio{
|
||||
schema.AudioPortuguese,
|
||||
schema.AudioEnglish,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := findAudioFromText(tt.args.text); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("findAudioFromText() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getIMDBLink(t *testing.T) {
|
||||
type args struct {
|
||||
link string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should return imdb link",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when end with /",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/title/tt1234567/",
|
||||
},
|
||||
want: "https://www.imdb.com/title/tt1234567/",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt18722864/",
|
||||
},
|
||||
{
|
||||
name: "should return imdb link when it has a language",
|
||||
args: args{
|
||||
link: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
want: "https://www.imdb.com/pt/title/tt34608980/",
|
||||
},
|
||||
{
|
||||
name: "should return error when link is invalid",
|
||||
args: args{
|
||||
link: "https://www.google.com",
|
||||
},
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getIMDBLink(tt.args.link)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getIMDBLink() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("getIMDBLink() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
88
api/index.go
88
api/index.go
@@ -6,6 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/cache"
|
||||
"github.com/felipemarinho97/torrent-indexer/consts"
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/monitoring"
|
||||
"github.com/felipemarinho97/torrent-indexer/requester"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
@@ -13,15 +15,19 @@ import (
|
||||
)
|
||||
|
||||
type Indexer struct {
|
||||
redis *cache.Redis
|
||||
metrics *monitoring.Metrics
|
||||
requester *requester.Requster
|
||||
search *meilisearch.SearchIndexer
|
||||
redis *cache.Redis
|
||||
metrics *monitoring.Metrics
|
||||
requester *requester.Requster
|
||||
search *meilisearch.SearchIndexer
|
||||
magnetMetadataAPI *magnet.MetadataClient
|
||||
postProcessors []PostProcessorFunc
|
||||
}
|
||||
|
||||
type IndexerMeta struct {
|
||||
URL string
|
||||
SearchURL string
|
||||
Label string // Label is used for Prometheus metrics and logging. Must be alphanumeric optionally with underscores.
|
||||
URL string // URL is the base URL of the indexer, e.g. "https://example.com/"
|
||||
SearchURL string // SearchURL is the base URL for search queries, e.g. "?s="
|
||||
PagePattern string // PagePattern for pagination, e.g. "page/%s"
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
@@ -29,12 +35,30 @@ type Response struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
func NewIndexers(redis *cache.Redis, metrics *monitoring.Metrics, req *requester.Requster, si *meilisearch.SearchIndexer) *Indexer {
|
||||
type PostProcessorFunc func(*Indexer, *http.Request, []schema.IndexedTorrent) []schema.IndexedTorrent
|
||||
|
||||
var GlobalPostProcessors = []PostProcessorFunc{
|
||||
AddSimilarityCheck, // Jaccard similarity
|
||||
FullfilMissingMetadata, // Fill missing size or title metadata
|
||||
CleanupTitleWebsites, // Remove website names from titles
|
||||
AppendAudioTags, // Add (brazilian, eng, etc.) audio tags to titles
|
||||
SendToSearchIndexer, // Send indexed torrents to Meilisearch
|
||||
}
|
||||
|
||||
func NewIndexers(
|
||||
redis *cache.Redis,
|
||||
metrics *monitoring.Metrics,
|
||||
req *requester.Requster,
|
||||
si *meilisearch.SearchIndexer,
|
||||
mc *magnet.MetadataClient,
|
||||
) *Indexer {
|
||||
return &Indexer{
|
||||
redis: redis,
|
||||
metrics: metrics,
|
||||
requester: req,
|
||||
search: si,
|
||||
redis: redis,
|
||||
metrics: metrics,
|
||||
requester: req,
|
||||
search: si,
|
||||
magnetMetadataAPI: mc,
|
||||
postProcessors: GlobalPostProcessors,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +67,8 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
err := json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"time": currentTime,
|
||||
"time": currentTime,
|
||||
"build": consts.GetBuildInfo(),
|
||||
"endpoints": map[string]interface{}{
|
||||
"/indexers/comando_torrents": []map[string]interface{}{
|
||||
{
|
||||
@@ -77,6 +102,39 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
||||
},
|
||||
},
|
||||
},
|
||||
"/indexers/comandohds": []map[string]interface{}{
|
||||
{
|
||||
"method": "GET",
|
||||
"page": "page number",
|
||||
"description": "Indexer for Comando HDs",
|
||||
"query_params": map[string]string{
|
||||
"q": "search query",
|
||||
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
||||
},
|
||||
},
|
||||
},
|
||||
"/indexers/starck-filmes": []map[string]interface{}{
|
||||
{
|
||||
"method": "GET",
|
||||
"page": "page number",
|
||||
"description": "Indexer for Starck Filmes",
|
||||
"query_params": map[string]string{
|
||||
"q": "search query",
|
||||
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
||||
},
|
||||
},
|
||||
},
|
||||
"/indexers/rede_torrent": []map[string]interface{}{
|
||||
{
|
||||
"method": "GET",
|
||||
"description": "Indexer for rede torrent",
|
||||
"query_params": map[string]string{
|
||||
"q": "search query",
|
||||
"page": "page number",
|
||||
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
||||
},
|
||||
},
|
||||
},
|
||||
"/indexers/manual": []map[string]interface{}{
|
||||
{
|
||||
"method": "POST",
|
||||
@@ -98,6 +156,12 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
||||
},
|
||||
},
|
||||
},
|
||||
"/ui/": []map[string]interface{}{
|
||||
{
|
||||
"method": "GET",
|
||||
"description": "Show the unified search UI (only work if Meilisearch is enabled)",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
@@ -76,19 +75,7 @@ func (i *Indexer) HandlerManualIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
releaseTitle := magnet.DisplayName
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
magnetAudio := []schema.Audio{}
|
||||
if strings.Contains(strings.ToLower(releaseTitle), "dual") || strings.Contains(strings.ToLower(releaseTitle), "dublado") {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
} else if len(audio) > 1 {
|
||||
// remove portuguese audio, and append to magnetAudio
|
||||
for _, a := range audio {
|
||||
if a != schema.AudioPortuguese {
|
||||
magnetAudio = append(magnetAudio, a)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
}
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
|
||||
100
api/post_processors.go
Normal file
100
api/post_processors.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
"github.com/hbollon/go-edlib"
|
||||
)
|
||||
|
||||
// CleanupTitleWebsites removes unwanted characters from the title
|
||||
func CleanupTitleWebsites(_ *Indexer, _ *http.Request, torrents []schema.IndexedTorrent) []schema.IndexedTorrent {
|
||||
for i := range torrents {
|
||||
torrents[i].Title = utils.RemoveKnownWebsites(torrents[i].Title)
|
||||
}
|
||||
return torrents
|
||||
}
|
||||
|
||||
func AppendAudioTags(_ *Indexer, _ *http.Request, torrents []schema.IndexedTorrent) []schema.IndexedTorrent {
|
||||
for i, it := range torrents {
|
||||
torrents[i].Title = appendAudioISO639_2Code(torrents[i].Title, it.Audio)
|
||||
}
|
||||
|
||||
return torrents
|
||||
}
|
||||
|
||||
// SendToSearchIndexer sends the indexed torrents to the search indexer
|
||||
func SendToSearchIndexer(i *Indexer, _ *http.Request, torrents []schema.IndexedTorrent) []schema.IndexedTorrent {
|
||||
go func() {
|
||||
_ = i.search.IndexTorrents(torrents)
|
||||
}()
|
||||
return torrents
|
||||
}
|
||||
|
||||
// FullfilMissingMetadata fills in missing metadata for indexed torrents
|
||||
func FullfilMissingMetadata(i *Indexer, r *http.Request, torrents []schema.IndexedTorrent) []schema.IndexedTorrent {
|
||||
if !i.magnetMetadataAPI.IsEnabled() {
|
||||
return torrents
|
||||
}
|
||||
|
||||
return utils.ParallelFlatMap(torrents, func(it schema.IndexedTorrent) ([]schema.IndexedTorrent, error) {
|
||||
if it.Size != "" && it.Title != "" && it.OriginalTitle != "" {
|
||||
return []schema.IndexedTorrent{it}, nil
|
||||
}
|
||||
m, err := i.magnetMetadataAPI.FetchMetadata(r.Context(), it.MagnetLink)
|
||||
if err != nil {
|
||||
return []schema.IndexedTorrent{it}, nil
|
||||
}
|
||||
|
||||
// convert size in bytes to a human-readable format
|
||||
it.Size = utils.FormatBytes(m.Size)
|
||||
|
||||
// Use name from metadata if available as it is more accurate
|
||||
if m.Name != "" {
|
||||
it.Title = m.Name
|
||||
}
|
||||
fmt.Printf("hash: %s get -> size: %s\n", m.InfoHash, it.Size)
|
||||
|
||||
// If files are present, add them to the indexed torrent
|
||||
if len(m.Files) > 0 {
|
||||
it.Files = make([]schema.File, len(m.Files))
|
||||
for i, file := range m.Files {
|
||||
it.Files[i] = schema.File{
|
||||
Path: file.Path,
|
||||
Size: utils.FormatBytes(file.Size),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return []schema.IndexedTorrent{it}, nil
|
||||
})
|
||||
}
|
||||
|
||||
func AddSimilarityCheck(i *Indexer, r *http.Request, torrents []schema.IndexedTorrent) []schema.IndexedTorrent {
|
||||
q := r.URL.Query().Get("q")
|
||||
|
||||
for i, it := range torrents {
|
||||
jLower := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s %s", it.Title, it.OriginalTitle)), ".", " ")
|
||||
qLower := strings.ToLower(q)
|
||||
splitLength := 2
|
||||
torrents[i].Similarity = edlib.JaccardSimilarity(jLower, qLower, splitLength)
|
||||
}
|
||||
|
||||
// remove the ones with zero similarity
|
||||
if len(torrents) > 20 && r.URL.Query().Get("filter_results") != "" && r.URL.Query().Get("q") != "" {
|
||||
torrents = utils.Filter(torrents, func(it schema.IndexedTorrent) bool {
|
||||
return it.Similarity > 0
|
||||
})
|
||||
}
|
||||
|
||||
// sort by similarity
|
||||
slices.SortFunc(torrents, func(i, j schema.IndexedTorrent) int {
|
||||
return int((j.Similarity - i.Similarity) * 1000)
|
||||
})
|
||||
|
||||
return torrents
|
||||
}
|
||||
250
api/rede_torrent.go
Normal file
250
api/rede_torrent.go
Normal file
@@ -0,0 +1,250 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
goscrape "github.com/felipemarinho97/torrent-indexer/scrape"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
var rede_torrent = IndexerMeta{
|
||||
Label: "rede_torrent",
|
||||
URL: "https://redetorrent.com/",
|
||||
SearchURL: "index.php?s=",
|
||||
PagePattern: "%s",
|
||||
}
|
||||
|
||||
func (i *Indexer) HandlerRedeTorrentIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := rede_torrent
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
// supported query params: q, season, episode, page, filter_results
|
||||
q := r.URL.Query().Get("q")
|
||||
page := r.URL.Query().Get("page")
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := metadata.URL
|
||||
if q != "" {
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
} else if page != "" {
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
resp, err := i.requester.GetDocument(ctx, url)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
var links []string
|
||||
doc.Find(".capa_lista").Each(func(i int, s *goquery.Selection) {
|
||||
link, _ := s.Find("a").Attr("href")
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrentsRedeTorrent(ctx, i, link)
|
||||
})
|
||||
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getTorrentsRedeTorrent(ctx context.Context, i *Indexer, link string) ([]schema.IndexedTorrent, error) {
|
||||
var indexedTorrents []schema.IndexedTorrent
|
||||
doc, err := getDocument(ctx, i, link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
article := doc.Find(".conteudo")
|
||||
// title pattern: "Something - optional balbla (dddd) some shit" - extract "Something" and "dddd"
|
||||
titleRe := regexp.MustCompile(`^(.*?)(?: - (.*?))? \((\d{4})\)`)
|
||||
titleP := titleRe.FindStringSubmatch(article.Find("h1").Text())
|
||||
if len(titleP) < 3 {
|
||||
return nil, fmt.Errorf("could not extract title from %s", link)
|
||||
}
|
||||
title := strings.TrimSpace(titleP[1])
|
||||
year := strings.TrimSpace(titleP[3])
|
||||
|
||||
textContent := article.Find(".apenas_itemprop")
|
||||
date := getPublishedDateFromMeta(doc)
|
||||
magnets := textContent.Find("a[href^=\"magnet\"]")
|
||||
var magnetLinks []string
|
||||
magnets.Each(func(i int, s *goquery.Selection) {
|
||||
magnetLink, _ := s.Attr("href")
|
||||
magnetLinks = append(magnetLinks, magnetLink)
|
||||
})
|
||||
|
||||
var audio []schema.Audio
|
||||
var size []string
|
||||
article.Find("div#informacoes > p").Each(func(i int, s *goquery.Selection) {
|
||||
// pattern:
|
||||
// Filme Bicho de Sete Cabeças Torrent
|
||||
// Título Original: Bicho de Sete Cabeças
|
||||
// Lançamento: 2001
|
||||
// Gêneros: Drama / Nacional
|
||||
// Idioma: Português
|
||||
// Qualidade: 720p / BluRay
|
||||
// Duração: 1h 14 Minutos
|
||||
// Formato: Mp4
|
||||
// Vídeo: 10 e Áudio: 10
|
||||
// Legendas: Português
|
||||
// Nota do Imdb: 7.7
|
||||
// Tamanho: 1.26 GB
|
||||
|
||||
// we need to manualy parse because the text is not well formatted
|
||||
htmlContent, err := s.Html()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// remove any \n and \t characters
|
||||
htmlContent = strings.ReplaceAll(htmlContent, "\n", "")
|
||||
htmlContent = strings.ReplaceAll(htmlContent, "\t", "")
|
||||
|
||||
// split by <br> tags and render each line
|
||||
brRe := regexp.MustCompile(`<br\s*\/?>`)
|
||||
htmlContent = brRe.ReplaceAllString(htmlContent, "<br>")
|
||||
lines := strings.Split(htmlContent, "<br>")
|
||||
|
||||
var text strings.Builder
|
||||
for _, line := range lines {
|
||||
// remove any HTML tags
|
||||
re := regexp.MustCompile(`<[^>]*>`)
|
||||
line = re.ReplaceAllString(line, "")
|
||||
|
||||
line = strings.TrimSpace(line)
|
||||
text.WriteString(line + "\n")
|
||||
}
|
||||
|
||||
audio = append(audio, findAudioFromText(text.String())...)
|
||||
y := findYearFromText(text.String(), title)
|
||||
if y != "" {
|
||||
year = y
|
||||
}
|
||||
size = append(size, findSizesFromText(text.String())...)
|
||||
})
|
||||
|
||||
// find any link from imdb
|
||||
imdbLink := ""
|
||||
article.Find("a").Each(func(i int, s *goquery.Selection) {
|
||||
link, _ := s.Attr("href")
|
||||
_imdbLink, err := getIMDBLink(link)
|
||||
if err == nil {
|
||||
imdbLink = _imdbLink
|
||||
}
|
||||
})
|
||||
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
// for each magnet link, create a new indexed torrent
|
||||
for it, magnetLink := range magnetLinks {
|
||||
it := it
|
||||
go func(it int, magnetLink string) {
|
||||
magnet, err := magnet.ParseMagnetUri(magnetLink)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
releaseTitle := magnet.DisplayName
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
title := processTitle(title, magnetAudio)
|
||||
|
||||
// if the number of sizes is equal to the number of magnets, then assign the size to each indexed torrent in order
|
||||
var mySize string
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
IMDB: imdbLink,
|
||||
Audio: magnetAudio,
|
||||
MagnetLink: magnetLink,
|
||||
Date: date,
|
||||
InfoHash: infoHash,
|
||||
Trackers: trackers,
|
||||
LeechCount: peer,
|
||||
SeedCount: seed,
|
||||
Size: mySize,
|
||||
}
|
||||
chanIndexedTorrent <- ixt
|
||||
}(it, magnetLink)
|
||||
}
|
||||
|
||||
for i := 0; i < len(magnetLinks); i++ {
|
||||
it := <-chanIndexedTorrent
|
||||
indexedTorrents = append(indexedTorrents, it)
|
||||
}
|
||||
|
||||
return indexedTorrents, nil
|
||||
}
|
||||
103
api/search.go
103
api/search.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
meilisearch "github.com/felipemarinho97/torrent-indexer/search"
|
||||
)
|
||||
@@ -13,6 +14,23 @@ type MeilisearchHandler struct {
|
||||
Module *meilisearch.SearchIndexer
|
||||
}
|
||||
|
||||
// HealthResponse represents the health check response
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status"`
|
||||
Service string `json:"service"`
|
||||
Details map[string]interface{} `json:"details,omitempty"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
// StatsResponse represents the stats endpoint response
|
||||
type StatsResponse struct {
|
||||
Status string `json:"status"`
|
||||
NumberOfDocuments int64 `json:"numberOfDocuments"`
|
||||
IsIndexing bool `json:"isIndexing"`
|
||||
FieldDistribution map[string]int64 `json:"fieldDistribution"`
|
||||
Service string `json:"service"`
|
||||
}
|
||||
|
||||
// NewMeilisearchHandler creates a new instance of MeilisearchHandler.
|
||||
func NewMeilisearchHandler(module *meilisearch.SearchIndexer) *MeilisearchHandler {
|
||||
return &MeilisearchHandler{Module: module}
|
||||
@@ -53,3 +71,88 @@ func (h *MeilisearchHandler) SearchTorrentHandler(w http.ResponseWriter, r *http
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// HealthHandler provides a health check endpoint for Meilisearch.
|
||||
func (h *MeilisearchHandler) HealthHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// Check if Meilisearch is healthy
|
||||
isHealthy := h.Module.IsHealthy()
|
||||
|
||||
response := HealthResponse{
|
||||
Service: "meilisearch",
|
||||
Timestamp: getCurrentTimestamp(),
|
||||
}
|
||||
|
||||
if isHealthy {
|
||||
// Try to get additional stats for more detailed health info
|
||||
stats, err := h.Module.GetStats()
|
||||
if err == nil {
|
||||
response.Status = "healthy"
|
||||
response.Details = map[string]interface{}{
|
||||
"documents": stats.NumberOfDocuments,
|
||||
"indexing": stats.IsIndexing,
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
// Service is up but can't get stats
|
||||
response.Status = "degraded"
|
||||
response.Details = map[string]interface{}{
|
||||
"error": "Could not retrieve stats",
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
} else {
|
||||
// Service is down
|
||||
response.Status = "unhealthy"
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// StatsHandler provides detailed statistics about the Meilisearch index.
|
||||
func (h *MeilisearchHandler) StatsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// Get detailed stats from Meilisearch
|
||||
stats, err := h.Module.GetStats()
|
||||
if err != nil {
|
||||
// Check if it's a connectivity issue
|
||||
if !h.Module.IsHealthy() {
|
||||
http.Error(w, "Meilisearch service is unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
http.Error(w, "Failed to retrieve statistics", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
response := StatsResponse{
|
||||
Status: "healthy",
|
||||
Service: "meilisearch",
|
||||
NumberOfDocuments: stats.NumberOfDocuments,
|
||||
IsIndexing: stats.IsIndexing,
|
||||
FieldDistribution: stats.FieldDistribution,
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// getCurrentTimestamp returns the current timestamp in RFC3339 format
|
||||
func getCurrentTimestamp() string {
|
||||
return time.Now().Format(time.RFC3339)
|
||||
}
|
||||
|
||||
226
api/starck_filmes.go
Normal file
226
api/starck_filmes.go
Normal file
@@ -0,0 +1,226 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
goscrape "github.com/felipemarinho97/torrent-indexer/scrape"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
var starck_filmes = IndexerMeta{
|
||||
Label: "starck_filmes",
|
||||
URL: "https://www.starckfilmes.online/",
|
||||
SearchURL: "?s=",
|
||||
PagePattern: "page/%s",
|
||||
}
|
||||
|
||||
func (i *Indexer) HandlerStarckFilmesIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := starck_filmes
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
// supported query params: q, page, filter_results
|
||||
q := r.URL.Query().Get("q")
|
||||
page := r.URL.Query().Get("page")
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := metadata.URL
|
||||
if q != "" {
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
} else if page != "" {
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
resp, err := i.requester.GetDocument(ctx, url)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
var links []string
|
||||
doc.Find(".item").Each(func(i int, s *goquery.Selection) {
|
||||
link, _ := s.Find("div.sub-item > a").Attr("href")
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrentStarckFilmes(ctx, i, link)
|
||||
})
|
||||
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getTorrentStarckFilmes(ctx context.Context, i *Indexer, link string) ([]schema.IndexedTorrent, error) {
|
||||
var indexedTorrents []schema.IndexedTorrent
|
||||
doc, err := getDocument(ctx, i, link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
date := getPublishedDateFromRawString(link)
|
||||
|
||||
post := doc.Find(".post")
|
||||
capa := post.Find(".capa")
|
||||
title := capa.Find(".post-description > h2").Text()
|
||||
post_buttons := post.Find(".post-buttons")
|
||||
magnets := post_buttons.Find("a[href^=\"magnet\"]")
|
||||
var magnetLinks []string
|
||||
magnets.Each(func(i int, s *goquery.Selection) {
|
||||
magnetLink, _ := s.Attr("href")
|
||||
magnetLinks = append(magnetLinks, magnetLink)
|
||||
})
|
||||
|
||||
var audio []schema.Audio
|
||||
var year string
|
||||
var size []string
|
||||
capa.Find(".post-description p").Each(func(i int, s *goquery.Selection) {
|
||||
// pattern:
|
||||
// Nome Original: 28 Weeks Later
|
||||
// Lançamento: 2007
|
||||
// Duração: 1h 40 min
|
||||
// Gênero: Terror, Suspense, Ficção
|
||||
// Formato: MKV
|
||||
// Tamanho: 2.45 GB
|
||||
// Qualidade de Video: 10
|
||||
// Qualidade do Audio: 10
|
||||
// Idioma: Português | Inglês
|
||||
// Legenda: Português, Inglês, Espanhol
|
||||
var text strings.Builder
|
||||
s.Find("span").Each(func(i int, span *goquery.Selection) {
|
||||
text.WriteString(span.Text())
|
||||
text.WriteString(" ")
|
||||
})
|
||||
audio = append(audio, findAudioFromText(text.String())...)
|
||||
y := findYearFromText(text.String(), title)
|
||||
if y != "" {
|
||||
year = y
|
||||
}
|
||||
size = append(size, findSizesFromText(text.String())...)
|
||||
})
|
||||
|
||||
// TODO: find any link from imdb
|
||||
imdbLink := ""
|
||||
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
// for each magnet link, create a new indexed torrent
|
||||
for it, magnetLink := range magnetLinks {
|
||||
it := it
|
||||
go func(it int, magnetLink string) {
|
||||
magnet, err := magnet.ParseMagnetUri(magnetLink)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
releaseTitle := strings.TrimSpace(magnet.DisplayName)
|
||||
// url decode the title
|
||||
releaseTitle, err = url.QueryUnescape(releaseTitle)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
releaseTitle = strings.TrimSpace(magnet.DisplayName)
|
||||
}
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
for i, tracker := range trackers {
|
||||
unescapedTracker, err := url.QueryUnescape(tracker)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
trackers[i] = strings.TrimSpace(unescapedTracker)
|
||||
}
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
title := processTitle(title, magnetAudio)
|
||||
|
||||
// if the number of sizes is equal to the number of magnets, then assign the size to each indexed torrent in order
|
||||
var mySize string
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
IMDB: imdbLink,
|
||||
Audio: magnetAudio,
|
||||
MagnetLink: magnetLink,
|
||||
Date: date,
|
||||
InfoHash: infoHash,
|
||||
Trackers: trackers,
|
||||
LeechCount: peer,
|
||||
SeedCount: seed,
|
||||
Size: mySize,
|
||||
}
|
||||
chanIndexedTorrent <- ixt
|
||||
}(it, magnetLink)
|
||||
}
|
||||
|
||||
for i := 0; i < len(magnetLinks); i++ {
|
||||
it := <-chanIndexedTorrent
|
||||
indexedTorrents = append(indexedTorrents, it)
|
||||
}
|
||||
|
||||
return indexedTorrents, nil
|
||||
}
|
||||
@@ -6,12 +6,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/hbollon/go-edlib"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/schema"
|
||||
@@ -20,15 +18,19 @@ import (
|
||||
)
|
||||
|
||||
var torrent_dos_filmes = IndexerMeta{
|
||||
URL: "https://torrentdosfilmes.se/",
|
||||
SearchURL: "?s=",
|
||||
Label: "torrent_dos_filmes",
|
||||
URL: "https://torrentdosfilmes.se/",
|
||||
SearchURL: "?s=",
|
||||
PagePattern: "category/dublado/page/%s",
|
||||
}
|
||||
|
||||
func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
metadata := torrent_dos_filmes
|
||||
|
||||
defer func() {
|
||||
i.metrics.IndexerDuration.WithLabelValues("torrent_dos_filmes").Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues("torrent_dos_filmes").Inc()
|
||||
i.metrics.IndexerDuration.WithLabelValues(metadata.Label).Observe(time.Since(start).Seconds())
|
||||
i.metrics.IndexerRequests.WithLabelValues(metadata.Label).Inc()
|
||||
}()
|
||||
|
||||
ctx := r.Context()
|
||||
@@ -38,11 +40,11 @@ func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.
|
||||
|
||||
// URL encode query param
|
||||
q = url.QueryEscape(q)
|
||||
url := torrent_dos_filmes.URL
|
||||
url := metadata.URL
|
||||
if q != "" {
|
||||
url = fmt.Sprintf("%s%s%s", url, torrent_dos_filmes.SearchURL, q)
|
||||
url = fmt.Sprintf("%s%s%s", url, metadata.SearchURL, q)
|
||||
} else if page != "" {
|
||||
url = fmt.Sprintf("%spage/%s", url, page)
|
||||
url = fmt.Sprintf(fmt.Sprintf("%s%s", url, metadata.PagePattern), page)
|
||||
}
|
||||
|
||||
fmt.Println("URL:>", url)
|
||||
@@ -53,7 +55,7 @@ func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
i.metrics.IndexerErrors.WithLabelValues("torrent_dos_filmes").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
@@ -66,7 +68,7 @@ func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
i.metrics.IndexerErrors.WithLabelValues("torrent_dos_filmes").Inc()
|
||||
i.metrics.IndexerErrors.WithLabelValues(metadata.Label).Inc()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -76,57 +78,21 @@ func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.
|
||||
links = append(links, link)
|
||||
})
|
||||
|
||||
var itChan = make(chan []schema.IndexedTorrent)
|
||||
var errChan = make(chan error)
|
||||
indexedTorrents := []schema.IndexedTorrent{}
|
||||
for _, link := range links {
|
||||
go func(link string) {
|
||||
torrents, err := getTorrentsTorrentDosFilmes(ctx, i, link)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
errChan <- err
|
||||
}
|
||||
itChan <- torrents
|
||||
}(link)
|
||||
}
|
||||
|
||||
for i := 0; i < len(links); i++ {
|
||||
select {
|
||||
case torrents := <-itChan:
|
||||
indexedTorrents = append(indexedTorrents, torrents...)
|
||||
case err := <-errChan:
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i, it := range indexedTorrents {
|
||||
jLower := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s %s", it.Title, it.OriginalTitle)), ".", " ")
|
||||
qLower := strings.ToLower(q)
|
||||
splitLength := 2
|
||||
indexedTorrents[i].Similarity = edlib.JaccardSimilarity(jLower, qLower, splitLength)
|
||||
}
|
||||
|
||||
// remove the ones with zero similarity
|
||||
if len(indexedTorrents) > 20 && r.URL.Query().Get("filter_results") != "" && r.URL.Query().Get("q") != "" {
|
||||
indexedTorrents = utils.Filter(indexedTorrents, func(it schema.IndexedTorrent) bool {
|
||||
return it.Similarity > 0
|
||||
})
|
||||
}
|
||||
|
||||
// sort by similarity
|
||||
slices.SortFunc(indexedTorrents, func(i, j schema.IndexedTorrent) int {
|
||||
return int((j.Similarity - i.Similarity) * 1000)
|
||||
// extract each torrent link
|
||||
indexedTorrents := utils.ParallelFlatMap(links, func(link string) ([]schema.IndexedTorrent, error) {
|
||||
return getTorrentsTorrentDosFilmes(ctx, i, link)
|
||||
})
|
||||
|
||||
// send to search index
|
||||
go func() {
|
||||
_ = i.search.IndexTorrents(indexedTorrents)
|
||||
}()
|
||||
// Apply post-processors
|
||||
postProcessedTorrents := indexedTorrents
|
||||
for _, processor := range i.postProcessors {
|
||||
postProcessedTorrents = processor(i, r, postProcessedTorrents)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: indexedTorrents,
|
||||
Count: len(indexedTorrents),
|
||||
Results: postProcessedTorrents,
|
||||
Count: len(postProcessedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -143,7 +109,7 @@ func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) (
|
||||
article := doc.Find("article")
|
||||
title := strings.Replace(article.Find(".title > h1").Text(), " - Download", "", -1)
|
||||
textContent := article.Find("div.content")
|
||||
date := getPublishedDateTDF(doc)
|
||||
date := getPublishedDateFromMeta(doc)
|
||||
magnets := textContent.Find("a[href^=\"magnet\"]")
|
||||
var magnetLinks []string
|
||||
magnets.Each(func(i int, s *goquery.Selection) {
|
||||
@@ -191,7 +157,7 @@ func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) (
|
||||
}
|
||||
})
|
||||
|
||||
size = stableUniq(size)
|
||||
size = utils.StableUniq(size)
|
||||
|
||||
var chanIndexedTorrent = make(chan schema.IndexedTorrent)
|
||||
|
||||
@@ -206,19 +172,7 @@ func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) (
|
||||
releaseTitle := magnet.DisplayName
|
||||
infoHash := magnet.InfoHash.String()
|
||||
trackers := magnet.Trackers
|
||||
magnetAudio := []schema.Audio{}
|
||||
if strings.Contains(strings.ToLower(releaseTitle), "dual") || strings.Contains(strings.ToLower(releaseTitle), "dublado") {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
} else if len(audio) > 1 {
|
||||
// remove portuguese audio, and append to magnetAudio
|
||||
for _, a := range audio {
|
||||
if a != schema.AudioPortuguese {
|
||||
magnetAudio = append(magnetAudio, a)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
magnetAudio = append(magnetAudio, audio...)
|
||||
}
|
||||
magnetAudio := getAudioFromTitle(releaseTitle, audio)
|
||||
|
||||
peer, seed, err := goscrape.GetLeechsAndSeeds(ctx, i.redis, i.metrics, infoHash, trackers)
|
||||
if err != nil {
|
||||
@@ -232,9 +186,14 @@ func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) (
|
||||
if len(size) == len(magnetLinks) {
|
||||
mySize = size[it]
|
||||
}
|
||||
if mySize == "" {
|
||||
go func() {
|
||||
_, _ = i.magnetMetadataAPI.FetchMetadata(ctx, magnetLink)
|
||||
}()
|
||||
}
|
||||
|
||||
ixt := schema.IndexedTorrent{
|
||||
Title: appendAudioISO639_2Code(releaseTitle, magnetAudio),
|
||||
Title: releaseTitle,
|
||||
OriginalTitle: title,
|
||||
Details: link,
|
||||
Year: year,
|
||||
@@ -259,15 +218,3 @@ func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) (
|
||||
|
||||
return indexedTorrents, nil
|
||||
}
|
||||
|
||||
func getPublishedDateTDF(document *goquery.Document) time.Time {
|
||||
var date time.Time
|
||||
//<meta property="article:published_time" content="2019-08-23T13:20:57+00:00">
|
||||
datePublished := strings.TrimSpace(document.Find("meta[property=\"article:published_time\"]").AttrOr("content", ""))
|
||||
|
||||
if datePublished != "" {
|
||||
date, _ = time.Parse(time.RFC3339, datePublished)
|
||||
}
|
||||
|
||||
return date
|
||||
}
|
||||
|
||||
14
consts/version.go
Normal file
14
consts/version.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package consts
|
||||
|
||||
// These will be injected via -ldflags at build time
|
||||
var (
|
||||
gitSha string = "unknown"
|
||||
gitTag string = "unknown"
|
||||
)
|
||||
|
||||
func GetBuildInfo() map[string]string {
|
||||
return map[string]string{
|
||||
"revision": gitSha,
|
||||
"version": gitTag,
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,16 @@ services:
|
||||
- indexer
|
||||
environment:
|
||||
- REDIS_HOST=redis
|
||||
- MEILISEARCH_ADDRESS=http://meilisearch:7700
|
||||
- MEILISEARCH_KEY=my-secret-key
|
||||
- FLARESOLVERR_ADDRESS=http://flaresolverr:8191
|
||||
|
||||
## Meilisearch configuration (optional)
|
||||
# - MEILISEARCH_ADDRESS=http://meilisearch:7700
|
||||
# - MEILISEARCH_KEY=my-secret-key
|
||||
|
||||
## Magnet Metadata API configuration (optional)
|
||||
# - MAGNET_METADATA_API_ENABLED=false
|
||||
# - MAGNET_METADATA_API_ADDRESS=http://magnet-metadata-api:8080
|
||||
# - MAGNET_METADATA_API_TIMEOUT_SECONDS=10
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
@@ -22,17 +29,45 @@ services:
|
||||
networks:
|
||||
- indexer
|
||||
|
||||
# This container is not necessary for the indexer to work,
|
||||
# deploy if you want to use the search feature
|
||||
meilisearch:
|
||||
image: getmeili/meilisearch:latest
|
||||
container_name: meilisearch
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- indexer
|
||||
environment:
|
||||
- MEILI_NO_ANALYTICS=true
|
||||
- MEILI_MASTER_KEY=my-secret-key
|
||||
##### MEILISEARCH #####
|
||||
## This container is not necessary for the indexer to work,
|
||||
## deploy if you want to use the search feature
|
||||
#
|
||||
# meilisearch:
|
||||
# image: getmeili/meilisearch:latest
|
||||
# container_name: meilisearch
|
||||
# restart: unless-stopped
|
||||
# networks:
|
||||
# - indexer
|
||||
# environment:
|
||||
# - MEILI_NO_ANALYTICS=true
|
||||
# - MEILI_MASTER_KEY=my-secret-key
|
||||
|
||||
##### MAGNET METADATA API #####
|
||||
## This container is not necessary for the indexer to work,
|
||||
## deploy if you want to fetch metadata from p2p network
|
||||
## CAUTION: Never deploy this container on a cloud server (AWS, GCP, Azure, Oracle), or you will get banned!
|
||||
#
|
||||
# magnet-metadata-api:
|
||||
# image: felipemarinho97/magnet-metadata-api:latest
|
||||
# container_name: magnet-metadata-api
|
||||
# restart: unless-stopped
|
||||
# ports:
|
||||
# - "8999:8080"
|
||||
# - "42069:42069"
|
||||
# networks:
|
||||
# - indexer
|
||||
# environment:
|
||||
# - PORT=8080
|
||||
# - REDIS_URL=redis://redis:6379
|
||||
# - CACHE_DIR=/home/torrent/cache
|
||||
# - ENABLE_DOWNLOADS=false
|
||||
# - DOWNLOAD_BASE_URL=http://localhost:8999
|
||||
# - CLIENT_PORT=42069
|
||||
# - SEEDING_ENABLED=false
|
||||
# - FALLBACK_INITIAL_CHUNK_SIZE_KB=24
|
||||
# volumes:
|
||||
# - ./magnet-metadata-cache:/home/torrent/cache
|
||||
|
||||
networks:
|
||||
indexer:
|
||||
|
||||
25
go.mod
25
go.mod
@@ -1,25 +1,26 @@
|
||||
module github.com/felipemarinho97/torrent-indexer
|
||||
|
||||
go 1.22
|
||||
go 1.24
|
||||
|
||||
require github.com/redis/go-redis/v9 v9.5.1
|
||||
require github.com/redis/go-redis/v9 v9.11.0
|
||||
|
||||
require (
|
||||
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/prometheus/client_model v0.6.0 // indirect
|
||||
github.com/prometheus/common v0.50.0 // indirect
|
||||
github.com/prometheus/procfs v0.13.0 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/prometheus/client_model v0.6.2 // indirect
|
||||
github.com/prometheus/common v0.65.0 // indirect
|
||||
github.com/prometheus/procfs v0.17.0 // indirect
|
||||
golang.org/x/sys v0.34.0 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.9.1
|
||||
github.com/PuerkitoBio/goquery v1.10.3
|
||||
github.com/hbollon/go-edlib v1.6.0
|
||||
github.com/prometheus/client_golang v1.19.0
|
||||
github.com/prometheus/client_golang v1.22.0
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0
|
||||
golang.org/x/net v0.42.0
|
||||
)
|
||||
|
||||
95
go.sum
95
go.sum
@@ -1,72 +1,115 @@
|
||||
github.com/PuerkitoBio/goquery v1.9.1 h1:mTL6XjbJTZdpfL+Gwl5U2h1l9yEkJjhmlTeV9VPW7UI=
|
||||
github.com/PuerkitoBio/goquery v1.9.1/go.mod h1:cW1n6TmIMDoORQU5IU/P1T3tGFunOeXEpGP2WHRwkbY=
|
||||
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
|
||||
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
|
||||
github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
|
||||
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
|
||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
||||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/hbollon/go-edlib v1.6.0 h1:ga7AwwVIvP8mHm9GsPueC0d71cfRU/52hmPJ7Tprv4E=
|
||||
github.com/hbollon/go-edlib v1.6.0/go.mod h1:wnt6o6EIVEzUfgbUZY7BerzQ2uvzp354qmS2xaLkrhM=
|
||||
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
|
||||
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
|
||||
github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ=
|
||||
github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ=
|
||||
github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o=
|
||||
github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g=
|
||||
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
|
||||
github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
|
||||
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
|
||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||
github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE=
|
||||
github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8=
|
||||
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
|
||||
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
|
||||
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
|
||||
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
|
||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
||||
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
113
magnet/magnet_metadata_api.go
Normal file
113
magnet/magnet_metadata_api.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package magnet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/cache"
|
||||
)
|
||||
|
||||
type MetadataRequest struct {
|
||||
MagnetURI string `json:"magnet_uri"`
|
||||
}
|
||||
|
||||
type TorrentFile struct {
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
Offset int64 `json:"offset"`
|
||||
}
|
||||
|
||||
type MetadataResponse struct {
|
||||
InfoHash string `json:"info_hash"`
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
Files []TorrentFile `json:"files"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Comment string `json:"comment"`
|
||||
Trackers []string `json:"trackers"`
|
||||
DownloadURL string `json:"download_url"`
|
||||
}
|
||||
|
||||
type MetadataClient struct {
|
||||
baseURL string
|
||||
httpClient *http.Client
|
||||
c *cache.Redis
|
||||
}
|
||||
|
||||
func NewClient(baseURL string, timeout time.Duration, c *cache.Redis) *MetadataClient {
|
||||
return &MetadataClient{
|
||||
baseURL: baseURL,
|
||||
httpClient: &http.Client{
|
||||
Timeout: timeout,
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
ForceAttemptHTTP2: true,
|
||||
},
|
||||
},
|
||||
c: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MetadataClient) IsEnabled() bool {
|
||||
return c != nil && c.baseURL != ""
|
||||
}
|
||||
|
||||
func (c *MetadataClient) FetchMetadata(ctx context.Context, magnetURI string) (*MetadataResponse, error) {
|
||||
if !c.IsEnabled() {
|
||||
return nil, fmt.Errorf("magnet metadata API is not enabled")
|
||||
}
|
||||
// Check cache first
|
||||
m, err := ParseMagnetUri(magnetURI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse magnet URI: %w", err)
|
||||
}
|
||||
cacheKey := fmt.Sprintf("metadata:%s", m.InfoHash)
|
||||
cachedData, err := c.c.Get(ctx, cacheKey)
|
||||
if err == nil && cachedData != nil {
|
||||
var cachedMetadata MetadataResponse
|
||||
if err := json.Unmarshal(cachedData, &cachedMetadata); err == nil {
|
||||
return &cachedMetadata, nil
|
||||
}
|
||||
}
|
||||
|
||||
reqBody := MetadataRequest{MagnetURI: magnetURI}
|
||||
body, err := json.Marshal(reqBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/api/v1/metadata", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to send POST request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("API responded with status: %s", resp.Status)
|
||||
}
|
||||
|
||||
var metadata MetadataResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&metadata); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode response: %w", err)
|
||||
}
|
||||
|
||||
// Cache the metadata response
|
||||
cacheData, err := json.Marshal(metadata)
|
||||
if err == nil {
|
||||
_ = c.c.SetWithExpiration(ctx, cacheKey, cacheData, 7*24*time.Hour)
|
||||
}
|
||||
|
||||
return &metadata, nil
|
||||
}
|
||||
24
main.go
24
main.go
@@ -4,9 +4,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
handler "github.com/felipemarinho97/torrent-indexer/api"
|
||||
"github.com/felipemarinho97/torrent-indexer/cache"
|
||||
"github.com/felipemarinho97/torrent-indexer/magnet"
|
||||
"github.com/felipemarinho97/torrent-indexer/monitoring"
|
||||
"github.com/felipemarinho97/torrent-indexer/public"
|
||||
"github.com/felipemarinho97/torrent-indexer/requester"
|
||||
@@ -19,6 +22,16 @@ import (
|
||||
func main() {
|
||||
redis := cache.NewRedis()
|
||||
searchIndex := meilisearch.NewSearchIndexer(os.Getenv("MEILISEARCH_ADDRESS"), os.Getenv("MEILISEARCH_KEY"), "torrents")
|
||||
var magnetMetadataAPI *magnet.MetadataClient
|
||||
if os.Getenv("MAGNET_METADATA_API_ENABLED") == "true" {
|
||||
timeout := 10 * time.Second
|
||||
if v := os.Getenv("MAGNET_METADATA_API_TIMEOUT_SECONDS"); v != "" {
|
||||
if t, err := strconv.Atoi(v); err == nil {
|
||||
timeout = time.Duration(t) * time.Second
|
||||
}
|
||||
}
|
||||
magnetMetadataAPI = magnet.NewClient(os.Getenv("MAGNET_METADATA_API_ADDRESS"), timeout, redis)
|
||||
}
|
||||
metrics := monitoring.NewMetrics()
|
||||
metrics.Register()
|
||||
|
||||
@@ -39,18 +52,23 @@ func main() {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
indexers := handler.NewIndexers(redis, metrics, req, searchIndex)
|
||||
indexers := handler.NewIndexers(redis, metrics, req, searchIndex, magnetMetadataAPI)
|
||||
search := handler.NewMeilisearchHandler(searchIndex)
|
||||
|
||||
indexerMux := http.NewServeMux()
|
||||
metricsMux := http.NewServeMux()
|
||||
|
||||
indexerMux.HandleFunc("/", handler.HandlerIndex)
|
||||
indexerMux.HandleFunc("/indexers/comando_torrents", indexers.HandlerComandoIndexer)
|
||||
indexerMux.HandleFunc("/indexers/torrent-dos-filmes", indexers.HandlerTorrentDosFilmesIndexer)
|
||||
indexerMux.HandleFunc("/indexers/bludv", indexers.HandlerBluDVIndexer)
|
||||
indexerMux.HandleFunc("/indexers/comando_torrents", indexers.HandlerComandoIndexer)
|
||||
indexerMux.HandleFunc("/indexers/comandohds", indexers.HandlerComandoHDsIndexer)
|
||||
indexerMux.HandleFunc("/indexers/rede_torrent", indexers.HandlerRedeTorrentIndexer)
|
||||
indexerMux.HandleFunc("/indexers/starck-filmes", indexers.HandlerStarckFilmesIndexer)
|
||||
indexerMux.HandleFunc("/indexers/torrent-dos-filmes", indexers.HandlerTorrentDosFilmesIndexer)
|
||||
indexerMux.HandleFunc("/indexers/manual", indexers.HandlerManualIndexer)
|
||||
indexerMux.HandleFunc("/search", search.SearchTorrentHandler)
|
||||
indexerMux.HandleFunc("/search/health", search.HealthHandler)
|
||||
indexerMux.HandleFunc("/search/stats", search.StatsHandler)
|
||||
indexerMux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.FS(public.UIFiles))))
|
||||
|
||||
metricsMux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/@heroicons/react/solid@2.0.0/dist/index.umd.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="bg-gray-900 text-white font-sans">
|
||||
<div class="container mx-auto p-6">
|
||||
<body class="bg-gray-900 text-white font-sans min-h-screen flex flex-col">
|
||||
<div class="container mx-auto p-6 flex-grow">
|
||||
<!-- Header -->
|
||||
<header class="text-center mb-10">
|
||||
<h1 class="text-4xl font-bold text-blue-400">Torrent Indexer 🇧🇷</h1>
|
||||
@@ -24,14 +24,95 @@
|
||||
<button id="search-btn"
|
||||
class="ml-4 px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-bold text-white">Search</button>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Results Section -->
|
||||
<div id="results" class="space-y-6">
|
||||
<div id="results" class="space-y-6 mb-10">
|
||||
<!-- Dynamic content will be injected here -->
|
||||
</div>
|
||||
|
||||
<!-- Health Warning -->
|
||||
<div id="health-warning" class="hidden mb-6 p-4 bg-yellow-800 border border-yellow-600 rounded-lg">
|
||||
<div class="flex items-center gap-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-9 4h18a2 2 0 002-2V7a2 2 0 00-2-2H3a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
||||
</svg>
|
||||
<span class="font-bold text-yellow-400">Service Warning</span>
|
||||
</div>
|
||||
<p class="text-yellow-200 mt-2">Search functionality may be disabled or experiencing issues. Please try again later.</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- Stats Section -->
|
||||
<div id="database-statistics" class="stats-info mt-auto mb-1 p-3 rounded text-center">
|
||||
<span id="torrentStats" class="text-gray-400">Loading stats...</span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Global variables
|
||||
let serviceHealthy = true;
|
||||
|
||||
// Function to check service health
|
||||
async function checkHealth() {
|
||||
try {
|
||||
const response = await fetch('/search/health');
|
||||
const health = await response.json();
|
||||
|
||||
if (response.status === 503 || health.status === 'unhealthy') {
|
||||
serviceHealthy = false;
|
||||
showHealthWarning();
|
||||
hideDatabaseStatistics();
|
||||
} else if (health.status === 'degraded') {
|
||||
serviceHealthy = true; // Still operational
|
||||
showHealthWarning(); // But show warning
|
||||
} else {
|
||||
serviceHealthy = true;
|
||||
hideHealthWarning();
|
||||
}
|
||||
} catch (error) {
|
||||
serviceHealthy = false;
|
||||
showHealthWarning();
|
||||
console.error('Health check failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to show health warning
|
||||
function showHealthWarning() {
|
||||
document.getElementById('health-warning').classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Function to hide health warning
|
||||
function hideHealthWarning() {
|
||||
document.getElementById('health-warning').classList.add('hidden');
|
||||
}
|
||||
|
||||
function hideDatabaseStatistics() {
|
||||
document.getElementById('database-statistics').classList.add('hidden');
|
||||
}
|
||||
|
||||
// Function to load stats
|
||||
async function loadStats() {
|
||||
try {
|
||||
const response = await fetch('/search/stats');
|
||||
if (response.ok) {
|
||||
const stats = await response.json();
|
||||
const statsElement = document.getElementById('torrentStats');
|
||||
|
||||
const formattedStats = `
|
||||
<span class="text-sm text-gray-500">
|
||||
<span class="text-green-400 font-medium">${stats.numberOfDocuments?.toLocaleString()+'+' || 'N/A'}</span> indexed torrents!
|
||||
</span>
|
||||
`;
|
||||
|
||||
statsElement.innerHTML = formattedStats;
|
||||
} else {
|
||||
throw new Error('Failed to load stats');
|
||||
}
|
||||
} catch (error) {
|
||||
hideDatabaseStatistics();
|
||||
console.error('Stats loading failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to render a single torrent result
|
||||
function renderTorrent(torrent) {
|
||||
return `
|
||||
@@ -100,28 +181,46 @@
|
||||
|
||||
const results = await response.json();
|
||||
const resultsContainer = document.getElementById('results');
|
||||
resultsContainer.innerHTML = results.map(renderTorrent).join('');
|
||||
|
||||
if (results.length === 0) {
|
||||
resultsContainer.innerHTML = `
|
||||
<div class="p-6 bg-gray-800 rounded-lg shadow-md text-center">
|
||||
<p class="text-xl font-bold text-gray-400">No results found</p>
|
||||
<p class="text-gray-500 mt-2">Try different search terms or check spelling</p>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
resultsContainer.innerHTML = results.map(renderTorrent).join('');
|
||||
}
|
||||
} catch (error) {
|
||||
// add error element
|
||||
document.getElementById('results').innerHTML = `
|
||||
<div class="p-6 bg-red-800 rounded-lg shadow-md text-center">
|
||||
<p class="text-xl font-bold text-red-400">Error fetching search results</p>
|
||||
<p class="text-gray-400 mt-2">Please try again later.</p>
|
||||
</div>
|
||||
`;
|
||||
//alert('Error fetching search results. Please try again.');
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
document.getElementById('search-btn').addEventListener('click', onSearch);
|
||||
// on enter press
|
||||
document.getElementById('search-query').addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
onSearch();
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize page
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await checkHealth();
|
||||
await loadStats();
|
||||
|
||||
// Refresh health and stats periodically
|
||||
setInterval(checkHealth, 30000); // Check health every 30 seconds
|
||||
setInterval(loadStats, 60000); // Update stats every minute
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/cache"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -77,8 +78,8 @@ func (i *Requster) GetDocument(ctx context.Context, url string) (io.ReadCloser,
|
||||
fmt.Printf("request served from plain client: %s\n", url)
|
||||
}
|
||||
|
||||
// save response to cache if it's not a challange and body is not empty
|
||||
if !hasChallange(bodyByte) && len(bodyByte) > 0 {
|
||||
// save response to cache if it's not a challange, body is not empty and is valid HTML
|
||||
if !hasChallange(bodyByte) && len(bodyByte) > 0 && utils.IsValidHTML(string(bodyByte)) {
|
||||
err = i.c.SetWithExpiration(ctx, key, bodyByte, i.shortLivedCacheExpiration)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to save response to cache: %v\n", err)
|
||||
|
||||
@@ -25,6 +25,7 @@ const (
|
||||
AudioMandarin3 = "Chines"
|
||||
AudioRussian = "Russo"
|
||||
AudioSwedish = "Sueco"
|
||||
AudioSwedish2 = "Suéco"
|
||||
AudioUkrainian = "Ucraniano"
|
||||
AudioPolish = "Polaco"
|
||||
AudioPolish2 = "Polonês"
|
||||
@@ -34,9 +35,32 @@ const (
|
||||
AudioTurkish = "Turco"
|
||||
AudioHindi = "Hindi"
|
||||
AudioFarsi = "Persa"
|
||||
AudioFarsi2 = "Farsi"
|
||||
AudioFarsi3 = "Iraniano"
|
||||
AudioMalay = "Malaio"
|
||||
AudioDutch = "Holandês"
|
||||
AudioDutch2 = "Holandes"
|
||||
AudioFinnish = "Finlandês"
|
||||
AudioFinnish2 = "Finlandes"
|
||||
AudioDanish = "Dinamarquês"
|
||||
AudioDanish2 = "Dinamarques"
|
||||
AudioNorwegian = "Norueguês"
|
||||
AudioNorwegian2 = "Noruegues"
|
||||
AudioIcelandic = "Islandês"
|
||||
AudioIcelandic2 = "Islandes"
|
||||
AudioGreek = "Grego"
|
||||
AudioArabic = "Árabe"
|
||||
AudioArabic2 = "Arabe"
|
||||
AudioHebrew = "Hebraico"
|
||||
AudioVietnamese = "Vietnamita"
|
||||
AudioIndonesian = "Indonésio"
|
||||
AudioIndonesian2 = "Indonesio"
|
||||
AudioFilipino = "Filipino"
|
||||
AudioBengali = "Bengali"
|
||||
AudioTamil = "Tamil"
|
||||
AudioTelugu = "Telugu"
|
||||
AudioGujarati = "Gujarati"
|
||||
AudioMarathi = "Marathi"
|
||||
)
|
||||
|
||||
var AudioList = []Audio{
|
||||
@@ -60,6 +84,7 @@ var AudioList = []Audio{
|
||||
AudioMandarin3,
|
||||
AudioRussian,
|
||||
AudioSwedish,
|
||||
AudioSwedish2,
|
||||
AudioUkrainian,
|
||||
AudioPolish,
|
||||
AudioPolish2,
|
||||
@@ -69,9 +94,32 @@ var AudioList = []Audio{
|
||||
AudioTurkish,
|
||||
AudioHindi,
|
||||
AudioFarsi,
|
||||
AudioFarsi2,
|
||||
AudioFarsi3,
|
||||
AudioMalay,
|
||||
AudioDutch,
|
||||
AudioDutch2,
|
||||
AudioFinnish,
|
||||
AudioFinnish2,
|
||||
AudioDanish,
|
||||
AudioDanish2,
|
||||
AudioNorwegian,
|
||||
AudioNorwegian2,
|
||||
AudioIcelandic,
|
||||
AudioIcelandic2,
|
||||
AudioGreek,
|
||||
AudioArabic,
|
||||
AudioArabic2,
|
||||
AudioHebrew,
|
||||
AudioVietnamese,
|
||||
AudioIndonesian,
|
||||
AudioIndonesian2,
|
||||
AudioFilipino,
|
||||
AudioBengali,
|
||||
AudioTamil,
|
||||
AudioTelugu,
|
||||
AudioGujarati,
|
||||
AudioMarathi,
|
||||
}
|
||||
|
||||
func (a Audio) String() string {
|
||||
@@ -129,6 +177,8 @@ func (a Audio) toTag() string {
|
||||
return "rus"
|
||||
case AudioSwedish:
|
||||
return "swe"
|
||||
case AudioSwedish2:
|
||||
return "swe"
|
||||
case AudioUkrainian:
|
||||
return "ukr"
|
||||
case AudioPolish:
|
||||
@@ -147,12 +197,58 @@ func (a Audio) toTag() string {
|
||||
return "hin"
|
||||
case AudioFarsi:
|
||||
return "fas"
|
||||
case AudioFarsi2:
|
||||
return "fas"
|
||||
case AudioFarsi3:
|
||||
return "fas"
|
||||
case AudioMalay:
|
||||
return "msa"
|
||||
case AudioDutch:
|
||||
return "nld"
|
||||
case AudioDutch2:
|
||||
return "nld"
|
||||
case AudioFinnish:
|
||||
return "fin"
|
||||
case AudioFinnish2:
|
||||
return "fin"
|
||||
case AudioDanish:
|
||||
return "dan"
|
||||
case AudioDanish2:
|
||||
return "dan"
|
||||
case AudioNorwegian:
|
||||
return "nor"
|
||||
case AudioNorwegian2:
|
||||
return "nor"
|
||||
case AudioIcelandic:
|
||||
return "isl"
|
||||
case AudioIcelandic2:
|
||||
return "isl"
|
||||
case AudioGreek:
|
||||
return "ell"
|
||||
case AudioArabic:
|
||||
return "ara"
|
||||
case AudioArabic2:
|
||||
return "ara"
|
||||
case AudioHebrew:
|
||||
return "heb"
|
||||
case AudioVietnamese:
|
||||
return "vie"
|
||||
case AudioIndonesian:
|
||||
return "ind"
|
||||
case AudioIndonesian2:
|
||||
return "ind"
|
||||
case AudioFilipino:
|
||||
return "fil"
|
||||
case AudioBengali:
|
||||
return "ben"
|
||||
case AudioTamil:
|
||||
return "tam"
|
||||
case AudioTelugu:
|
||||
return "tel"
|
||||
case AudioGujarati:
|
||||
return "guj"
|
||||
case AudioMarathi:
|
||||
return "mar"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -14,7 +14,13 @@ type IndexedTorrent struct {
|
||||
InfoHash string `json:"info_hash"`
|
||||
Trackers []string `json:"trackers"`
|
||||
Size string `json:"size"`
|
||||
Files []File `json:"files,omitempty"`
|
||||
LeechCount int `json:"leech_count"`
|
||||
SeedCount int `json:"seed_count"`
|
||||
Similarity float32 `json:"similarity"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Path string `json:"path"`
|
||||
Size string `json:"size"`
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/felipemarinho97/torrent-indexer/cache"
|
||||
"github.com/felipemarinho97/torrent-indexer/monitoring"
|
||||
"github.com/felipemarinho97/torrent-indexer/utils"
|
||||
)
|
||||
|
||||
type peers struct {
|
||||
@@ -45,6 +46,86 @@ func setPeersToCache(ctx context.Context, r *cache.Redis, infoHash string, peer,
|
||||
return nil
|
||||
}
|
||||
|
||||
var additionalTrackers = []string{
|
||||
"udp://tracker.opentrackr.org:1337/announce",
|
||||
"udp://p4p.arenabg.com:1337/announce",
|
||||
"udp://retracker.hotplug.ru:2710/announce",
|
||||
"http://tracker.bt4g.com:2095/announce",
|
||||
"http://bt.okmp3.ru:2710/announce",
|
||||
"udp://tracker.torrent.eu.org:451/announce",
|
||||
"http://tracker.mywaifu.best:6969/announce",
|
||||
"udp://ttk2.nbaonlineservice.com:6969/announce",
|
||||
"http://tracker.privateseedbox.xyz:2710/announce",
|
||||
"udp://evan.im:6969/announce",
|
||||
"https://tracker.yemekyedim.com:443/announce",
|
||||
"udp://retracker.lanta.me:2710/announce",
|
||||
"udp://martin-gebhardt.eu:25/announce",
|
||||
"http://tracker.beeimg.com:6969/announce",
|
||||
"udp://udp.tracker.projectk.org:23333/announce",
|
||||
"http://tracker.renfei.net:8080/announce",
|
||||
"https://tracker.expli.top:443/announce",
|
||||
"https://tr.nyacat.pw:443/announce",
|
||||
"udp://tracker.ducks.party:1984/announce",
|
||||
"udp://extracker.dahrkael.net:6969/announce",
|
||||
"http://ipv4.rer.lol:2710/announce",
|
||||
"udp://tracker.plx.im:6969/announce",
|
||||
"udp://tracker.tvunderground.org.ru:3218/announce",
|
||||
"http://tracker.tricitytorrents.com:2710/announce",
|
||||
"udp://open.stealth.si:80/announce",
|
||||
"udp://tracker.dler.com:6969/announce",
|
||||
"https://tracker.moeblog.cn:443/announce",
|
||||
"udp://d40969.acod.regrucolo.ru:6969/announce",
|
||||
"https://tracker.jdx3.org:443/announce",
|
||||
"http://ipv6.rer.lol:6969/announce",
|
||||
"udp://bandito.byterunner.io:6969/announce",
|
||||
"udp://tracker.gigantino.net:6969/announce",
|
||||
"http://tracker.netmap.top:6969/announce",
|
||||
"udp://tracker.yume-hatsuyuki.moe:6969/announce",
|
||||
"https://tracker.aburaya.live:443/announce",
|
||||
"udp://tracker.srv00.com:6969/announce",
|
||||
"udp://open.demonii.com:1337/announce",
|
||||
"udp://1c.premierzal.ru:6969/announce",
|
||||
"udp://tracker.fnix.net:6969/announce",
|
||||
"udp://tracker.kmzs123.cn:17272/announce",
|
||||
"https://tracker.home.kmzs123.cn:4443/announce",
|
||||
"udp://tracker-udp.gbitt.info:80/announce",
|
||||
"udp://tracker.torrust-demo.com:6969/announce",
|
||||
"udp://tracker.hifimarket.in:2710/announce",
|
||||
"udp://retracker01-msk-virt.corbina.net:80/announce",
|
||||
"https://tracker.ghostchu-services.top:443/announce",
|
||||
"udp://open.dstud.io:6969/announce",
|
||||
"udp://tracker.therarbg.to:6969/announce",
|
||||
"udp://tracker.bitcoinindia.space:6969/announce",
|
||||
"udp://www.torrent.eu.org:451/announce",
|
||||
"udp://tracker.hifitechindia.com:6969/announce",
|
||||
"udp://tracker.gmi.gd:6969/announce",
|
||||
"udp://tracker.skillindia.site:6969/announce",
|
||||
"http://tracker.ipv6tracker.ru:80/announce",
|
||||
"udp://tracker.tryhackx.org:6969/announce",
|
||||
"http://torrent.hificode.in:6969/announce",
|
||||
"http://open.trackerlist.xyz:80/announce",
|
||||
"http://taciturn-shadow.spb.ru:6969/announce",
|
||||
"http://0123456789nonexistent.com:80/announce",
|
||||
"http://shubt.net:2710/announce",
|
||||
"udp://tracker.valete.tf:9999/announce",
|
||||
"https://tracker.zhuqiy.top:443/announce",
|
||||
"https://tracker.leechshield.link:443/announce",
|
||||
"http://tracker.tritan.gg:8080/announce",
|
||||
"udp://t.overflow.biz:6969/announce",
|
||||
"udp://open.tracker.cl:1337/announce",
|
||||
"udp://explodie.org:6969/announce",
|
||||
"udp://exodus.desync.com:6969/announce",
|
||||
"udp://bt.ktrackers.com:6666/announce",
|
||||
"udp://wepzone.net:6969/announce",
|
||||
"udp://tracker2.dler.org:80/announce",
|
||||
"udp://tracker.theoks.net:6969/announce",
|
||||
"udp://tracker.ololosh.space:6969/announce",
|
||||
"udp://tracker.filemail.com:6969/announce",
|
||||
"udp://tracker.dump.cl:6969/announce",
|
||||
"udp://tracker.dler.org:6969/announce",
|
||||
"udp://tracker.bittor.pw:1337/announce",
|
||||
}
|
||||
|
||||
func GetLeechsAndSeeds(ctx context.Context, r *cache.Redis, m *monitoring.Metrics, infoHash string, trackers []string) (int, int, error) {
|
||||
leech, seed, err := getPeersFromCache(ctx, r, infoHash)
|
||||
if err != nil {
|
||||
@@ -59,7 +140,12 @@ func GetLeechsAndSeeds(ctx context.Context, r *cache.Redis, m *monitoring.Metric
|
||||
var peerChan = make(chan peers)
|
||||
var errChan = make(chan error)
|
||||
|
||||
for _, tracker := range trackers {
|
||||
allTrackers := make([]string, 0, len(trackers)+len(additionalTrackers))
|
||||
allTrackers = append(allTrackers, trackers...)
|
||||
allTrackers = append(allTrackers, additionalTrackers...)
|
||||
allTrackers = utils.StableUniq(allTrackers)
|
||||
|
||||
for _, tracker := range allTrackers {
|
||||
go func(tracker string) {
|
||||
// get peers and seeds from redis first
|
||||
scraper, err := New(tracker)
|
||||
@@ -85,7 +171,7 @@ func GetLeechsAndSeeds(ctx context.Context, r *cache.Redis, m *monitoring.Metric
|
||||
}
|
||||
|
||||
var peer peers
|
||||
for i := 0; i < len(trackers); i++ {
|
||||
for i := 0; i < len(allTrackers); i++ {
|
||||
select {
|
||||
case <-errChan:
|
||||
// discard error
|
||||
|
||||
@@ -19,6 +19,18 @@ type SearchIndexer struct {
|
||||
IndexName string
|
||||
}
|
||||
|
||||
// IndexStats represents statistics about the Meilisearch index
|
||||
type IndexStats struct {
|
||||
NumberOfDocuments int64 `json:"numberOfDocuments"`
|
||||
IsIndexing bool `json:"isIndexing"`
|
||||
FieldDistribution map[string]int64 `json:"fieldDistribution"`
|
||||
}
|
||||
|
||||
// HealthStatus represents the health status of Meilisearch
|
||||
type HealthStatus struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// NewSearchIndexer creates a new instance of SearchIndexer.
|
||||
func NewSearchIndexer(baseURL, apiKey, indexName string) *SearchIndexer {
|
||||
return &SearchIndexer{
|
||||
@@ -145,3 +157,67 @@ func (t *SearchIndexer) SearchTorrent(query string, limit int) ([]schema.Indexed
|
||||
|
||||
return result.Hits, nil
|
||||
}
|
||||
|
||||
// GetStats retrieves statistics about the Meilisearch index including document count.
|
||||
// This method can be used for health checks and monitoring.
|
||||
func (t *SearchIndexer) GetStats() (*IndexStats, error) {
|
||||
url := fmt.Sprintf("%s/indexes/%s/stats", t.BaseURL, t.IndexName)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
if t.APIKey != "" {
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", t.APIKey))
|
||||
}
|
||||
|
||||
resp, err := t.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("failed to get stats: status %d, body: %s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
var stats IndexStats
|
||||
if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse stats response: %w", err)
|
||||
}
|
||||
|
||||
return &stats, nil
|
||||
}
|
||||
|
||||
// IsHealthy checks if Meilisearch is available and responsive.
|
||||
// Returns true if the service is healthy, false otherwise.
|
||||
func (t *SearchIndexer) IsHealthy() bool {
|
||||
url := fmt.Sprintf("%s/health", t.BaseURL)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Use a shorter timeout for health checks
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}
|
||||
|
||||
// GetDocumentCount returns the number of indexed documents.
|
||||
// This is a convenience method that extracts just the document count from stats.
|
||||
func (t *SearchIndexer) GetDocumentCount() (int64, error) {
|
||||
stats, err := t.GetStats()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return stats.NumberOfDocuments, nil
|
||||
}
|
||||
|
||||
28
utils/decoder.go
Normal file
28
utils/decoder.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"html"
|
||||
)
|
||||
|
||||
func DecodeAdLink(encodedStr string) (string, error) {
|
||||
reversed := reverseString(encodedStr)
|
||||
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(reversed)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
htmlUnescaped := html.UnescapeString(string(decodedBytes))
|
||||
|
||||
return htmlUnescaped, nil
|
||||
}
|
||||
|
||||
// Helper function to reverse a string
|
||||
func reverseString(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
103
utils/util.go
103
utils/util.go
@@ -1,7 +1,13 @@
|
||||
package utils
|
||||
|
||||
import "regexp"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
// Filter filters a slice based on a predicate function.
|
||||
func Filter[A any](arr []A, f func(A) bool) []A {
|
||||
var res []A
|
||||
res = make([]A, 0)
|
||||
@@ -13,20 +19,89 @@ func Filter[A any](arr []A, f func(A) bool) []A {
|
||||
return res
|
||||
}
|
||||
|
||||
func IsValidHTML(input string) bool {
|
||||
// Check for <!DOCTYPE> declaration (case-insensitive)
|
||||
doctypeRegex := regexp.MustCompile(`(?i)<!DOCTYPE\s+html>`)
|
||||
if !doctypeRegex.MatchString(input) {
|
||||
return false
|
||||
// ParallelFlatMap applies a function to each item in the iterable concurrently
|
||||
// and returns a slice of results. It can handle errors by passing an error handler function.
|
||||
func ParallelFlatMap[T any, R any](iterable []T, mapper func(item T) ([]R, error), errHandler ...func(error)) []R {
|
||||
var itChan = make(chan []R)
|
||||
var errChan = make(chan error)
|
||||
mappedItems := []R{}
|
||||
for _, link := range iterable {
|
||||
go func(link T) {
|
||||
items, err := mapper(link)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
}
|
||||
itChan <- items
|
||||
}(link)
|
||||
}
|
||||
|
||||
// Check for <html> and </html> tags (case-insensitive)
|
||||
htmlTagRegex := regexp.MustCompile(`(?i)<html[\s\S]*?>[\s\S]*?</html>`)
|
||||
if !htmlTagRegex.MatchString(input) {
|
||||
return false
|
||||
for range iterable {
|
||||
select {
|
||||
case items := <-itChan:
|
||||
mappedItems = append(mappedItems, items...)
|
||||
case err := <-errChan:
|
||||
for _, handler := range errHandler {
|
||||
handler(err)
|
||||
}
|
||||
if len(errHandler) == 0 {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappedItems
|
||||
}
|
||||
|
||||
// StableUniq removes duplicates from a slice while maintaining the order of elements.
|
||||
func StableUniq(s []string) []string {
|
||||
var uniq []map[string]interface{}
|
||||
m := make(map[string]map[string]interface{})
|
||||
for i, v := range s {
|
||||
m[v] = map[string]interface{}{
|
||||
"v": v,
|
||||
"i": i,
|
||||
}
|
||||
}
|
||||
// to order by index
|
||||
for _, v := range m {
|
||||
uniq = append(uniq, v)
|
||||
}
|
||||
|
||||
// sort by index
|
||||
for i := 0; i < len(uniq); i++ {
|
||||
for j := i + 1; j < len(uniq); j++ {
|
||||
if uniq[i]["i"].(int) > uniq[j]["i"].(int) {
|
||||
uniq[i], uniq[j] = uniq[j], uniq[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get only values
|
||||
var uniqValues []string
|
||||
for _, v := range uniq {
|
||||
uniqValues = append(uniqValues, v["v"].(string))
|
||||
}
|
||||
|
||||
return uniqValues
|
||||
}
|
||||
|
||||
func IsValidHTML(input string) bool {
|
||||
r := strings.NewReader(input)
|
||||
_, err := html.Parse(r)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// FormatBytes formats a byte size into a human-readable string.
|
||||
// It converts bytes to KB, MB, or GB as appropriate.
|
||||
func FormatBytes(bytes int64) string {
|
||||
if bytes < 1024 {
|
||||
return fmt.Sprintf("%d B", bytes)
|
||||
} else if bytes < 1024*1024 {
|
||||
return fmt.Sprintf("%.2f KB", float64(bytes)/1024)
|
||||
} else if bytes < 1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2f MB", float64(bytes)/(1024*1024))
|
||||
} else if bytes < 1024*1024*1024*1024 {
|
||||
return fmt.Sprintf("%.2f GB", float64(bytes)/(1024*1024*1024))
|
||||
} else {
|
||||
return fmt.Sprintf("%.2f TB", float64(bytes)/(1024*1024*1024*1024))
|
||||
}
|
||||
|
||||
// Check for <body> and </body> tags (case-insensitive)
|
||||
bodyTagRegex := regexp.MustCompile(`(?i)<body[\s\S]*?>[\s\S]*?</body>`)
|
||||
return bodyTagRegex.MatchString(input)
|
||||
}
|
||||
|
||||
97
utils/website.go
Normal file
97
utils/website.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var commonTLDs = []string{
|
||||
".com",
|
||||
".net",
|
||||
".org",
|
||||
".info",
|
||||
".biz",
|
||||
".co",
|
||||
".io",
|
||||
".xyz",
|
||||
".me",
|
||||
".tv",
|
||||
".cc",
|
||||
".us",
|
||||
".online",
|
||||
".site",
|
||||
".la",
|
||||
".se",
|
||||
".to",
|
||||
}
|
||||
|
||||
var commonSubdomains = []string{
|
||||
"", // no prefix
|
||||
"www.",
|
||||
}
|
||||
|
||||
var commonWebsiteSLDs = []string{
|
||||
"bludv",
|
||||
"torrentdosfilmes",
|
||||
"comando",
|
||||
"comandotorrents",
|
||||
"comandohds",
|
||||
"redetorrent",
|
||||
"torrenting",
|
||||
"baixarfilmesdubladosviatorrent",
|
||||
"hidratorrents",
|
||||
"wolverdonfilmes",
|
||||
"starckfilmes",
|
||||
"rapidotorrents",
|
||||
"sitedetorrents",
|
||||
"vamostorrent",
|
||||
"AZTORRENTS",
|
||||
}
|
||||
|
||||
var websitePatterns = []string{
|
||||
`\[\s*ACESSE\s+%s\s*\]`,
|
||||
`\[?\s*%s(\s*\])?`,
|
||||
}
|
||||
|
||||
var regexesOnce sync.Once
|
||||
var regexes []*regexp.Regexp
|
||||
|
||||
func getRegexes() []*regexp.Regexp {
|
||||
regexesOnce.Do(func() {
|
||||
var websites strings.Builder
|
||||
websites.WriteString("(?i)(")
|
||||
for _, prefix := range commonSubdomains {
|
||||
for _, name := range commonWebsiteSLDs {
|
||||
for _, tld := range commonTLDs {
|
||||
websites.WriteString(fmt.Sprintf("%s%s%s|", prefix, name, tld))
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove the last pipe character
|
||||
websites.WriteString(")")
|
||||
|
||||
websitesStr := websites.String()
|
||||
websitesStr = strings.Replace(websitesStr, "|)", ")", 1)
|
||||
|
||||
for _, pattern := range websitePatterns {
|
||||
regexes = append(regexes, regexp.MustCompile(fmt.Sprintf(pattern, websitesStr)))
|
||||
}
|
||||
})
|
||||
return regexes
|
||||
}
|
||||
|
||||
// RemoveKnownWebsites removes known website patterns from the title.
|
||||
// It uses a set of common prefixes, names, and TLDs to identify and remove
|
||||
// website references from the title.
|
||||
// It also removes any common patterns like "[ ACESSE bludv.com ]" or
|
||||
// "[ bludv.se ]" or "bludv.xyz".
|
||||
func RemoveKnownWebsites(title string) string {
|
||||
regexes := getRegexes()
|
||||
for _, re := range regexes {
|
||||
title = re.ReplaceAllString(title, "")
|
||||
}
|
||||
title = strings.TrimSpace(title)
|
||||
return title
|
||||
}
|
||||
Reference in New Issue
Block a user