[stitcher] Add extractor
[youtube-dl] / youtube_dl / extractor / stitcher.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 class StitcherIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?stitcher\.com/podcast/[\/a-z\-]+(?P<id>\d+)'
9     _TEST = {
10         'url': 'http://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true',
11         'md5': '391dd4e021e6edeb7b8e68fbf2e9e940',
12         'info_dict': {
13             'id': '40789481',
14             'ext': 'mp3',
15             'title': 'Machine Learning Mastery and Cancer Clusters from Talking Machines',
16         }
17     }
18
19     def _real_extract(self, url):
20         audio_id = self._match_id(url)
21
22         webpage = self._download_webpage(url, audio_id)
23
24         title = self._og_search_title(webpage)
25         url = self._search_regex(r'episodeURL: "(.+?)"', webpage, 'url')
26         episode_image = self._search_regex(r'episodeImage: "(.+?)"', webpage, 'episode_image', fatal=False)
27         duration = int_or_none(self._search_regex(r'duration: (\d+?),', webpage, 'duration', fatal=False))
28
29         return {
30             'id': audio_id,
31             'url': url,
32             'title': title,
33             'duration': duration,
34             'thumbnail': episode_image,
35             'ext': 'mp3',
36             'vcodec': 'none',
37         }