podkasto

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.swab.dev/podkasto.git
Log | Files | Refs | README | LICENSE

commit 20f4be790de8b0574d20a6243bdd8866cfcfdad7
parent dff083eafd6a5b15633227a548ef36d528480887
Author: Jaron Swab <jaron@swab.dev>
Date:   Sun, 25 Apr 2021 15:40:22 -0400

Added podcast searcd by feed ID

Diffstat:
Mmain.go | 31+++++++++++++++++++++++++++----
Mpodkasto | 0
Mrequest/request.go | 2+-
Asearch/common.go | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asearch/podcasts.go | 26++++++++++++++++++++++++++
Asearch/search.go | 48++++++++++++++++++++++++++++++++++++++++++++++++
Dsearch/terms.go | 73-------------------------------------------------------------------------
7 files changed, 161 insertions(+), 78 deletions(-)

diff --git a/main.go b/main.go @@ -8,14 +8,37 @@ import ( ) func main() { - var term = flag.String("term", "", "A term to search for.") + var ( + searchType = flag.String("search", "", + "May be set to \"podcasts\" or \"episodes\".\nIf left unset, podkasto will perform a basic query to PodcastIndex.org") + term = flag.String("term", "", + "Used to search for podcasts containing a term.\nExample: podkasto --search podcasts --term \"Hacker Culture\"") + id = flag.String("id", "", + "Used to search for a podcast by the \"Podcast Index\" id.\nExample: podkasto --search podcasts --id 669240") + name = flag.String("name", "", + "Search for podcasts by author name. Do not include the \"search\" flag with this one.\nExpample: podkasto --name \"Jaron Swab\"") + ) flag.Parse() conf := new(config.Config) conf.Load() - if *term != "" { - q := &search.Query{ApiKey: conf.ApiKey, ApiSecret: conf.ApiSecret} - q.ByTerm(*term) + q := &search.API{ApiKey: conf.ApiKey, ApiSecret: conf.ApiSecret} + if *searchType == "podcasts" { + if *term != "" { + q.ByTerm(*term) + } + + if *id != "" { + q.ByFeedID(*id) + } + } else { + if *term != "" { + q.ByTerm(*term) + } else if *name != "" { + q.ByPerson(*name) + } else { + flag.PrintDefaults() + } } } diff --git a/podkasto b/podkasto Binary files differ. diff --git a/request/request.go b/request/request.go @@ -10,7 +10,7 @@ import ( ) func Send(searchQuery, apiKey, apiSecret string) ([]byte, error) { - url := fmt.Sprintf("https://api.podcastindex.org/api/1.0/search/%s", searchQuery) + url := fmt.Sprintf("https://api.podcastindex.org/api/1.0/%s", searchQuery) req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err diff --git a/search/common.go b/search/common.go @@ -0,0 +1,59 @@ +package search + +// API contains the API Key and Secret for sending requests to PodcastIndex.org +type API struct { + ApiKey string + ApiSecret string +} + +// Response contains the unmarshaled data from a successful query to PodcastIndex.org +type Search struct { + Status string `json:"status"` + Query string `json:"query"` + Feeds []Feed `json:"feeds"` + Description string `json:"description"` + Count int `json:"count"` +} + +type Podcasts struct { + Status string `json:"status"` + Query Query `json:"query"` + Feed Feed `json:"feed"` + Description string `json:"description"` + Count int `json:"count"` +} + +type Query struct { + ID string `json:"id"` +} + +// Feed contains the unmarshaled data about a returned feed from PodcastingIndex.org +type Feed struct { + ID int `json:"id"` + Title string `json:"title"` + URL string `json:"url"` + Originalurl string `json:"originalUrl"` + Link string `json:"link"` + Description string `json:"description"` + Author string `json:"author"` + Ownername string `json:"ownerName"` + Image string `json:"image"` + Artwork string `json:"artwork"` + Lastupdatetime int `json:"lastUpdateTime"` + Lastcrawltime int `json:"lastCrawlTime"` + Lastparsetime int `json:"lastParseTime"` + Lastgoodhttpstatustime int `json:"lastGoodHttpStatusTime"` + Lasthttpstatus int `json:"lastHttpStatus"` + Contenttype string `json:"contentType"` + Itunesid int `json:"itunesId"` + Generator string `json:"generator"` + Language string `json:"language"` + Type int `json:"type"` + Dead int `json:"dead"` + Chash string `json:"chash"` + EpisodeCount int `json:"episodeCount"` + Crawlerrors int `json:"crawlErrors"` + Parseerrors int `json:"parseErrors"` + Locked int `json:"locked"` + Imageurlhash int `json:"imageUrlHash"` +} diff --git a/search/podcasts.go b/search/podcasts.go @@ -0,0 +1,26 @@ +package search + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/jrswab/podkasto/request" +) + +func (q *API) ByFeedID(id string) { + searchQuery := fmt.Sprintf("podcasts/byfeedid?id=%s&pretty", id) + + body, err := request.Send(searchQuery, q.ApiKey, q.ApiSecret) + if err != nil { + log.Fatalf("query \"ByFeedID\" failed: %s", err) + } + + resp := new(Podcasts) + err = json.Unmarshal(body, &resp) + if err != nil { + log.Fatalf("query \"ByFeedID\" failed: %s", err) + } + + fmt.Printf("%+v\n", resp.Feed) +} diff --git a/search/search.go b/search/search.go @@ -0,0 +1,48 @@ +package search + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/jrswab/podkasto/request" +) + +func (q *API) ByTerm(term string) { + //searchQuery := fmt.Sprintf("%sbyterm?q=%s&pretty=%s", searchBase, query, isPretty) + searchQuery := fmt.Sprintf("search/byterm?q=%s", term) + + body, err := request.Send(searchQuery, q.ApiKey, q.ApiSecret) + if err != nil { + log.Fatal(err) + } + + response := new(Search) + err = json.Unmarshal(body, &response) + if err != nil { + log.Fatalf("query \"ByTerm\" failed: %s", err) + } + + for _, feed := range response.Feeds { + fmt.Printf("%+v\n\n", feed) + } +} + +func (q *API) ByPerson(name string) { + searchQuery := fmt.Sprintf("search/byperson?q=%s", name) + + body, err := request.Send(searchQuery, q.ApiKey, q.ApiSecret) + if err != nil { + log.Fatal(err) + } + + response := new(Search) + err = json.Unmarshal(body, &response) + if err != nil { + log.Fatalf("query \"ByPerson\" failed: %s", err) + } + + for _, feed := range response.Feeds { + fmt.Printf("%+v\n\n", feed) + } +} diff --git a/search/terms.go b/search/terms.go @@ -1,73 +0,0 @@ -package search - -import ( - "encoding/json" - "fmt" - "log" - - "github.com/jrswab/podkasto/request" -) - -type Podcasts struct { - Status string `json:"status"` - Feeds []Feeds `json:"feeds"` - Count int `json:"count"` - Query string `json:"query"` - Description string `json:"description"` -} - -type Categories struct { - Num102 string `json:"102"` -} - -type Feeds struct { - ID int `json:"id"` - Title string `json:"title"` - URL string `json:"url"` - Originalurl string `json:"originalUrl"` - Link string `json:"link"` - Description string `json:"description"` - Author string `json:"author"` - Ownername string `json:"ownerName"` - Image string `json:"image"` - Artwork string `json:"artwork"` - Lastupdatetime int `json:"lastUpdateTime"` - Lastcrawltime int `json:"lastCrawlTime"` - Lastparsetime int `json:"lastParseTime"` - Lastgoodhttpstatustime int `json:"lastGoodHttpStatusTime"` - Lasthttpstatus int `json:"lastHttpStatus"` - Contenttype string `json:"contentType"` - Itunesid int `json:"itunesId"` - Generator string `json:"generator"` - Language string `json:"language"` - Type int `json:"type"` - Dead int `json:"dead"` - Crawlerrors int `json:"crawlErrors"` - Parseerrors int `json:"parseErrors"` - Categories Categories `json:"categories"` - Locked int `json:"locked"` - Imageurlhash int `json:"imageUrlHash"` -} - -type Query struct { - ApiKey string - ApiSecret string -} - -func (q *Query) ByTerm(term string) { - //searchQuery := fmt.Sprintf("%sbyterm?q=%s&pretty=%s", searchBase, query, isPretty) - searchQuery := fmt.Sprintf("byterm?q=%s", term) - - body, err := request.Send(searchQuery, q.ApiKey, q.ApiSecret) - if err != nil { - log.Fatal(err) - } - - search := new(Podcasts) - err = json.Unmarshal(body, &search) - if err != nil { - log.Fatal(err) - } - - fmt.Println("%+v", search) -}