2022-04-21 15:14:49 -03:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
2023-09-23 17:02:55 +00:00
|
|
|
"encoding/json"
|
2022-04-21 15:14:49 -03:00
|
|
|
"net/http"
|
|
|
|
|
"time"
|
2023-09-23 17:02:55 +00:00
|
|
|
|
|
|
|
|
"github.com/felipemarinho97/torrent-indexer/cache"
|
2025-07-29 13:22:21 -03:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/consts"
|
2025-07-29 12:34:37 -03:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/magnet"
|
2024-03-10 14:00:07 +00:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/monitoring"
|
2024-09-24 18:31:58 -03:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/requester"
|
2023-10-01 20:27:44 +00:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/schema"
|
2024-12-13 11:54:55 -03:00
|
|
|
meilisearch "github.com/felipemarinho97/torrent-indexer/search"
|
2022-04-21 15:14:49 -03:00
|
|
|
)
|
|
|
|
|
|
2023-09-23 17:02:55 +00:00
|
|
|
type Indexer struct {
|
2025-07-29 12:34:37 -03:00
|
|
|
redis *cache.Redis
|
|
|
|
|
metrics *monitoring.Metrics
|
|
|
|
|
requester *requester.Requster
|
|
|
|
|
search *meilisearch.SearchIndexer
|
|
|
|
|
magnetMetadataAPI *magnet.MetadataClient
|
|
|
|
|
postProcessors []PostProcessorFunc
|
2023-09-23 17:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-01 20:27:44 +00:00
|
|
|
type IndexerMeta struct {
|
2025-07-24 01:03:38 -03:00
|
|
|
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"
|
2023-10-01 20:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 17:04:12 +00:00
|
|
|
type Response struct {
|
2024-12-13 11:54:55 -03:00
|
|
|
Results []schema.IndexedTorrent `json:"results"`
|
|
|
|
|
Count int `json:"count"`
|
2024-02-12 17:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 01:03:38 -03:00
|
|
|
type PostProcessorFunc func(*Indexer, *http.Request, []schema.IndexedTorrent) []schema.IndexedTorrent
|
|
|
|
|
|
|
|
|
|
var GlobalPostProcessors = []PostProcessorFunc{
|
2025-07-29 12:34:37 -03:00
|
|
|
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
|
2025-07-24 01:03:38 -03:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 12:34:37 -03:00
|
|
|
func NewIndexers(
|
|
|
|
|
redis *cache.Redis,
|
|
|
|
|
metrics *monitoring.Metrics,
|
|
|
|
|
req *requester.Requster,
|
|
|
|
|
si *meilisearch.SearchIndexer,
|
|
|
|
|
mc *magnet.MetadataClient,
|
|
|
|
|
) *Indexer {
|
2023-09-23 17:02:55 +00:00
|
|
|
return &Indexer{
|
2025-07-29 12:34:37 -03:00
|
|
|
redis: redis,
|
|
|
|
|
metrics: metrics,
|
|
|
|
|
requester: req,
|
|
|
|
|
search: si,
|
|
|
|
|
magnetMetadataAPI: mc,
|
|
|
|
|
postProcessors: GlobalPostProcessors,
|
2023-09-23 17:02:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 15:14:49 -03:00
|
|
|
func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
currentTime := time.Now().Format(time.RFC850)
|
2023-09-23 17:02:55 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2024-04-28 11:52:01 -03:00
|
|
|
err := json.NewEncoder(w).Encode(map[string]interface{}{
|
2025-07-29 13:22:21 -03:00
|
|
|
"time": currentTime,
|
|
|
|
|
"build": consts.GetBuildInfo(),
|
2023-09-23 17:02:55 +00:00
|
|
|
"endpoints": map[string]interface{}{
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/comando_torrents": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Indexer for comando torrents",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-06-18 12:38:08 -03:00
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
2023-09-23 17:02:55 +00:00
|
|
|
},
|
|
|
|
|
},
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/bludv": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Indexer for bludv",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-06-18 12:38:08 -03:00
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
}},
|
|
|
|
|
},
|
2024-11-18 18:54:30 -03:00
|
|
|
"/indexers/torrent-dos-filmes": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-11-18 18:54:30 -03:00
|
|
|
"description": "Indexer for Torrent dos Filmes",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 15:32:27 -03:00
|
|
|
"/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)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 15:25:17 -03:00
|
|
|
"/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)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-22 14:57:05 -03:00
|
|
|
"/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)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/manual": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "POST",
|
|
|
|
|
"description": "Add a manual torrent entry to the indexer for 12 hours",
|
|
|
|
|
"body": map[string]interface{}{
|
|
|
|
|
"magnetLink": "magnet link",
|
|
|
|
|
}},
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Get all manual torrents",
|
2023-10-01 20:27:44 +00:00
|
|
|
},
|
|
|
|
|
},
|
2024-12-13 11:54:55 -03:00
|
|
|
"/search": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Search for cached torrents across all indexers",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-22 14:57:05 -03:00
|
|
|
"/ui/": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Show the unified search UI (only work if Meilisearch is enabled)",
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-09-23 17:02:55 +00:00
|
|
|
},
|
|
|
|
|
})
|
2024-04-28 11:52:01 -03:00
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
}
|
2022-04-21 15:14:49 -03:00
|
|
|
}
|