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.

64 lines
1.9 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'https?://(?: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. 'age_limit': 13,
  18. }
  19. }, {
  20. 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
  21. 'only_matching': True,
  22. }]
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(
  26. 'http://www.break.com/embed/%s' % video_id, video_id)
  27. info = json.loads(self._search_regex(
  28. r'var embedVars = ({.*})\s*?</script>',
  29. webpage, 'info json', flags=re.DOTALL))
  30. youtube_id = info.get('youtubeId')
  31. if youtube_id:
  32. return self.url_result(youtube_id, 'Youtube')
  33. formats = [{
  34. 'url': media['uri'] + '?' + info['AuthToken'],
  35. 'tbr': media['bitRate'],
  36. 'width': media['width'],
  37. 'height': media['height'],
  38. } for media in info['media'] if media.get('mediaPurpose') == 'play']
  39. if not formats:
  40. formats.append({
  41. 'url': info['videoUri']
  42. })
  43. self._sort_formats(formats)
  44. duration = int_or_none(info.get('videoLengthInSeconds'))
  45. age_limit = parse_age_limit(info.get('audienceRating'))
  46. return {
  47. 'id': video_id,
  48. 'title': info['contentName'],
  49. 'thumbnail': info['thumbUri'],
  50. 'duration': duration,
  51. 'age_limit': age_limit,
  52. 'formats': formats,
  53. }