-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
81 lines (71 loc) · 2.21 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package api
import (
"encoding/json"
"fmt"
"strconv"
"github.com/mrjdainc/da-inc/config"
"github.com/mrjdainc/da-inc/providers"
"github.com/mrjdainc/da-inc/tmdb"
"github.com/mrjdainc/da-inc/xbmc"
"github.com/gin-gonic/gin"
)
type providerDebugResponse struct {
Payload interface{} `json:"payload"`
Results interface{} `json:"results"`
}
// ProviderGetMovie ...
func ProviderGetMovie(ctx *gin.Context) {
tmdbID := ctx.Params.ByName("tmdbId")
provider := ctx.Params.ByName("provider")
log.Infof("Searching links for:", tmdbID)
movie := tmdb.GetMovieByID(tmdbID, config.Get().Language)
log.Infof("Resolved %s to %s", tmdbID, movie.Title)
searcher := providers.NewAddonSearcher(provider)
torrents := searcher.SearchMovieLinks(movie)
if ctx.Query("resolve") == "true" {
for _, torrent := range torrents {
torrent.Resolve()
}
}
data, err := json.MarshalIndent(providerDebugResponse{
Payload: searcher.GetMovieSearchObject(movie),
Results: torrents,
}, "", " ")
if err != nil {
xbmc.AddonFailure(provider)
ctx.Error(err)
}
ctx.Data(200, "application/json", data)
}
// ProviderGetEpisode ...
func ProviderGetEpisode(ctx *gin.Context) {
provider := ctx.Params.ByName("provider")
showID, _ := strconv.Atoi(ctx.Params.ByName("showId"))
seasonNumber, _ := strconv.Atoi(ctx.Params.ByName("season"))
episodeNumber, _ := strconv.Atoi(ctx.Params.ByName("episode"))
log.Infof("Searching links for TMDB Id:", showID)
show := tmdb.GetShow(showID, config.Get().Language)
season := tmdb.GetSeason(showID, seasonNumber, config.Get().Language, len(show.Seasons))
if season == nil {
ctx.Error(fmt.Errorf("Unable to get season %d", seasonNumber))
return
}
episode := season.Episodes[episodeNumber-1]
log.Infof("Resolved %d to %s", showID, show.Name)
searcher := providers.NewAddonSearcher(provider)
torrents := searcher.SearchEpisodeLinks(show, episode)
if ctx.Query("resolve") == "true" {
for _, torrent := range torrents {
torrent.Resolve()
}
}
data, err := json.MarshalIndent(providerDebugResponse{
Payload: searcher.GetEpisodeSearchObject(show, episode),
Results: torrents,
}, "", " ")
if err != nil {
xbmc.AddonFailure(provider)
ctx.Error(err)
}
ctx.Data(200, "application/json", data)
}