Skip to content

Instantly share code, notes, and snippets.

@juanriaza
Created May 17, 2015 08:39
Show Gist options
  • Save juanriaza/f722bd307fc06b95de89 to your computer and use it in GitHub Desktop.
Save juanriaza/f722bd307fc06b95de89 to your computer and use it in GitHub Desktop.
hypem
# -*- coding: utf-8 -*-
import requests
from mutagen import mp3, id3
req = requests.get(
'https://api.hypem.com/v2/users/juanriaza/favorites',
params={'count': 500, 'key': 'e51d64cf4ff893dfca4e2b5caa60bd21'})
if req.ok:
for song in req.json():
name = u'{} - {}'.format(song['artist'], song['title'])
file_name = u'{}.mp3'.format(name)
f = open(file_name, 'wb+')
f.write(requests.get(song['stream_pub']).content)
f.close()
audio = mp3.MP3(file_name)
try:
audio.add_tags()
except id3.error:
pass
audio.tags.add(
id3.APIC(
encoding=3,
mime='image/png',
type=3,
desc=u'Cover',
data=requests.get(song['thumb_url_large']).content
)
)
audio['TIT2'] = id3.TIT2(encoding=3, text=song['title'])
audio['TPE1'] = id3.TPE1(encoding=3, text=song['artist'])
audio['WOAR'] = id3.WOAR(url='http://hypem.com/track/{}'.format(song['itemid']))
audio.save()
print(audio.pprint())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment