added podcast index search

pull/60/head
Akhil Gupta 4 years ago
parent ff631fafdb
commit 1dc2ca3c57

@ -87,7 +87,7 @@
>
<br />
<form action="/search" method="post" @submit="search">
<div class="nine columns">
<div class="seven columns">
<input
type="search"
name="search"
@ -98,6 +98,19 @@
/>
</div>
<div class="three columns">
<select
type="submit"
class="u-full-width button"
v-model="searchSource"
name="searchSource"
>
{{range $key, $value := .searchOptions}}
<option value="{{$key}}">{{$value}}</option>
{{end}}
</select>
</div>
<div class="two columns">
<input
type="submit"
value="Search"
@ -118,9 +131,12 @@
/>
</div>
<div class="columns nine">
<h5>${item.title}</h5>
<h5 style="margin-bottom: 0px;">${item.title}</h5>
<small v-if="item.categories && item.categories.length">
<p>${ item.description }</p>
Categories: ${item.categories.join(', ')}
</small>
<p v-if="item.description">${ item.description }</p>
</div>
<div class="columns one">
<button
@ -154,10 +170,26 @@
data: {
results: [],
query: "",
searchSource:"itunes",
searching: false,
url: "",
selectedFiles: undefined,
},
mounted(){
if(localStorage && localStorage.searchSource){
this.searchSource=localStorage.searchSource;
}
},
watch:{
searchSource(newSource,oldSource){
if(newSource===oldSource){
return;
}
if(localStorage){
localStorage.searchSource=newSource
}
}
},
methods: {
selectFile: function () {
this.selectedFiles = this.$refs.file.files;
@ -212,7 +244,7 @@
var self = this;
self.searching = true;
axios
.get("/search?q=" + this.query)
.get("/search?q=" + this.query+"&searchSource="+this.searchSource)
.then(function (response) {
self.results = response.data;
})

@ -7,7 +7,6 @@ import (
"math"
"net/http"
"os"
"strconv"
"strings"
"time"
@ -17,7 +16,8 @@ import (
)
type SearchGPodderData struct {
Q string `binding:"required" form:"q" json:"q" query:"q"`
Q string `binding:"required" form:"q" json:"q" query:"q"`
SearchSource string `binding:"required" form:"searchSource" json:"searchSource" query:"searchSource"`
}
type SettingModel struct {
DownloadOnAdd bool `form:"downloadOnAdd" json:"downloadOnAdd" query:"downloadOnAdd"`
@ -29,9 +29,18 @@ type SettingModel struct {
DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"`
}
var searchOptions = map[string]string{
"itunes": "iTunes",
"podcastindex": "PodcastIndex",
}
var searchProvider = map[string]service.SearchService{
"itunes": new(service.ItunesService),
"podcastindex": new(service.PodcastIndexService),
}
func AddPage(c *gin.Context) {
setting := c.MustGet("setting").(*db.Setting)
c.HTML(http.StatusOK, "addPodcast.html", gin.H{"title": "Add Podcast", "setting": setting})
c.HTML(http.StatusOK, "addPodcast.html", gin.H{"title": "Add Podcast", "setting": setting, "searchOptions": searchOptions})
}
func HomePage(c *gin.Context) {
//var podcasts []db.Podcast
@ -321,18 +330,21 @@ func AllTagsPage(c *gin.Context) {
func Search(c *gin.Context) {
var searchQuery SearchGPodderData
if c.ShouldBindQuery(&searchQuery) == nil {
itunesService := new(service.ItunesService)
data := itunesService.Query(searchQuery.Q)
var searcher service.SearchService
var isValidSearchProvider bool
if searcher, isValidSearchProvider = searchProvider[searchQuery.SearchSource]; !isValidSearchProvider {
searcher = new(service.PodcastIndexService)
}
data := searcher.Query(searchQuery.Q)
allPodcasts := service.GetAllPodcasts("")
urls := make(map[string]string, len(*allPodcasts))
for _, pod := range *allPodcasts {
fmt.Println(pod.URL)
urls[pod.URL] = pod.ID
}
for _, pod := range data {
_, ok := urls[pod.URL]
fmt.Println(pod.URL + " " + strconv.FormatBool(ok))
pod.AlreadySaved = ok
}
c.JSON(200, data)

@ -3,6 +3,7 @@ module github.com/akhilrex/podgrab
go 1.15
require (
github.com/TheHippo/podcastindex v1.0.0
github.com/antchfx/xmlquery v1.3.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.6.3

@ -1,5 +1,7 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/TheHippo/podcastindex v1.0.0 h1:Bttru+Jih6VjMEfgaTf160L0JjnmnaA+pnZt1pOzCNI=
github.com/TheHippo/podcastindex v1.0.0/go.mod h1:XG6uVUiapExkeTNhOYPX4vkSBVuh3u+69RRcc6u3A4k=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/antchfx/xmlquery v1.3.3 h1:HYmadPG0uz8CySdL68rB4DCLKXz2PurCjS3mnkVF4CQ=
github.com/antchfx/xmlquery v1.3.3/go.mod h1:64w0Xesg2sTaawIdNqMB+7qaW/bSqkQm+ssPaCMWNnc=

@ -93,9 +93,10 @@ type PodcastData struct {
}
type CommonSearchResultModel struct {
URL string `json:"url"`
Title string `json:"title"`
Image string `json:"image"`
AlreadySaved bool `json:"already_saved"`
Description string `json:"description"`
URL string `json:"url"`
Title string `json:"title"`
Image string `json:"image"`
AlreadySaved bool `json:"already_saved"`
Description string `json:"description"`
Categories []string `json:"categories"`
}

@ -3,11 +3,17 @@ 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 {
}
@ -28,3 +34,28 @@ func (service ItunesService) Query(q string) []*model.CommonSearchResultModel {
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
}

@ -12,6 +12,7 @@ import (
"sync"
"time"
"github.com/TheHippo/podcastindex"
"github.com/akhilrex/podgrab/db"
"github.com/akhilrex/podgrab/model"
"github.com/antchfx/xmlquery"
@ -649,6 +650,23 @@ func GetSearchFromItunes(pod model.ItunesSingleResult) *model.CommonSearchResult
return p
}
func GetSearchFromPodcastIndex(pod *podcastindex.Podcast) *model.CommonSearchResultModel {
p := new(model.CommonSearchResultModel)
p.URL = pod.URL
p.Image = pod.Image
p.Title = pod.Title
p.Description = pod.Description
if pod.Categories != nil {
values := make([]string, 0, len(pod.Categories))
for _, val := range pod.Categories {
values = append(values, val)
}
p.Categories = values
}
return p
}
func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool) error {
setting := db.GetOrCreateSetting()

Loading…
Cancel
Save