implement itunes search

pull/24/head
Akhil Gupta 4 years ago
parent 60b33e6e99
commit 6319fdf86f

@ -35,7 +35,7 @@
<hr>
<div class="row" id="searchContainer">
<h4>Search for your favorite podcast</h4>
<p>Experimental: Uses gpodder API to show search results.</p>
<p>Experimental: Uses iTunes API to show search results.</p>
<form action="/search" method="post" @submit="search">
<div class="nine columns">
<input type="search" name="search" id="search" placeholder="Search for your podcast" v-model="query" class="u-full-width">
@ -50,7 +50,7 @@
<div v-for="item in results" :key="item.url" class="row">
<div class="columns two">
<img class="u-full-width" :src="item.scaled_logo_url" :alt="item.title">
<img class="u-full-width" :src="item.image" :alt="item.title">
</div>
<div class="columns nine">
<h5>${item.title}</h5>
@ -135,6 +135,7 @@ var app = new Vue({
}).
then(function(){
self.searching=false;
self.url=""
})
return false;
}

@ -57,7 +57,7 @@ hr{
<div class="row">
<div class="columns nine">
<h4>{{.Title}} // {{ .Podcast.Title}}</h4>
<h4>{{.Title}} {{if .Podcast.Title }} // {{ .Podcast.Title}} {{end}}</h4>
</div>
<div class="columns two">
<small>{{ formatDate .PubDate }}</small>

@ -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))

@ -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"`
}

@ -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"`
}

@ -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)

@ -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
}

@ -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
}

Loading…
Cancel
Save