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.

105 lines
3.2 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. 'https://api.beeg.com/api/v6/1738/video/%s' % video_id, video_id)
  33. def split(o, e):
  34. def cut(s, x):
  35. n.append(s[:x])
  36. return s[x:]
  37. n = []
  38. r = len(o) % e
  39. if r > 0:
  40. o = cut(o, r)
  41. while len(o) > e:
  42. o = cut(o, e)
  43. n.append(o)
  44. return n
  45. def decrypt_key(key):
  46. # Reverse engineered from http://static.beeg.com/cpl/1738.js
  47. a = 'GUuyodcfS8FW8gQp4OKLMsZBcX0T7B'
  48. e = compat_urllib_parse_unquote(key)
  49. o = ''.join([
  50. compat_chr(compat_ord(e[n]) - compat_ord(a[n % len(a)]) % 21)
  51. for n in range(len(e))])
  52. return ''.join(split(o, 3)[::-1])
  53. def decrypt_url(encrypted_url):
  54. encrypted_url = self._proto_relative_url(
  55. encrypted_url.replace('{DATA_MARKERS}', ''), 'https:')
  56. key = self._search_regex(
  57. r'/key=(.*?)%2Cend=', encrypted_url, 'key', default=None)
  58. if not key:
  59. return encrypted_url
  60. return encrypted_url.replace(key, decrypt_key(key))
  61. formats = []
  62. for format_id, video_url in video.items():
  63. if not video_url:
  64. continue
  65. height = self._search_regex(
  66. r'^(\d+)[pP]$', format_id, 'height', default=None)
  67. if not height:
  68. continue
  69. formats.append({
  70. 'url': decrypt_url(video_url),
  71. 'format_id': format_id,
  72. 'height': int(height),
  73. })
  74. self._sort_formats(formats)
  75. title = video['title']
  76. video_id = video.get('id') or video_id
  77. display_id = video.get('code')
  78. description = video.get('desc')
  79. timestamp = parse_iso8601(video.get('date'), ' ')
  80. duration = int_or_none(video.get('duration'))
  81. tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
  82. return {
  83. 'id': video_id,
  84. 'display_id': display_id,
  85. 'title': title,
  86. 'description': description,
  87. 'timestamp': timestamp,
  88. 'duration': duration,
  89. 'tags': tags,
  90. 'formats': formats,
  91. 'age_limit': 18,
  92. }