Merge remote-tracking branch 'pachacamac/soundgasm'
[youtube-dl] / youtube_dl / extractor / soundgasm.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8 class SoundgasmIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?soundgasm\.net/u/(?P<user>[0-9a-zA-Z_\-]+)/(?P<title>[0-9a-zA-Z_\-]+)'
10     _TEST = {
11         'url': 'http://soundgasm.net/u/ytdl/Piano-sample',
12         'md5': '010082a2c802c5275bb00030743e75ad',
13         'info_dict': {
14             'id': '88abd86ea000cafe98f96321b23cc1206cbcbcc9',
15             'ext': 'm4a',
16             'title': 'ytdl_Piano-sample',
17             'description': 'Royalty Free Sample Music'
18         }
19     }
20
21     def _real_extract(self, url):
22         mobj = re.match(self._VALID_URL, url)
23         audio_title = mobj.group('user') + '_' + mobj.group('title')
24         webpage = self._download_webpage(url, '')
25         audio_url = self._html_search_regex(r'(?s)m4a\:\s"([^"]+)"', webpage, 'audio URL')
26         audio_id = re.split('\/|\.', audio_url)[-2]
27         description = self._html_search_regex(r'(?s)<li>Description:\s(.*?)<\/li>', webpage, 'description', fatal=False, flags=re.DOTALL)
28
29         return {
30             'id': audio_id,
31             'url': audio_url,
32             'title': audio_title,
33             'description': description
34         }