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.

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