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.

89 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from .youtube import YoutubeIE
  5. from ..compat import compat_str
  6. from ..utils import int_or_none
  7. class BreakIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?break\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)'
  9. _TESTS = [{
  10. 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
  11. 'info_dict': {
  12. 'id': '2468056',
  13. 'ext': 'mp4',
  14. 'title': 'When Girls Act Like D-Bags',
  15. 'age_limit': 13,
  16. },
  17. }, {
  18. # youtube embed
  19. 'url': 'http://www.break.com/video/someone-forgot-boat-brakes-work',
  20. 'info_dict': {
  21. 'id': 'RrrDLdeL2HQ',
  22. 'ext': 'mp4',
  23. 'title': 'Whale Watching Boat Crashing Into San Diego Dock',
  24. 'description': 'md5:afc1b2772f0a8468be51dd80eb021069',
  25. 'upload_date': '20160331',
  26. 'uploader': 'Steve Holden',
  27. 'uploader_id': 'sdholden07',
  28. },
  29. 'params': {
  30. 'skip_download': True,
  31. }
  32. }, {
  33. 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. display_id, video_id = re.match(self._VALID_URL, url).groups()
  38. webpage = self._download_webpage(url, display_id)
  39. youtube_url = YoutubeIE._extract_url(webpage)
  40. if youtube_url:
  41. return self.url_result(youtube_url, ie=YoutubeIE.ie_key())
  42. content = self._parse_json(
  43. self._search_regex(
  44. r'(?s)content["\']\s*:\s*(\[.+?\])\s*[,\n]', webpage,
  45. 'content'),
  46. display_id)
  47. formats = []
  48. for video in content:
  49. video_url = video.get('url')
  50. if not video_url or not isinstance(video_url, compat_str):
  51. continue
  52. bitrate = int_or_none(self._search_regex(
  53. r'(\d+)_kbps', video_url, 'tbr', default=None))
  54. formats.append({
  55. 'url': video_url,
  56. 'format_id': 'http-%d' % bitrate if bitrate else 'http',
  57. 'tbr': bitrate,
  58. })
  59. self._sort_formats(formats)
  60. title = self._search_regex(
  61. (r'title["\']\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  62. r'<h1[^>]*>(?P<value>[^<]+)'), webpage, 'title', group='value')
  63. def get(key, name):
  64. return int_or_none(self._search_regex(
  65. r'%s["\']\s*:\s*["\'](\d+)' % key, webpage, name,
  66. default=None))
  67. age_limit = get('ratings', 'age limit')
  68. video_id = video_id or get('pid', 'video id') or display_id
  69. return {
  70. 'id': video_id,
  71. 'display_id': display_id,
  72. 'title': title,
  73. 'thumbnail': self._og_search_thumbnail(webpage),
  74. 'age_limit': age_limit,
  75. 'formats': formats,
  76. }