Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c02f72e13 | |||
| 339db28d5a | |||
| 5034a11a66 | |||
| e994ee109d | |||
| a6977aec0d |
@@ -10,6 +10,7 @@ Visit [https://torrent-indexer.darklyn.org/](https://torrent-indexer.darklyn.org
|
|||||||
|
|
||||||
- [comando-torrents](https://comando.la/)
|
- [comando-torrents](https://comando.la/)
|
||||||
- [bludv](https://bludvfilmes.tv/)
|
- [bludv](https://bludvfilmes.tv/)
|
||||||
|
- [torrent-dos-filmes](https://torrentdosfilmes.se/)
|
||||||
|
|
||||||
## Deploy
|
## Deploy
|
||||||
|
|
||||||
|
|||||||
10
api/index.go
10
api/index.go
@@ -78,6 +78,16 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
"/indexers/torrent-dos-filmes": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"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)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"/indexers/manual": []map[string]interface{}{
|
"/indexers/manual": []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
|
|||||||
267
api/torrent_dos_filmes.go
Normal file
267
api/torrent_dos_filmes.go
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"regexp"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
"github.com/hbollon/go-edlib"
|
||||||
|
|
||||||
|
"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 torrent_dos_filmes = IndexerMeta{
|
||||||
|
URL: "https://torrentdosfilmes.se/",
|
||||||
|
SearchURL: "?s=",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Indexer) HandlerTorrentDosFilmesIndexer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
start := time.Now()
|
||||||
|
defer func() {
|
||||||
|
i.metrics.IndexerDuration.WithLabelValues("torrent_dos_filmes").Observe(time.Since(start).Seconds())
|
||||||
|
i.metrics.IndexerRequests.WithLabelValues("torrent_dos_filmes").Inc()
|
||||||
|
}()
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
|
// supported query params: q, season, episode, filter_results
|
||||||
|
q := r.URL.Query().Get("q")
|
||||||
|
|
||||||
|
// URL encode query param
|
||||||
|
q = url.QueryEscape(q)
|
||||||
|
url := torrent_dos_filmes.URL
|
||||||
|
if q != "" {
|
||||||
|
url = fmt.Sprintf("%s%s%s", url, torrent_dos_filmes.SearchURL, q)
|
||||||
|
}
|
||||||
|
|
||||||
|
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("torrent_dos_filmes").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("torrent_dos_filmes").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)
|
||||||
|
})
|
||||||
|
|
||||||
|
var itChan = make(chan []IndexedTorrent)
|
||||||
|
var errChan = make(chan error)
|
||||||
|
indexedTorrents := []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 IndexedTorrent) bool {
|
||||||
|
return it.Similarity > 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort by similarity
|
||||||
|
slices.SortFunc(indexedTorrents, func(i, j IndexedTorrent) int {
|
||||||
|
return int((j.Similarity - i.Similarity) * 1000)
|
||||||
|
})
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
err = json.NewEncoder(w).Encode(Response{
|
||||||
|
Results: indexedTorrents,
|
||||||
|
Count: len(indexedTorrents),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTorrentsTorrentDosFilmes(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
||||||
|
var indexedTorrents []IndexedTorrent
|
||||||
|
doc, err := getDocument(ctx, i, link)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
article := doc.Find("article")
|
||||||
|
title := strings.Replace(article.Find(".title > h1").Text(), " - Download", "", -1)
|
||||||
|
textContent := article.Find("div.content")
|
||||||
|
date := getPublishedDateTDF(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:
|
||||||
|
// Título Traduzido: Fundação
|
||||||
|
// Título Original: Foundation
|
||||||
|
// IMDb: 7,5
|
||||||
|
// Ano de Lançamento: 2023
|
||||||
|
// Gênero: Ação | Aventura | Ficção
|
||||||
|
// Formato: MKV
|
||||||
|
// Qualidade: WEB-DL
|
||||||
|
// Áudio: Português | Inglês
|
||||||
|
// Idioma: Português | Inglês
|
||||||
|
// Legenda: Português
|
||||||
|
// Tamanho: –
|
||||||
|
// Qualidade de Áudio: 10
|
||||||
|
// Qualidade de Vídeo: 10
|
||||||
|
// Duração: 59 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")
|
||||||
|
re := regexp.MustCompile(`https://www.imdb.com/title/(tt\d+)`)
|
||||||
|
matches := re.FindStringSubmatch(link)
|
||||||
|
if len(matches) > 0 {
|
||||||
|
imdbLink = matches[0]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
size = stableUniq(size)
|
||||||
|
|
||||||
|
var chanIndexedTorrent = make(chan IndexedTorrent)
|
||||||
|
|
||||||
|
// 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 := []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...)
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
|
||||||
|
ixt := IndexedTorrent{
|
||||||
|
Title: appendAudioISO639_2Code(releaseTitle, magnetAudio),
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
1
main.go
1
main.go
@@ -26,6 +26,7 @@ func main() {
|
|||||||
|
|
||||||
indexerMux.HandleFunc("/", handler.HandlerIndex)
|
indexerMux.HandleFunc("/", handler.HandlerIndex)
|
||||||
indexerMux.HandleFunc("/indexers/comando_torrents", indexers.HandlerComandoIndexer)
|
indexerMux.HandleFunc("/indexers/comando_torrents", indexers.HandlerComandoIndexer)
|
||||||
|
indexerMux.HandleFunc("/indexers/torrent-dos-filmes", indexers.HandlerTorrentDosFilmesIndexer)
|
||||||
indexerMux.HandleFunc("/indexers/bludv", indexers.HandlerBluDVIndexer)
|
indexerMux.HandleFunc("/indexers/bludv", indexers.HandlerBluDVIndexer)
|
||||||
indexerMux.HandleFunc("/indexers/manual", indexers.HandlerManualIndexer)
|
indexerMux.HandleFunc("/indexers/manual", indexers.HandlerManualIndexer)
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/cookiejar"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -19,6 +21,10 @@ type FlareSolverr struct {
|
|||||||
initiated bool
|
initiated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrListSessions = fmt.Errorf("failed to list sessions")
|
||||||
|
)
|
||||||
|
|
||||||
func NewFlareSolverr(url string, timeoutMilli int) *FlareSolverr {
|
func NewFlareSolverr(url string, timeoutMilli int) *FlareSolverr {
|
||||||
poolSize := 5
|
poolSize := 5
|
||||||
httpClient := &http.Client{}
|
httpClient := &http.Client{}
|
||||||
@@ -48,6 +54,14 @@ func (f *FlareSolverr) FillSessionPool() error {
|
|||||||
// Pre-initialize the pool with existing sessions
|
// Pre-initialize the pool with existing sessions
|
||||||
sessions, err := f.ListSessions()
|
sessions, err := f.ListSessions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// if fail to list sessions, it may not support the sessions.list command
|
||||||
|
// create new dumb sessions to fill the pool
|
||||||
|
if err == ErrListSessions {
|
||||||
|
for len(f.sessionPool) < cap(f.sessionPool) {
|
||||||
|
f.sessionPool <- "dumb-session"
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
fmt.Println("Failed to list existing FlareSolverr sessions:", err)
|
fmt.Println("Failed to list existing FlareSolverr sessions:", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
@@ -134,6 +148,9 @@ func (f *FlareSolverr) ListSessions() ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if sessionsResponse["sessions"] == nil {
|
||||||
|
return nil, ErrListSessions
|
||||||
|
}
|
||||||
|
|
||||||
sessions := sessionsResponse["sessions"].([]interface{})
|
sessions := sessionsResponse["sessions"].([]interface{})
|
||||||
var sessionIDs []string
|
var sessionIDs []string
|
||||||
@@ -172,7 +189,7 @@ type Response struct {
|
|||||||
} `json:"solution"`
|
} `json:"solution"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlareSolverr) Get(url string) (io.ReadCloser, error) {
|
func (f *FlareSolverr) Get(_url string) (io.ReadCloser, error) {
|
||||||
// Check if the FlareSolverr instance was initiated
|
// Check if the FlareSolverr instance was initiated
|
||||||
if !f.initiated {
|
if !f.initiated {
|
||||||
return io.NopCloser(bytes.NewReader([]byte(""))), nil
|
return io.NopCloser(bytes.NewReader([]byte(""))), nil
|
||||||
@@ -188,7 +205,7 @@ func (f *FlareSolverr) Get(url string) (io.ReadCloser, error) {
|
|||||||
|
|
||||||
body := map[string]string{
|
body := map[string]string{
|
||||||
"cmd": "request.get",
|
"cmd": "request.get",
|
||||||
"url": url,
|
"url": _url,
|
||||||
"maxTimeout": fmt.Sprintf("%d", f.maxTimeout),
|
"maxTimeout": fmt.Sprintf("%d", f.maxTimeout),
|
||||||
"session": session,
|
"session": session,
|
||||||
}
|
}
|
||||||
@@ -196,6 +213,7 @@ func (f *FlareSolverr) Get(url string) (io.ReadCloser, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v1", f.url), bytes.NewBuffer(jsonBody))
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v1", f.url), bytes.NewBuffer(jsonBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -225,6 +243,40 @@ func (f *FlareSolverr) Get(url string) (io.ReadCloser, error) {
|
|||||||
return nil, fmt.Errorf("under attack")
|
return nil, fmt.Errorf("under attack")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the response body
|
// If the response body is empty but cookies are present, make a new request
|
||||||
|
if response.Solution.Response == "" && len(response.Solution.Cookies) > 0 {
|
||||||
|
// Create a new request with cookies
|
||||||
|
client := &http.Client{}
|
||||||
|
cookieJar, err := cookiejar.New(&cookiejar.Options{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, cookie := range response.Solution.Cookies {
|
||||||
|
cookieJar.SetCookies(&url.URL{Host: cookie.Domain}, []*http.Cookie{
|
||||||
|
{
|
||||||
|
Name: cookie.Name,
|
||||||
|
Value: cookie.Value,
|
||||||
|
Domain: cookie.Domain,
|
||||||
|
Path: cookie.Path,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
client.Jar = cookieJar
|
||||||
|
|
||||||
|
secondReq, err := http.NewRequest("GET", _url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
secondResp, err := client.Do(secondReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the body of the second request
|
||||||
|
return secondResp.Body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the original response body
|
||||||
return io.NopCloser(bytes.NewReader([]byte(response.Solution.Response))), nil
|
return io.NopCloser(bytes.NewReader([]byte(response.Solution.Response))), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
type Audio string
|
type Audio string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AudioPortuguese = "Português"
|
AudioPortuguese = "Português"
|
||||||
AudioPortuguese2 = "Portugues"
|
AudioPortuguese2 = "Portugues"
|
||||||
|
AudioPortuguese3 = "PT-BR"
|
||||||
|
AudioPortuguese4 = "Dublado"
|
||||||
AudioEnglish = "Inglês"
|
AudioEnglish = "Inglês"
|
||||||
AudioEnglish2 = "Ingles"
|
AudioEnglish2 = "Ingles"
|
||||||
AudioSpanish = "Espanhol"
|
AudioSpanish = "Espanhol"
|
||||||
@@ -28,11 +32,14 @@ const (
|
|||||||
AudioThai = "Tailandês"
|
AudioThai = "Tailandês"
|
||||||
AudioThai2 = "Tailandes"
|
AudioThai2 = "Tailandes"
|
||||||
AudioTurkish = "Turco"
|
AudioTurkish = "Turco"
|
||||||
|
AudioHindi = "Hindi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AudioList = []Audio{
|
var AudioList = []Audio{
|
||||||
AudioPortuguese,
|
AudioPortuguese,
|
||||||
AudioPortuguese2,
|
AudioPortuguese2,
|
||||||
|
AudioPortuguese3,
|
||||||
|
AudioPortuguese4,
|
||||||
AudioEnglish,
|
AudioEnglish,
|
||||||
AudioEnglish2,
|
AudioEnglish2,
|
||||||
AudioSpanish,
|
AudioSpanish,
|
||||||
@@ -56,27 +63,32 @@ var AudioList = []Audio{
|
|||||||
AudioThai,
|
AudioThai,
|
||||||
AudioThai2,
|
AudioThai2,
|
||||||
AudioTurkish,
|
AudioTurkish,
|
||||||
|
AudioHindi,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Audio) String() string {
|
func (a Audio) String() string {
|
||||||
return a.toISO639_2()
|
return a.toTag()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAudioFromString(s string) *Audio {
|
func GetAudioFromString(s string) *Audio {
|
||||||
for _, a := range AudioList {
|
for _, a := range AudioList {
|
||||||
if string(a) == s {
|
if strings.EqualFold(string(a), s) {
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Audio) toISO639_2() string {
|
func (a Audio) toTag() string {
|
||||||
switch a {
|
switch a {
|
||||||
case AudioPortuguese:
|
case AudioPortuguese:
|
||||||
return "por"
|
return "brazilian"
|
||||||
case AudioPortuguese2:
|
case AudioPortuguese2:
|
||||||
return "por"
|
return "brazilian"
|
||||||
|
case AudioPortuguese3:
|
||||||
|
return "brazilian"
|
||||||
|
case AudioPortuguese4:
|
||||||
|
return "brazilian"
|
||||||
case AudioEnglish:
|
case AudioEnglish:
|
||||||
return "eng"
|
return "eng"
|
||||||
case AudioEnglish2:
|
case AudioEnglish2:
|
||||||
@@ -123,6 +135,8 @@ func (a Audio) toISO639_2() string {
|
|||||||
return "tha"
|
return "tha"
|
||||||
case AudioTurkish:
|
case AudioTurkish:
|
||||||
return "tur"
|
return "tur"
|
||||||
|
case AudioHindi:
|
||||||
|
return "hin"
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user