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.

79 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. }
  28. },
  29. ]
  30. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('id')
  33. page = self._download_webpage('http://videobam.com/%s' % video_id, video_id, 'Downloading page')
  34. formats = []
  35. for preference, format_id in enumerate(['low', 'high']):
  36. mobj = re.search(r"%s: '(?P<url>[^']+)'" % format_id, page)
  37. if not mobj:
  38. continue
  39. formats.append({
  40. 'url': mobj.group('url'),
  41. 'ext': 'mp4',
  42. 'format_id': format_id,
  43. 'preference': preference,
  44. })
  45. if not formats:
  46. player_config = json.loads(self._html_search_regex(r'var player_config = ({.+?});', page, 'player config'))
  47. formats = [{
  48. 'url': item['url'],
  49. 'ext': 'mp4',
  50. } for item in player_config['playlist'] if 'autoPlay' in item]
  51. self._sort_formats(formats)
  52. title = self._og_search_title(page, default='VideoBam', fatal=False)
  53. description = self._og_search_description(page, default=None)
  54. thumbnail = self._og_search_thumbnail(page)
  55. uploader = self._html_search_regex(r'Upload by ([^<]+)</a>', page, 'uploader', fatal=False, default=None)
  56. view_count = int_or_none(
  57. self._html_search_regex(r'<strong>Views:</strong> (\d+) ', page, 'view count', fatal=False))
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'description': description,
  62. 'thumbnail': thumbnail,
  63. 'uploader': uploader,
  64. 'view_count': view_count,
  65. 'formats': formats,
  66. 'age_limit': 18,
  67. }