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.8 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_chr,
  5. compat_ord,
  6. compat_urllib_parse_unquote,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. parse_iso8601,
  11. )
  12. class BeegIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?beeg\.com/(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://beeg.com/5416503',
  16. 'md5': '46c384def73b33dbc581262e5ee67cef',
  17. 'info_dict': {
  18. 'id': '5416503',
  19. 'ext': 'mp4',
  20. 'title': 'Sultry Striptease',
  21. 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
  22. 'timestamp': 1391813355,
  23. 'upload_date': '20140207',
  24. 'duration': 383,
  25. 'tags': list,
  26. 'age_limit': 18,
  27. }
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. video = self._download_json(
  32. 'http://beeg.com/api/v4/video/%s' % video_id, video_id)
  33. def decrypt_key(key):
  34. # Reverse engineered from http://static.beeg.com/cpl/1067.js
  35. a = '8RPUUCS35ZWp3ADnKcSmpH71ZusrROo'
  36. e = compat_urllib_parse_unquote(key)
  37. return ''.join([
  38. compat_chr(compat_ord(e[n]) - compat_ord(a[n % len(a)]) % 25)
  39. for n in range(len(e))])
  40. def decrypt_url(encrypted_url):
  41. encrypted_url = self._proto_relative_url(
  42. encrypted_url.replace('{DATA_MARKERS}', ''), 'http:')
  43. key = self._search_regex(
  44. r'/key=(.*?)%2Cend=', encrypted_url, 'key', default=None)
  45. if not key:
  46. return encrypted_url
  47. return encrypted_url.replace(key, decrypt_key(key))
  48. formats = []
  49. for format_id, video_url in video.items():
  50. if not video_url:
  51. continue
  52. height = self._search_regex(
  53. r'^(\d+)[pP]$', format_id, 'height', default=None)
  54. if not height:
  55. continue
  56. formats.append({
  57. 'url': decrypt_url(video_url),
  58. 'format_id': format_id,
  59. 'height': int(height),
  60. })
  61. self._sort_formats(formats)
  62. title = video['title']
  63. video_id = video.get('id') or video_id
  64. display_id = video.get('code')
  65. description = video.get('desc')
  66. timestamp = parse_iso8601(video.get('date'), ' ')
  67. duration = int_or_none(video.get('duration'))
  68. tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
  69. return {
  70. 'id': video_id,
  71. 'display_id': display_id,
  72. 'title': title,
  73. 'description': description,
  74. 'timestamp': timestamp,
  75. 'duration': duration,
  76. 'tags': tags,
  77. 'formats': formats,
  78. 'age_limit': 18,
  79. }