Created
August 2, 2015 15:48
-
-
Save selahattinunlu/401646e228ac842dd055 to your computer and use it in GitHub Desktop.
This is a Python script to download all podcasts on fullstackradio.com
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
from lxml import html | |
import requests | |
import sys | |
class App: | |
def __init__(self): | |
self.url = 'http://fullstackradio.com' | |
page = requests.get(self.url) | |
page_string = html.fromstring(page.text) | |
episodes = page_string.find_class('episode') | |
for episode in episodes: | |
title = episode.cssselect('.episode-header-title')[0].text_content() | |
download_link = episode.cssselect('.episode-audio .text-right a')[0].get('href') | |
self.download(title, download_link) | |
print '' | |
def download(self, title, url): | |
title = title.strip() | |
file_name = title + '.mp3' | |
with open(file_name, 'wb') as f: | |
print file_name + " is downloading..." | |
r = requests.get(url, stream = True) | |
total_length = r.headers.get('content-length') | |
dl = 0 | |
if total_length is None: | |
f.write(r.content) | |
else: | |
for chunk in r.iter_content(1024): | |
total_length = int(total_length) | |
dl += len(chunk) | |
f.write(chunk) | |
done = int(50 * dl / total_length) | |
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) ) | |
sys.stdout.flush() | |
app = App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment