audiomack.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. import datetime
  5. import time
  6. import urllib.request
  7. import json
  8. class AudiomackIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?audiomack\.com/song/(?P<id>[\w/-]+)'
  10. _TEST = {
  11. 'url': 'https://www.audiomack.com/song/crewneckkramer/story-i-tell',
  12. 'info_dict': {
  13. 'id': 'story-i-tell',
  14. 'ext': 'mp3',
  15. 'title': 'story-i-tell'
  16. }
  17. }
  18. def _real_extract(self, url):
  19. # TODO more code goes here, for example ...
  20. #webpage = self._download_webpage(url, video_id)
  21. #title = self._html_search_regex(r'<h1>(.*?)</h1>', webpage, 'title')
  22. assert("/song/" in url)
  23. songurl = url[url.index("/song/")+5:]
  24. title = songurl[songurl.rindex("/")+1:]
  25. video_id = title
  26. t = int(time.mktime(datetime.datetime.now().timetuple()))
  27. s = "http://www.audiomack.com/api/music/url/song"+songurl+"?_="+str(t)
  28. f = urllib.request.urlopen(s)
  29. j = f.read(1000).decode("utf-8")
  30. data = json.loads(j)
  31. return {
  32. 'id': video_id,
  33. 'title': title,
  34. 'url' : data["url"],
  35. 'ext' : 'mp3'
  36. # TODO more properties (see youtube_dl/extractor/common.py)
  37. }