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.

80 lines
2.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class VideoBamIE(InfoExtractor):
  7. _VALID_URL = r'http://(?:www\.)?videobam\.com/(?:videos/download/)?(?P<id>[a-zA-Z]+)'
  8. _TESTS = [
  9. {
  10. 'url': 'http://videobam.com/OiJQM',
  11. 'md5': 'db471f27763a531f10416a0c58b5a1e0',
  12. 'info_dict': {
  13. 'id': 'OiJQM',
  14. 'ext': 'mp4',
  15. 'title': 'Is Alcohol Worse Than Ecstasy?',
  16. 'description': 'md5:d25b96151515c91debc42bfbb3eb2683',
  17. 'uploader': 'frihetsvinge',
  18. },
  19. },
  20. {
  21. 'url': 'http://videobam.com/pqLvq',
  22. 'md5': 'd9a565b5379a99126ef94e1d7f9a383e',
  23. 'note': 'HD video',
  24. 'info_dict': {
  25. 'id': 'pqLvq',
  26. 'ext': 'mp4',
  27. 'title': '_',
  28. }
  29. },
  30. ]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. page = self._download_webpage('http://videobam.com/%s' % video_id, video_id, 'Downloading page')
  35. formats = []
  36. for preference, format_id in enumerate(['low', 'high']):
  37. mobj = re.search(r"%s: '(?P<url>[^']+)'" % format_id, page)
  38. if not mobj:
  39. continue
  40. formats.append({
  41. 'url': mobj.group('url'),
  42. 'ext': 'mp4',
  43. 'format_id': format_id,
  44. 'preference': preference,
  45. })
  46. if not formats:
  47. player_config = json.loads(self._html_search_regex(r'var player_config = ({.+?});', page, 'player config'))
  48. formats = [{
  49. 'url': item['url'],
  50. 'ext': 'mp4',
  51. } for item in player_config['playlist'] if 'autoPlay' in item]
  52. self._sort_formats(formats)
  53. title = self._og_search_title(page, default='_', fatal=False)
  54. description = self._og_search_description(page, default=None)
  55. thumbnail = self._og_search_thumbnail(page)
  56. uploader = self._html_search_regex(r'Upload by ([^<]+)</a>', page, 'uploader', fatal=False, default=None)
  57. view_count = int_or_none(
  58. self._html_search_regex(r'<strong>Views:</strong> (\d+) ', page, 'view count', fatal=False))
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'description': description,
  63. 'thumbnail': thumbnail,
  64. 'uploader': uploader,
  65. 'view_count': view_count,
  66. 'formats': formats,
  67. 'age_limit': 18,
  68. }