/
itunesService.go
61 lines (45 loc) · 1.28 KB
/
itunesService.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
package service
import (
"encoding/json"
"fmt"
"log"
"net/url"
"github.com/TheHippo/podcastindex"
"github.com/akhilrex/podgrab/model"
)
type SearchService interface {
Query(q string) []*model.CommonSearchResultModel
}
type ItunesService struct {
}
const ITUNES_BASE = "https://itunes.apple.com"
func (service ItunesService) Query(q string) []*model.CommonSearchResultModel {
url := fmt.Sprintf("%s/search?term=%s&entity=podcast", ITUNES_BASE, url.QueryEscape(q))
body, _ := makeQuery(url)
var response model.ItunesResponse
json.Unmarshal(body, &response)
var toReturn []*model.CommonSearchResultModel
for _, obj := range response.Results {
toReturn = append(toReturn, GetSearchFromItunes(obj))
}
return toReturn
}
type PodcastIndexService struct {
}
const (
PODCASTINDEX_KEY = "LNGTNUAFVL9W2AQKVZ49"
PODCASTINDEX_SECRET = "H8tq^CZWYmAywbnngTwB$rwQHwMSR8#fJb#Bhgb3"
)
func (service PodcastIndexService) Query(q string) []*model.CommonSearchResultModel {
c := podcastindex.NewClient(PODCASTINDEX_KEY, PODCASTINDEX_SECRET)
var toReturn []*model.CommonSearchResultModel
podcasts, err := c.Search(q)
if err != nil {
log.Fatal(err.Error())
return toReturn
}
for _, obj := range podcasts {
toReturn = append(toReturn, GetSearchFromPodcastIndex(obj))
}
return toReturn
}