Last active
January 25, 2016 21:42
-
-
Save joanfont/9cd8f529c3a2c35037f2 to your computer and use it in GitHub Desktop.
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
import multiprocessing | |
import os | |
import requests | |
BASE_URL = 'http://www.bigozine2.com/{folder}/GHlondon/GHlondon{song_id}.mp3' | |
SONGS = { | |
110: 'I Want To Tell You', | |
111: 'Old Brown Shoe', | |
112: 'Taxman', | |
113: 'Introduction', | |
114: 'Give Me Love', | |
115: 'Something', | |
201: 'What Is Life', | |
202: 'Piggies', | |
203: 'Got My Mind Set On You', | |
204: 'Cloud 9', | |
205: 'Here Comes The Sun', | |
206: 'My Sweet Lord', | |
207: 'All Those Years Ago', | |
208: 'Cheer Down', | |
209: 'Isn’t It A Pity', | |
210: 'Devil’s Radio', | |
211: 'While My Guitar Gently Weeps', | |
212: 'Roll Over Beethoven', | |
213: 'Drum Solo', | |
214: 'Roll Over Beethoven', | |
} | |
FOLDERS = { | |
1: 'TRKS', | |
2: 'TRKSB1' | |
} | |
def download_song(song_item): | |
song_id, song_name = song_item | |
print('Downloading {song_name}...'.format(song_name=song_name)) | |
folder_idx = song_id // 100 | |
folder = FOLDERS.get(folder_idx) | |
song_url = BASE_URL.format(folder=folder, song_id=song_id) | |
song_iter = requests.get(song_url, stream=True) | |
song_file_name = '{song_name}.mp3'.format(song_name=song_name) | |
song_path = os.path.join(song_file_name) | |
with open(song_path, 'wb') as f: | |
for block in song_iter: | |
f.write(block) | |
def main(): | |
pool_size = 2 * multiprocessing.cpu_count() | |
pool = multiprocessing.Pool(pool_size) | |
items = SONGS.items() | |
pool.map(download_song, items) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment