You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_age_limit,
  8. )
  9. class BreakIE(InfoExtractor):
  10. _VALID_URL = r'http://(?:www\.)?break\.com/video/(?:[^/]+/)*.+-(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
  13. 'info_dict': {
  14. 'id': '2468056',
  15. 'ext': 'mp4',
  16. 'title': 'When Girls Act Like D-Bags',
  17. }
  18. }, {
  19. 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(
  25. 'http://www.break.com/embed/%s' % video_id, video_id)
  26. info = json.loads(self._search_regex(
  27. r'var embedVars = ({.*})\s*?</script>',
  28. webpage, 'info json', flags=re.DOTALL))
  29. youtube_id = info.get('youtubeId')
  30. if youtube_id:
  31. return self.url_result(youtube_id, 'Youtube')
  32. formats = [{
  33. 'url': media['uri'] + '?' + info['AuthToken'],
  34. 'tbr': media['bitRate'],
  35. 'width': media['width'],
  36. 'height': media['height'],
  37. } for media in info['media'] if media.get('mediaPurpose') == 'play']
  38. if not formats:
  39. formats.append({
  40. 'url': info['videoUri']
  41. })
  42. self._sort_formats(formats)
  43. duration = int_or_none(info.get('videoLengthInSeconds'))
  44. age_limit = parse_age_limit(info.get('audienceRating'))
  45. return {
  46. 'id': video_id,
  47. 'title': info['contentName'],
  48. 'thumbnail': info['thumbUri'],
  49. 'duration': duration,
  50. 'age_limit': age_limit,
  51. 'formats': formats,
  52. }