]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hearthisat.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_urlparse
 
  18 class HearThisAtIE(InfoExtractor
): 
  19     _VALID_URL 
= r
'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$' 
  20     _PLAYLIST_URL 
= 'https://hearthis.at/playlist.php' 
  22         'url': 'https://hearthis.at/moofi/dr-kreep', 
  23         'md5': 'ab6ec33c8fed6556029337c7885eb4e0', 
  27             'title': 'Moofi - Dr. Kreep', 
  28             'thumbnail': 're:^https?://.*\.jpg$', 
  29             'timestamp': 1421564134, 
  30             'description': 'Listen to Dr. Kreep by Moofi on hearthis.at - Modular, Eurorack, Mutable Intruments Braids, Valhalla-DSP', 
  31             'upload_date': '20150118', 
  36             'categories': ['Experimental'], 
  39         # 'download' link redirects to the original webpage 
  40         'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/', 
  41         'md5': '5980ceb7c461605d30f1f039df160c6e', 
  45             'title': 'TwitchSF - DJ Jim Hopkins -  Totally Bitchin\' 80\'s Dance Mix!', 
  46             'description': 'Listen to DJ Jim Hopkins -  Totally Bitchin\' 80\'s Dance Mix! by TwitchSF on hearthis.at - Dance', 
  47             'upload_date': '20160328', 
  48             'timestamp': 1459186146, 
  49             'thumbnail': 're:^https?://.*\.jpg$', 
  54             'categories': ['Dance'], 
  58     def _real_extract(self
, url
): 
  59         m 
= re
.match(self
._VALID
_URL
, url
) 
  60         display_id 
= '{artist:s} - {title:s}'.format(**m
.groupdict()) 
  62         webpage 
= self
._download
_webpage
(url
, display_id
) 
  63         track_id 
= self
._search
_regex
( 
  64             r
'intTrackId\s*=\s*(\d+)', webpage
, 'track ID') 
  66         payload 
= urlencode_postdata({'tracks[]': track_id
}) 
  67         req 
= sanitized_Request(self
._PLAYLIST
_URL
, payload
) 
  68         req
.add_header('Content-type', 'application/x-www-form-urlencoded') 
  70         track 
= self
._download
_json
(req
, track_id
, 'Downloading playlist')[0] 
  71         title 
= '{artist:s} - {title:s}'.format(**track
) 
  74         if track
.get('category'): 
  75             categories 
= [track
['category']] 
  77         description 
= self
._og
_search
_description
(webpage
) 
  78         thumbnail 
= self
._og
_search
_thumbnail
(webpage
) 
  80         meta_span 
= r
'<span[^>]+class="%s".*?</i>([^<]+)</span>' 
  81         view_count 
= str_to_int(self
._search
_regex
( 
  82             meta_span 
% 'plays_count', webpage
, 'view count', fatal
=False)) 
  83         like_count 
= str_to_int(self
._search
_regex
( 
  84             meta_span 
% 'likes_count', webpage
, 'like count', fatal
=False)) 
  85         comment_count 
= str_to_int(self
._search
_regex
( 
  86             meta_span 
% 'comment_count', webpage
, 'comment count', fatal
=False)) 
  87         duration 
= str_to_int(self
._search
_regex
( 
  88             r
'data-length="(\d+)', webpage
, 'duration', fatal
=False)) 
  89         timestamp 
= str_to_int(self
._search
_regex
( 
  90             r
'<span[^>]+class="calctime"[^>]+data-time="(\d+)', webpage
, 'timestamp', fatal
=False)) 
  93         mp3_url 
= self
._search
_regex
( 
  94             r
'(?s)<a class="player-link"\s+(?:[a-zA-Z0-9_:-]+="[^"]+"\s+)*?data-mp3="([^"]+)"', 
  95             webpage
, 'mp3 URL', fatal
=False) 
 103         download_path 
= self
._search
_regex
( 
 104             r
'<a class="[^"]*download_fct[^"]*"\s+href="([^"]+)"', 
 105             webpage
, 'download URL', default
=None) 
 107             download_url 
= compat_urlparse
.urljoin(url
, download_path
) 
 108             ext_req 
= HEADRequest(download_url
) 
 109             ext_handle 
= self
._request
_webpage
( 
 110                 ext_req
, display_id
, note
='Determining extension') 
 111             ext 
= urlhandle_detect_ext(ext_handle
) 
 112             if ext 
in KNOWN_EXTENSIONS
: 
 114                     'format_id': 'download', 
 118                     'preference': 2,  # Usually better quality 
 120         self
._sort
_formats
(formats
) 
 124             'display_id': display_id
, 
 127             'thumbnail': thumbnail
, 
 128             'description': description
, 
 129             'duration': duration
, 
 130             'timestamp': timestamp
, 
 131             'view_count': view_count
, 
 132             'comment_count': comment_count
, 
 133             'like_count': like_count
, 
 134             'categories': categories
,