...
 
Commits (3)
getpods.py is a very simple command line podcast client in Python,
that I made for my personal use.
getpods.py is a very simple command line podcast client in Python, that I made for my personal use.
# Requirements
As of June 25, 2018 it only supports Python 3. I'm too old to keep
messing with unicode issues, etc.
As of June 25, 2018 it only supports Python 3. I'm too old to keep messing with unicode issues, etc.
The `feedparser` module needs to be installed, for example as `apt
install python3-feedparser` in Debian or Ubuntu.
The `feedparser` module needs to be installed, for example as `apt install python3-feedparser` in Debian or Ubuntu.
# Usage and configuration
You need a directory for your podcasts, e.g. `~/Podcasts` or directly
on your mounted media player (like I have). You should make a
configuration called `~/.getpods` that points to this directory. There
should be a file getpods.sample.conf distributed together with this
script that you can copy to `~/.getpods` and modify.
You need to create a configuration file called `~/.getpods` with this minimum content (change the podcast directory as appropriate):
In the podcast_dir directory, create a file called `urls` which
contains one line for each podcast feed with the following format:
[general]
podcasts_dir=~/Podcasts
There is a sample configuration file showing all the options called `getpods.sample.conf` distributed together with this script that you can copy and modify.
In the `podcast_dir` directory, create a file called `urls` which contains one line for each podcast feed with the following format:
# comments preceeded by hash
url directory_name [?]
......@@ -29,9 +26,6 @@ For example:
http://faif.us/feeds/cast-ogg/ faif
http://hackerpublicradio.org/hpr_ogg_rss.php hpr ?
The question mark is for feeds where the program should query about
each new episode. Other feeds have new episodes automatically
downloaded.
The question mark is for feeds where the program should query about each new episode. Other feeds have new episodes automatically downloaded.
Episodes that have been downloaded or otherwise marked as "seen" are
registered in a file called "cache" in the podcast_dir.
Episodes that have been downloaded or otherwise marked as "seen" are registered in a file called "cache" in the podcast_dir.
......@@ -19,12 +19,14 @@
import collections
import configparser
import feedparser
import os
import sys
import re
import sys
import tempfile
import urllib.request
import feedparser
#------------------------------------------------------------------------------
config_filename = "~/.getpods"
......@@ -106,8 +108,8 @@ class Item(object):
def download_localname(self):
dl_url = self.download_url()
parts = dl_url.rpartition('/')
return parts[2]
parts = dl_url.rpartition('.')
return re.sub('[^a-zA-Z0-9]','_', self.title()) + '.' + parts[2]
def print_summary(self):
#clear_screen()
......@@ -240,15 +242,15 @@ def read_urls(urls_fname):
#------------------------------------------------------------------------------
old_output = ''
def progress_download(download_t, download_d, upload_t, upload_d):
def download_progress(current, size):
global old_output
if download_t < 1000 or not os.isatty(1):
if size < 1024 and not os.isatty(1):
return
output = "{:.2f}MB of {:.2f}MB ({:.2%})".format(download_d/1024/1024,
download_t/1024/1024,
download_d/download_t)
output = "{:.2f}MB of {:.2f}MB ({:.2%})".format(current/1024/1024,
size/1024/1024,
current/size)
if output != old_output:
sys.stdout.write(output)
sys.stdout.flush()
......@@ -258,7 +260,22 @@ def progress_download(download_t, download_d, upload_t, upload_d):
#------------------------------------------------------------------------------
def download_url(url, localname):
urllib.request.urlretrieve(url, localname)
read_bytes = 0
with urllib.request.urlopen(url) as r, \
tempfile.NamedTemporaryFile(delete=False) as fp:
total_bytes = r.length
while not r.closed and r.length > 0:
data = r.read(16384)
fp.write(data)
read_bytes += len(data)
download_progress(read_bytes, total_bytes)
fp.close()
tmpname = fp.name
os.rename(tmpname, localname)
return localname
#------------------------------------------------------------------------------
......