LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   CLI app to get podcast feed URLs (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/cli-app-to-get-podcast-feed-urls-4175656322/)

dugan 06-24-2019 09:46 PM

CLI app to get podcast feed URLs
 
I've been getting into podcasts recently, and I've noticed that, a) a lot of clients expect you to just give them the RSS feeds that you want to subscribe to, and b) those RSS feeds aren't always easy to find.

So I kludged up a small script to query for them.

Code:

#!/usr/bin/env bash

if [[ "$1" == "" ]]; then
  exit 1
fi

PODCAST=$(http "https://itunes.apple.com/search?media=podcast&term=$1" | jq -r '.results[].collectionName' | fzf --select-1 --exit-0)

if [[ "$PODCAST" == "" ]]; then
  exit
fi

echo "$PODCAST"
http "https://itunes.apple.com/search?media=podcast&term=$PODCAST" | jq -r '.results[0].feedUrl'

Name it "podfeed" and call it like this:

Code:

podfeed "You Must Remember"
That currently gives you a menu of two choices:
  • You Must Remember Manson
  • You Must Remember This

Narrow down the list by typing, or use the arrow keys to make a selection, and press ENTER.

Then you'll see:

Code:

You Must Remember Manson
http://feeds.megaphone.fm/PPY3689373157

Note that this uses a fairly modern pipeline, specifically:

I'll decline to link to the iTunes search API documentation, as all I did was look at what CPod does:

https://github.com/z-------------/CP...ch-podcasts.js

For more ideas on what you can do with FZF, see here:

How FZF and ripgrep improved my workflow

individual 06-25-2019 07:50 AM

That's pretty neat, Dugan. My only question is whether it would be better to store the result of the first search in a variable, that way you don't need to call the same URL again?
Something like this?
Code:

#!/usr/bin/env bash

data="$(<1.txt)"
feedNames="$(<<<"$data" jq '.results[].collectionName')"
<<<"$data" jq -r ".results[] | select(.collectionName == $(fzy <<< "$feedNames")) | .feedUrl"

EDIT: By the way, I use fzy, but it works just the same with fzf.

dugan 06-27-2022 06:32 PM

I wrote another implementation using skim. This one will just give you a prompt and an autocomplete. It's slightly less responsive because it's sending a request to itunes with each keystroke.

pdfd script to make it work:
Code:

#!/usr/bin/env bash

if [[ "$1" == "" ]]; then
  exit 1
fi

http "https://itunes.apple.com/search?media=podcast&term=$1" | jq -r '.results[].collectionName'

The new podfeed script you actually run:
Code:

#!/usr/bin/env bash

PODCAST=$(sk --ansi -i -c 'pdfd "{}" &')

if [[ "$PODCAST" == "" ]]; then
  exit
fi

URL=$(http "https://itunes.apple.com/search?media=podcast&term=$PODCAST" | jq -r '.results[0].feedUrl')

echo "$URL" "$PODCAST"

And do you want to know what else I did? I wrote my own podcast aggregator, Podfeeds.


All times are GMT -5. The time now is 01:06 AM.