Last active
February 24, 2019 22:59
-
-
Save papodaca/667f30e2c0ce4e07ae63c0c4030e87cf to your computer and use it in GitHub Desktop.
Download podcasts and name with release order, assuming the feed is delivered in release order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
threads=4 | |
if [ -z "$1" ]; then | |
echo "Usage:" | |
echo " encode.sh <output_path>" | |
exit 1 | |
fi | |
dir=$1 | |
mkdir -p $dir | |
encode() { | |
outname=$(echo $1 | sed 's/.mp3//gI') | |
outpath="${dir}${outname}.mp3" | |
echo "encode ${1} to ${outpath}" | |
ffmpeg -v 0 -i "$1" -y -f mp2 -ar 44100 -ab 64000 -ac 1 -acodec mp3 "$outpath" | |
} | |
export -f encode | |
export dir | |
files=(*.mp3) | |
for file in "${files[@]}"; do | |
echo $file | |
done | xargs -n 1 -P $threads -I {} bash -c 'encode "$@"' _ {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
threads=4 | |
tmp=~/.cache/feed_download | |
feed="${tmp}/feed.xml" | |
if command -v python3 &>/dev/null; then | |
python=python3 | |
else | |
echo "Python 3 is required" | |
exit 1 | |
fi | |
if [ -z "$1" ]; then | |
echo "Usage:" | |
echo " feed_download.sh <feed_url>" | |
exit 1 | |
fi | |
download() { | |
IFS=';' read -ra ADDR <<< "$1" | |
index=${ADDR[0]} | |
url=${ADDR[1]} | |
filename=$(python3 -c "from urllib.parse import urlparse; print(urlparse('${url}').path.split('/')[-1])") | |
output="${index}-${filename}" | |
echo "Downloading ${output}" | |
curl -Ls -o "${output}" "${url}" | |
return 0; | |
} | |
export -f download | |
mkdir -p $tmp | |
curl -Ls $1 > $feed | |
array=($(python3 -c "import xml.etree.ElementTree; items = xml.etree.ElementTree.parse('${feed}').find('channel').iter(tag='item'); [print(item.find('enclosure').get('url')) for item in items]")) | |
rm -rf $tmp | |
length=$[${#array[@]}-1] | |
for i in `seq $length -1 0`;do | |
idx=$(printf "%04d" $[${length}-${i}]) | |
echo "${idx};${array[$i]}" | |
done | xargs -n 1 -P $threads -I {} bash -c 'download "$@"' _ {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment