@@ -135,6 +135,7 @@ var app = new Vue({
}).
then(function(){
self.searching=false;
+ self.url=""
})
return false;
}
diff --git a/client/episodes.html b/client/episodes.html
index 3d732ca..46a4349 100644
--- a/client/episodes.html
+++ b/client/episodes.html
@@ -57,7 +57,7 @@ hr{
-
{{.Title}} // {{ .Podcast.Title}}
+ {{.Title}} {{if .Podcast.Title }} // {{ .Podcast.Title}} {{end}}
{{ formatDate .PubDate }}
diff --git a/controllers/pages.go b/controllers/pages.go
index ce0da23..387d574 100644
--- a/controllers/pages.go
+++ b/controllers/pages.go
@@ -32,7 +32,17 @@ func PodcastPage(c *gin.Context) {
if err := db.GetPodcastById(searchByIdQuery.Id, &podcast); err == nil {
setting := c.MustGet("setting").(*db.Setting)
- c.HTML(http.StatusOK, "podcast.html", gin.H{"title": podcast.Title, "podcast": podcast, "setting": setting})
+ c.HTML(http.StatusOK, "episodes.html", gin.H{
+ "title": podcast.Title,
+ "podcastItems": podcast.PodcastItems,
+ "setting": setting,
+ "page": 1,
+ "count": 10,
+ "totalCount": len(podcast.PodcastItems),
+ "totalPages": 0,
+ "nextPage": 0,
+ "previousPage": 0,
+ })
} else {
c.JSON(http.StatusBadRequest, err)
}
@@ -86,7 +96,8 @@ func AllEpisodesPage(c *gin.Context) {
func Search(c *gin.Context) {
var searchQuery SearchGPodderData
if c.ShouldBindQuery(&searchQuery) == nil {
- data := service.Query(searchQuery.Q)
+ itunesService := new(service.ItunesService)
+ data := itunesService.Query(searchQuery.Q)
allPodcasts := service.GetAllPodcasts()
urls := make(map[string]string, len(*allPodcasts))
diff --git a/model/itunesModel.go b/model/itunesModel.go
new file mode 100644
index 0000000..d163913
--- /dev/null
+++ b/model/itunesModel.go
@@ -0,0 +1,45 @@
+package model
+
+import "time"
+
+type ItunesResponse struct {
+ ResultCount int `json:"resultCount"`
+ Results []ItunesSingleResult `json:"results"`
+}
+
+type ItunesSingleResult struct {
+ WrapperType string `json:"wrapperType"`
+ Kind string `json:"kind"`
+ CollectionID int `json:"collectionId"`
+ TrackID int `json:"trackId"`
+ ArtistName string `json:"artistName"`
+ CollectionName string `json:"collectionName"`
+ TrackName string `json:"trackName"`
+ CollectionCensoredName string `json:"collectionCensoredName"`
+ TrackCensoredName string `json:"trackCensoredName"`
+ CollectionViewURL string `json:"collectionViewUrl"`
+ FeedURL string `json:"feedUrl"`
+ TrackViewURL string `json:"trackViewUrl"`
+ ArtworkURL30 string `json:"artworkUrl30"`
+ ArtworkURL60 string `json:"artworkUrl60"`
+ ArtworkURL100 string `json:"artworkUrl100"`
+ CollectionPrice float64 `json:"collectionPrice"`
+ TrackPrice float64 `json:"trackPrice"`
+ TrackRentalPrice int `json:"trackRentalPrice"`
+ CollectionHdPrice int `json:"collectionHdPrice"`
+ TrackHdPrice int `json:"trackHdPrice"`
+ TrackHdRentalPrice int `json:"trackHdRentalPrice"`
+ ReleaseDate time.Time `json:"releaseDate"`
+ CollectionExplicitness string `json:"collectionExplicitness"`
+ TrackExplicitness string `json:"trackExplicitness"`
+ TrackCount int `json:"trackCount"`
+ Country string `json:"country"`
+ Currency string `json:"currency"`
+ PrimaryGenreName string `json:"primaryGenreName"`
+ ContentAdvisoryRating string `json:"contentAdvisoryRating,omitempty"`
+ ArtworkURL600 string `json:"artworkUrl600"`
+ GenreIds []string `json:"genreIds"`
+ Genres []string `json:"genres"`
+ ArtistID int `json:"artistId,omitempty"`
+ ArtistViewURL string `json:"artistViewUrl,omitempty"`
+}
diff --git a/model/podcastModels.go b/model/podcastModels.go
index 08d40d1..72b3f83 100644
--- a/model/podcastModels.go
+++ b/model/podcastModels.go
@@ -91,3 +91,11 @@ type PodcastData struct {
} `xml:"item"`
} `xml:"channel"`
}
+
+type CommonSearchResultModel struct {
+ URL string `json:"url"`
+ Title string `json:"title"`
+ Image string `json:"image"`
+ AlreadySaved bool `json:"already_saved"`
+ Description string `json:"description"`
+}
diff --git a/service/gpodderService.go b/service/gpodderService.go
index d70580b..09b9be4 100644
--- a/service/gpodderService.go
+++ b/service/gpodderService.go
@@ -13,13 +13,20 @@ import (
const BASE = "https://gpodder.net"
-func Query(q string) []model.GPodcast {
+func Query(q string) []*model.CommonSearchResultModel {
url := fmt.Sprintf("%s/search.json?q=%s", BASE, url.QueryEscape(q))
body, _ := makeQuery(url)
var response []model.GPodcast
json.Unmarshal(body, &response)
- return response
+
+ var toReturn []*model.CommonSearchResultModel
+
+ for _, obj := range response {
+ toReturn = append(toReturn, GetSearchFromGpodder(obj))
+ }
+
+ return toReturn
}
func ByTag(tag string, count int) []model.GPodcast {
url := fmt.Sprintf("%s/api/2/tag/%s/%d.json", BASE, url.QueryEscape(tag), count)
diff --git a/service/itunesService.go b/service/itunesService.go
new file mode 100644
index 0000000..c30784f
--- /dev/null
+++ b/service/itunesService.go
@@ -0,0 +1,30 @@
+package service
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/url"
+
+ "github.com/akhilrex/podgrab/model"
+)
+
+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
+}
diff --git a/service/podcastService.go b/service/podcastService.go
index 3164c21..62bd3aa 100644
--- a/service/podcastService.go
+++ b/service/podcastService.go
@@ -198,3 +198,19 @@ func makeQuery(url string) ([]byte, error) {
return body, nil
}
+func GetSearchFromGpodder(pod model.GPodcast) *model.CommonSearchResultModel {
+ p := new(model.CommonSearchResultModel)
+ p.URL = pod.URL
+ p.Image = pod.LogoURL
+ p.Title = pod.Title
+ p.Description = pod.Description
+ return p
+}
+func GetSearchFromItunes(pod model.ItunesSingleResult) *model.CommonSearchResultModel {
+ p := new(model.CommonSearchResultModel)
+ p.URL = pod.FeedURL
+ p.Image = pod.ArtworkURL600
+ p.Title = pod.TrackName
+
+ return p
+}