Skip to content

Instantly share code, notes, and snippets.

@tyndyll
Created September 18, 2014 10:55
Show Gist options
  • Save tyndyll/de791bdf9f7f2528b635 to your computer and use it in GitHub Desktop.
Save tyndyll/de791bdf9f7f2528b635 to your computer and use it in GitHub Desktop.
Get Source URL from Downcast Link
#!/usr/bin/env python
# Requirements: BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/
# Example:
# overcast_downloader (~) python download.py https://overcast.fm/podcasts/episode/101217043409120
# http://traffic.libsyn.com/oneyoufeed/Mini_Episode_7.mp3#t=0
#
# overcast_downloader (~) python download.py https://overcast.fm/podcasts/episode/101217043409120 | xargs wget
# --2014-09-18 11:53:45-- http://traffic.libsyn.com/oneyoufeed/Mini_Episode_7.mp3
# Resolving traffic.libsyn.com... 204.16.245.39
# Connecting to traffic.libsyn.com|204.16.245.39|:80... connected.
# HTTP request sent, awaiting response... 302 Found
# Location: http://ec.libsyn.com/p/9/7/0/970f4825ef7246c2/Mini_Episode_7.mp3?d13a76d516d9dec20c3d276ce028ed5089ab1ce3dae902ea1d06c98637d2ce54bdfb&c_id=7600167 [following]
# --2014-09-18 11:53:45-- http://ec.libsyn.com/p/9/7/0/970f4825ef7246c2/Mini_Episode_7.mp3?d13a76d516d9dec20c3d276ce028ed5089ab1ce3dae902ea1d06c98637d2ce54bdfb&c_id=7600167
# Resolving ec.libsyn.com... 68.232.34.133
# Connecting to ec.libsyn.com|68.232.34.133|:80... connected.
# HTTP request sent, awaiting response... 200 OK
# Length: 13182955 (13M) [audio/mpeg]
# Saving to: 'Mini_Episode_7.mp3'
#
# 100%[================================================================================================>] 13,182,955 3.74MB/s in 3.4s
#
# 2014-09-18 11:53:48 (3.71 MB/s) - 'Mini_Episode_7.mp3.2' saved [13182955/13182955]
import optparse
import urllib2
from bs4 import BeautifulSoup, SoupStrainer
def get_audio_link(url):
response = urllib2.urlopen(url)
links = []
for audio in BeautifulSoup(response.read(), parse_only=SoupStrainer('audio')):
for source in audio.findChildren("source"):
if source.has_attr('src'):
links.append(source['src'])
return links
if __name__ == "__main__":
o = optparse.OptionParser()
(opts, args) = o.parse_args()
for arg in args:
for link in get_audio_link(arg):
print link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment