]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tunein.py
8322cc14da821f4615a4a8038904039b01c18827
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..utils
import ExtractorError
8 from ..compat
import compat_urlparse
11 class TuneInBaseIE(InfoExtractor
):
12 _API_BASE_URL
= 'http://tunein.com/tuner/tune/'
14 def _real_extract(self
, url
):
15 content_id
= self
._match
_id
(url
)
17 content_info
= self
._download
_json
(
18 self
._API
_BASE
_URL
+ self
._API
_URL
_QUERY
% content_id
,
19 content_id
, note
='Downloading JSON metadata')
21 title
= content_info
['Title']
22 thumbnail
= content_info
.get('Logo')
23 location
= content_info
.get('Location')
24 streams_url
= content_info
.get('StreamUrl')
26 raise ExtractorError('No downloadable streams found', expected
=True)
27 if not streams_url
.startswith('http://'):
28 streams_url
= compat_urlparse
.urljoin(url
, streams_url
)
30 stream_data
= self
._download
_webpage
(
31 streams_url
, content_id
, note
='Downloading stream data')
32 streams
= json
.loads(self
._search
_regex
(
33 r
'\((.*)\);', stream_data
, 'stream info'))['Streams']
37 for stream
in streams
:
38 if stream
.get('Type') == 'Live':
40 reliability
= stream
.get('Reliability')
42 'Reliability: %d%%' % reliability
43 if reliability
is not None else None)
46 0 if reliability
is None or reliability
> 90
48 'abr': stream
.get('Bandwidth'),
49 'ext': stream
.get('MediaType').lower(),
50 'acodec': stream
.get('MediaType'),
52 'url': stream
.get('Url'),
53 'source_preference': reliability
,
54 'format_note': format_note
,
56 self
._sort
_formats
(formats
)
62 'thumbnail': thumbnail
,
68 class TuneInClipIE(TuneInBaseIE
):
69 IE_NAME
= 'tunein:clip'
70 _VALID_URL
= r
'https?://(?:www\.)?tunein\.com/station/.*?audioClipId\=(?P<id>\d+)'
71 _API_URL_QUERY
= '?tuneType=AudioClip&audioclipId=%s'
75 'url': 'http://tunein.com/station/?stationId=246119&audioClipId=816',
76 'md5': '99f00d772db70efc804385c6b47f4e77',
86 class TuneInStationIE(TuneInBaseIE
):
87 IE_NAME
= 'tunein:station'
88 _VALID_URL
= r
'https?://(?:www\.)?tunein\.com/(?:radio/.*?-s|station/.*?StationId\=)(?P<id>\d+)'
89 _API_URL_QUERY
= '?tuneType=Station&stationId=%s'
92 def suitable(cls
, url
):
93 return False if TuneInClipIE
.suitable(url
) else super(TuneInStationIE
, cls
).suitable(url
)
97 'url': 'http://tunein.com/radio/Jazz24-885-s34682/',
100 'title': 'Jazz 24 on 88.5 Jazz24 - KPLU-HD2',
102 'location': 'Tacoma, WA',
105 'skip_download': True, # live stream
111 class TuneInProgramIE(TuneInBaseIE
):
112 IE_NAME
= 'tunein:program'
113 _VALID_URL
= r
'https?://(?:www\.)?tunein\.com/(?:radio/.*?-p|program/.*?ProgramId\=)(?P<id>\d+)'
114 _API_URL_QUERY
= '?tuneType=Program&programId=%s'
118 'url': 'http://tunein.com/radio/Jazz-24-p2506/',
121 'title': 'Jazz 24 on 91.3 WUKY-HD3',
123 'location': 'Lexington, KY',
126 'skip_download': True, # live stream
132 class TuneInTopicIE(TuneInBaseIE
):
133 IE_NAME
= 'tunein:topic'
134 _VALID_URL
= r
'https?://(?:www\.)?tunein\.com/topic/.*?TopicId\=(?P<id>\d+)'
135 _API_URL_QUERY
= '?tuneType=Topic&topicId=%s'
139 'url': 'http://tunein.com/topic/?TopicId=101830576',
140 'md5': 'c31a39e6f988d188252eae7af0ef09c9',
143 'title': 'Votez pour moi du 29 octobre 2015 (29/10/15)',
145 'location': 'Belgium',
151 class TuneInShortenerIE(InfoExtractor
):
152 IE_NAME
= 'tunein:shortener'
153 IE_DESC
= False # Do not list
154 _VALID_URL
= r
'https?://tun\.in/(?P<id>[A-Za-z0-9]+)'
158 'url': 'http://tun.in/ser7s',
161 'title': 'Jazz 24 on 88.5 Jazz24 - KPLU-HD2',
163 'location': 'Tacoma, WA',
166 'skip_download': True, # live stream
170 def _real_extract(self
, url
):
171 redirect_id
= self
._match
_id
(url
)
172 # The server doesn't support HEAD requests
173 urlh
= self
._request
_webpage
(
174 url
, redirect_id
, note
='Downloading redirect page')
176 self
.to_screen('Following redirect: %s' % url
)
177 return self
.url_result(url
)