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.

116 lines
3.5 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_str,
  5. compat_urlparse,
  6. )
  7. from ..utils import (
  8. int_or_none,
  9. unified_timestamp,
  10. )
  11. class BeegIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?beeg\.(?:com|porn(?:/video)?)/(?P<id>\d+)'
  13. _TESTS = [{
  14. # api/v6 v1
  15. 'url': 'http://beeg.com/5416503',
  16. 'md5': 'a1a1b1a8bc70a89e49ccfd113aed0820',
  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. # api/v6 v2
  30. 'url': 'https://beeg.com/1941093077?t=911-1391',
  31. 'only_matching': True,
  32. }, {
  33. # api/v6 v2 w/o t
  34. 'url': 'https://beeg.com/1277207756',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'https://beeg.porn/video/5416503',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'https://beeg.porn/5416503',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. webpage = self._download_webpage(url, video_id)
  46. beeg_version = self._search_regex(
  47. r'beeg_version\s*=\s*([\da-zA-Z_-]+)', webpage, 'beeg version',
  48. default='1546225636701')
  49. if len(video_id) >= 10:
  50. query = {
  51. 'v': 2,
  52. }
  53. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  54. t = qs.get('t', [''])[0].split('-')
  55. if len(t) > 1:
  56. query.update({
  57. 's': t[0],
  58. 'e': t[1],
  59. })
  60. else:
  61. query = {'v': 1}
  62. for api_path in ('', 'api.'):
  63. video = self._download_json(
  64. 'https://%sbeeg.com/api/v6/%s/video/%s'
  65. % (api_path, beeg_version, video_id), video_id,
  66. fatal=api_path == 'api.', query=query)
  67. if video:
  68. break
  69. formats = []
  70. for format_id, video_url in video.items():
  71. if not video_url:
  72. continue
  73. height = self._search_regex(
  74. r'^(\d+)[pP]$', format_id, 'height', default=None)
  75. if not height:
  76. continue
  77. formats.append({
  78. 'url': self._proto_relative_url(
  79. video_url.replace('{DATA_MARKERS}', 'data=pc_XX__%s_0' % beeg_version), 'https:'),
  80. 'format_id': format_id,
  81. 'height': int(height),
  82. })
  83. self._sort_formats(formats)
  84. title = video['title']
  85. video_id = compat_str(video.get('id') or video_id)
  86. display_id = video.get('code')
  87. description = video.get('desc')
  88. series = video.get('ps_name')
  89. timestamp = unified_timestamp(video.get('date'))
  90. duration = int_or_none(video.get('duration'))
  91. tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
  92. return {
  93. 'id': video_id,
  94. 'display_id': display_id,
  95. 'title': title,
  96. 'description': description,
  97. 'series': series,
  98. 'timestamp': timestamp,
  99. 'duration': duration,
  100. 'tags': tags,
  101. 'formats': formats,
  102. 'age_limit': self._rta_search(webpage),
  103. }