Skip to content

2021

Podcasts

I use the Pocket Casts app to download a few podcasts I listen to, however I also wanted to download and keep all the episodes from some of these podcasts as an archive if you will on my machine. Space is limited on my phone where I do most of my podcast listening but I've got ample space on my primary machine.

Thus I wrote a small python podcast downloader that takes the RSS URL, parses the feed and its entries, identify the actual download link and downloads to a directory of my choosing if the episode isn't already downloaded.

A few packages that I found super useful when writing this are:

  • rich
  • feedparser
  • requests
  • pathlib
  • argparse

argparse and pathlib are part of the standard library but Rich, Feedparser and Requests you'll have to install.

Install dependencies

poetry add feedparser
poetry add rich
poetry add requests
poetry install

Example run

poetry run python .\download_podcast_episodes.py "C:\Podcasts\"

Example output if you enable warnings just to verify you've already got files downloaded.

Output showing files are already downloaded

{{< gist axi0m be404e2aae6cd78b4db7fe1ed7b2d3c5 >}}

Rich

If you find yourself constantly creating command-line interfaces and have not heard of rich, take a few hours next week and play with it!

Historically I've used termcolor and colorama to handle the pretty terminal colors in Python programs I write but now that I've discovered rich I'm not sure I'll ever go back. The project is well-maintained, feature rich and Will the author seems to have put a lot of effort into it.

Install

I prefer to use pipenv but you can use normal pip or poetry too of course.

pip install rich
pipenv install rich

Usage

This is mentioned in detail on the README for Rich but this was the most immediately useful example I took away for my CLI programs.

from rich.console import Console

console = Console()

console.print(f'[+] Building the mechtronics matrix splicer...', style="bold green")

In addition there is a wonderful track() function you can use to wrap around an iterator and have rich progress bars in your console. I have used this in some non-public programs but have yet to add it to anything that's on my GitHub repos or Gists.

Replacing Tabulate

I blogged about using the package tabulate previously when I developed a small API client to interact with AWS EC2 resources using boto3 but after finding the rich package I think I'm goint to explore using its table rendering features instead.

References

Tabulate

Tabulate is a handy Python package on PyPI you can install to make fancy terminal tables.

Install

With pipenv

pipenv install tabulate

With pip and virtualenv

virtualenv tabulate
pip install tabulate --user

Example

Take a list of lists, and use tabulate to create pretty terminal tables. I created a simple file called tabulate_example.py in a dedicated venv.

from tabulate import tabulate

example_list = [["Beverly Hills","California", "United States"],["Minneapolis", "Minnesota", "United States"],["Chicago","Illinois","United States"]]

print(tabulate(example_list, headers=["City","State","Country"], tablefmt="pretty"))

Windows

pipenv run python .\tabulate_example.py

Output

tabulate output

Use Case

I recently found myself having to interact with AWS APIs and was manipulating the data structures in response and wanted to display a fairly large amount of items in my terminal.