From 328f0dbf467f4aaebeef650c4e071e003c292a4c Mon Sep 17 00:00:00 2001 From: sdsafdasgerfyhwrstehbserthb Date: Wed, 22 Mar 2017 14:40:06 +0500 Subject: [PATCH 1/3] Revert "0.11.0 - encode albumart into mp3s" This reverts commit f56330441b423f1a719a60d28cb8598932007f3b. --- requirements.txt | 6 ++-- setup.py | 2 +- soundscrape/soundscrape.py | 59 ++++++++++---------------------------- 3 files changed, 19 insertions(+), 48 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5b81573..f208b1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -args>=0.1.0 -clint>=0.3.2 +args==0.1.0 +clint==0.3.2 fudge==1.0.3 mutagen==1.22 requests>=2.1.0 simplejson==3.3.1 -soundcloud>=0.4.1 +soundcloud==0.4.1 wsgiref==0.1.2 diff --git a/setup.py b/setup.py index 3afd155..1776c64 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='soundscrape', - version='0.11.0', + version='0.10.2', packages=['soundscrape'], install_requires=required, include_package_data=True, diff --git a/soundscrape/soundscrape.py b/soundscrape/soundscrape.py index 43188a0..312ca0b 100755 --- a/soundscrape/soundscrape.py +++ b/soundscrape/soundscrape.py @@ -5,9 +5,8 @@ import sys import argparse -from mutagen.mp3 import MP3, EasyMP3 -from mutagen.id3 import APIC -from mutagen.id3 import ID3 as OldID3 +from mutagen.easyid3 import ID3, EasyID3 +from mutagen.mp3 import EasyMP3 from clint.textui import colored, puts, progress @@ -16,7 +15,6 @@ CLIENT_SECRET = '3a7815c3f9a82c3448ee4e7d3aa484a4' MAGIC_CLIENT_ID = 'b45b1aa10f1ac2941910a7f0d10f8e28' - def main(): parser = argparse.ArgumentParser(description='SoundScrape. Scrape an artist from SoundCloud.\n') parser.add_argument('artist_url', metavar='U', type=str, @@ -69,20 +67,18 @@ def main(): tracks = client.get('/users/' + str(artist_id) + '/tracks') if one_track: - num_tracks = 1 + num_tracks = 1; else: num_tracks = vargs['num_tracks'] download_tracks(client, tracks, num_tracks) - def download_tracks(client, tracks, num_tracks=sys.maxint): for i, track in enumerate(tracks): - # "Track" and "Resource" objects are actually different, - # even though they're the same. + # "Track" and "Resource" objects are actually different, + # even though they're the same. if isinstance(track, soundcloud.resource.Resource): - try: t_track = {} t_track['downloadable'] = track.downloadable @@ -91,7 +87,6 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): t_track['user'] = {'username': track.user['username']} t_track['release_year'] = track.release t_track['genre'] = track.genre - t_track['artwork_url'] = track.artwork_url if track.downloadable: t_track['stream_url'] = track.download_url else: @@ -109,7 +104,7 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): continue try: if not track.get('stream_url', False): - puts(track['title'].encode('utf-8') + colored.red(u' is not downloadable') + '.') + puts(track['title'].encode('utf-8') + colored.red(u' is not downloadable') + '.') continue else: puts(colored.green(u"Downloading") + ": " + track['title'].encode('utf-8')) @@ -124,30 +119,27 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): track_filename = track['user']['username'].replace('/', '-') + ' - ' + track['title'].replace('/', '-') + '.mp3' download_file(location, track_filename) - tag_file(track_filename, - artist=track['user']['username'], - title=track['title'], - year=track['release_year'], - genre=track['genre'], - artwork_url=track['artwork_url']) + tag_file(track_filename, + artist=track['user']['username'], + title=track['title'], + year=track['release_year'], + genre=track['genre']) except Exception, e: - puts(colored.red(u"Problem downloading ") + track['title'].encode('utf-8')) + puts(colored.red(u"Problem downloading ") + track['title'].encode('utf-8') ) print e - def download_file(url, path): r = requests.get(url, stream=True) with open(path, 'wb') as f: total_length = int(r.headers.get('content-length')) - for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1): - if chunk: # filter out keep-alive new chunks + for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): + if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() return path - -def tag_file(filename, artist, title, year, genre, artwork_url): +def tag_file(filename, artist, title, year, genre): try: audio = EasyMP3(filename) audio["artist"] = artist @@ -156,27 +148,6 @@ def tag_file(filename, artist, title, year, genre, artwork_url): audio["date"] = str(year) audio["genre"] = genre audio.save() - - if artwork_url: - mime = 'image/jpeg' - if 'jpg' in artwork_url: - mime = 'image/jpeg' - if 'png' in artwork_url: - mime - 'image/png' - - image_data = requests.get(artwork_url).content - - audio = MP3(filename, ID3=OldID3) - audio.tags.add( - APIC( - encoding=3, # 3 is for utf-8 - mime=mime, - type=3, # 3 is for the cover image - desc=u'Cover', - data=image_data - ) - ) - audio.save() except Exception, e: print e From 3ba6558564748230b1c17bb3a2ea96257d4f7be4 Mon Sep 17 00:00:00 2001 From: sdsafdasgerfyhwrstehbserthb Date: Wed, 22 Mar 2017 14:45:12 +0500 Subject: [PATCH 2/3] Revert "Revert "0.11.0 - encode albumart into mp3s"" This reverts commit 328f0dbf467f4aaebeef650c4e071e003c292a4c. --- requirements.txt | 6 ++-- setup.py | 2 +- soundscrape/soundscrape.py | 59 ++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/requirements.txt b/requirements.txt index f208b1f..5b81573 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -args==0.1.0 -clint==0.3.2 +args>=0.1.0 +clint>=0.3.2 fudge==1.0.3 mutagen==1.22 requests>=2.1.0 simplejson==3.3.1 -soundcloud==0.4.1 +soundcloud>=0.4.1 wsgiref==0.1.2 diff --git a/setup.py b/setup.py index 1776c64..3afd155 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='soundscrape', - version='0.10.2', + version='0.11.0', packages=['soundscrape'], install_requires=required, include_package_data=True, diff --git a/soundscrape/soundscrape.py b/soundscrape/soundscrape.py index 312ca0b..43188a0 100755 --- a/soundscrape/soundscrape.py +++ b/soundscrape/soundscrape.py @@ -5,8 +5,9 @@ import sys import argparse -from mutagen.easyid3 import ID3, EasyID3 -from mutagen.mp3 import EasyMP3 +from mutagen.mp3 import MP3, EasyMP3 +from mutagen.id3 import APIC +from mutagen.id3 import ID3 as OldID3 from clint.textui import colored, puts, progress @@ -15,6 +16,7 @@ CLIENT_SECRET = '3a7815c3f9a82c3448ee4e7d3aa484a4' MAGIC_CLIENT_ID = 'b45b1aa10f1ac2941910a7f0d10f8e28' + def main(): parser = argparse.ArgumentParser(description='SoundScrape. Scrape an artist from SoundCloud.\n') parser.add_argument('artist_url', metavar='U', type=str, @@ -67,18 +69,20 @@ def main(): tracks = client.get('/users/' + str(artist_id) + '/tracks') if one_track: - num_tracks = 1; + num_tracks = 1 else: num_tracks = vargs['num_tracks'] download_tracks(client, tracks, num_tracks) + def download_tracks(client, tracks, num_tracks=sys.maxint): for i, track in enumerate(tracks): - # "Track" and "Resource" objects are actually different, - # even though they're the same. + # "Track" and "Resource" objects are actually different, + # even though they're the same. if isinstance(track, soundcloud.resource.Resource): + try: t_track = {} t_track['downloadable'] = track.downloadable @@ -87,6 +91,7 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): t_track['user'] = {'username': track.user['username']} t_track['release_year'] = track.release t_track['genre'] = track.genre + t_track['artwork_url'] = track.artwork_url if track.downloadable: t_track['stream_url'] = track.download_url else: @@ -104,7 +109,7 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): continue try: if not track.get('stream_url', False): - puts(track['title'].encode('utf-8') + colored.red(u' is not downloadable') + '.') + puts(track['title'].encode('utf-8') + colored.red(u' is not downloadable') + '.') continue else: puts(colored.green(u"Downloading") + ": " + track['title'].encode('utf-8')) @@ -119,27 +124,30 @@ def download_tracks(client, tracks, num_tracks=sys.maxint): track_filename = track['user']['username'].replace('/', '-') + ' - ' + track['title'].replace('/', '-') + '.mp3' download_file(location, track_filename) - tag_file(track_filename, - artist=track['user']['username'], - title=track['title'], - year=track['release_year'], - genre=track['genre']) + tag_file(track_filename, + artist=track['user']['username'], + title=track['title'], + year=track['release_year'], + genre=track['genre'], + artwork_url=track['artwork_url']) except Exception, e: - puts(colored.red(u"Problem downloading ") + track['title'].encode('utf-8') ) + puts(colored.red(u"Problem downloading ") + track['title'].encode('utf-8')) print e + def download_file(url, path): r = requests.get(url, stream=True) with open(path, 'wb') as f: total_length = int(r.headers.get('content-length')) - for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): - if chunk: # filter out keep-alive new chunks + for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1): + if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() return path -def tag_file(filename, artist, title, year, genre): + +def tag_file(filename, artist, title, year, genre, artwork_url): try: audio = EasyMP3(filename) audio["artist"] = artist @@ -148,6 +156,27 @@ def tag_file(filename, artist, title, year, genre): audio["date"] = str(year) audio["genre"] = genre audio.save() + + if artwork_url: + mime = 'image/jpeg' + if 'jpg' in artwork_url: + mime = 'image/jpeg' + if 'png' in artwork_url: + mime - 'image/png' + + image_data = requests.get(artwork_url).content + + audio = MP3(filename, ID3=OldID3) + audio.tags.add( + APIC( + encoding=3, # 3 is for utf-8 + mime=mime, + type=3, # 3 is for the cover image + desc=u'Cover', + data=image_data + ) + ) + audio.save() except Exception, e: print e From f2ef526d3de6d8297f86f631e69854c59a4502f6 Mon Sep 17 00:00:00 2001 From: sdsafdasgerfyhwrstehbserthb Date: Wed, 22 Mar 2017 14:45:28 +0500 Subject: [PATCH 3/3] Revert "Revert "0.11.0 - encode albumart into mp3s"" This reverts commit 328f0dbf467f4aaebeef650c4e071e003c292a4c. --- soundscrape/.gitattributes | 17 +++++++++++++++++ .../__pycache__/__init__.cpython-36.pyc | Bin 0 -> 196 bytes 2 files changed, 17 insertions(+) create mode 100644 soundscrape/.gitattributes create mode 100644 soundscrape/__pycache__/__init__.cpython-36.pyc diff --git a/soundscrape/.gitattributes b/soundscrape/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/soundscrape/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/soundscrape/__pycache__/__init__.cpython-36.pyc b/soundscrape/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2201394794a19db948cec30753ffea0fc0bfcc54 GIT binary patch literal 196 zcmXr!<>fN9xfCJ6z`*brh~a<{$Z`PUVh$jY!Vtxf!Whh;$yCK=pl58LXW*yFc#Ate zzAUwKgcbv3V=hd%u;s#@3p+0Cy|CkA