]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tunein.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..utils
import ExtractorError
11 class TuneInIE(InfoExtractor
):
12 _VALID_URL
= r
'''(?x)https?://(?:www\.)?
17 station/.*?StationId\=
19 |tun\.in/(?P<redirect_id>[A-Za-z0-9]+)
22 _API_URL_TEMPLATE
= 'http://tunein.com/tuner/tune/?stationId={0:}&tuneType=Station'
26 'title': 'Jazz 24 on 88.5 Jazz24 - KPLU-HD2',
28 'thumbnail': 're:^https?://.*\.png$',
29 'location': 'Tacoma, WA',
33 'url': 'http://tunein.com/radio/Jazz24-885-s34682/',
34 'info_dict': _INFO_DICT
,
36 'skip_download': True, # live stream
40 'url': 'http://tun.in/ser7s',
41 'info_dict': _INFO_DICT
,
43 'skip_download': True, # live stream
48 def _real_extract(self
, url
):
49 mobj
= re
.match(self
._VALID
_URL
, url
)
50 redirect_id
= mobj
.group('redirect_id')
52 # The server doesn't support HEAD requests
53 urlh
= self
._request
_webpage
(
54 url
, redirect_id
, note
='Downloading redirect page')
56 self
.to_screen('Following redirect: %s' % url
)
57 mobj
= re
.match(self
._VALID
_URL
, url
)
58 station_id
= mobj
.group('id')
60 station_info
= self
._download
_json
(
61 self
._API
_URL
_TEMPLATE
.format(station_id
),
62 station_id
, note
='Downloading station JSON')
64 title
= station_info
['Title']
65 thumbnail
= station_info
.get('Logo')
66 location
= station_info
.get('Location')
67 streams_url
= station_info
.get('StreamUrl')
69 raise ExtractorError('No downloadable streams found',
71 stream_data
= self
._download
_webpage
(
72 streams_url
, station_id
, note
='Downloading stream data')
73 streams
= json
.loads(self
._search
_regex
(
74 r
'\((.*)\);', stream_data
, 'stream info'))['Streams']
78 for stream
in streams
:
79 if stream
.get('Type') == 'Live':
82 'abr': stream
.get('Bandwidth'),
83 'ext': stream
.get('MediaType'),
84 'acodec': stream
.get('MediaType'),
86 'url': stream
.get('Url'),
87 # Sometimes streams with the highest quality do not exist
88 'preference': stream
.get('Reliability'),
90 self
._sort
_formats
(formats
)
96 'thumbnail': thumbnail
,