yt-dlp/youtube_dl/extractor/breakcom.py

43 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

2014-02-10 19:48:46 +00:00
from __future__ import unicode_literals
2013-06-23 20:59:51 +00:00
import re
import json
2013-06-23 20:59:51 +00:00
from .common import InfoExtractor
class BreakIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?break\.com/video/(?:[^/]+/)*.+-(?P<id>\d+)'
_TESTS = [{
2014-02-10 19:48:46 +00:00
'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
'md5': '33aa4ff477ecd124d18d7b5d23b87ce5',
2014-02-10 19:48:46 +00:00
'info_dict': {
'id': '2468056',
'ext': 'mp4',
'title': 'When Girls Act Like D-Bags',
2013-06-27 18:46:46 +00:00
}
}, {
'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
'only_matching': True,
}]
2013-06-23 20:59:51 +00:00
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(
'http://www.break.com/embed/%s' % video_id, video_id)
info = json.loads(self._search_regex(
r'var embedVars = ({.*})\s*?</script>',
webpage, 'info json', flags=re.DOTALL))
video_url = info['videoUri']
youtube_id = info.get('youtubeId')
if youtube_id:
return self.url_result(youtube_id, 'Youtube')
final_url = video_url + '?' + info['AuthToken']
2014-02-10 19:48:46 +00:00
return {
'id': video_id,
'url': final_url,
'title': info['contentName'],
'thumbnail': info['thumbUri'],
2014-02-10 19:48:46 +00:00
}