beeg.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. int_or_none,
  6. unified_timestamp,
  7. )
  8. class BeegIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?beeg\.com/(?P<id>\d+)'
  10. _TEST = {
  11. 'url': 'http://beeg.com/5416503',
  12. 'md5': 'a1a1b1a8bc70a89e49ccfd113aed0820',
  13. 'info_dict': {
  14. 'id': '5416503',
  15. 'ext': 'mp4',
  16. 'title': 'Sultry Striptease',
  17. 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
  18. 'timestamp': 1391813355,
  19. 'upload_date': '20140207',
  20. 'duration': 383,
  21. 'tags': list,
  22. 'age_limit': 18,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. beeg_version = self._search_regex(
  29. r'beeg_version\s*=\s*([\da-zA-Z_-]+)', webpage, 'beeg version',
  30. default='1546225636701')
  31. for api_path in ('', 'api.'):
  32. video = self._download_json(
  33. 'https://%sbeeg.com/api/v6/%s/video/%s'
  34. % (api_path, beeg_version, video_id), video_id,
  35. fatal=api_path == 'api.')
  36. if video:
  37. break
  38. formats = []
  39. for format_id, video_url in video.items():
  40. if not video_url:
  41. continue
  42. height = self._search_regex(
  43. r'^(\d+)[pP]$', format_id, 'height', default=None)
  44. if not height:
  45. continue
  46. formats.append({
  47. 'url': self._proto_relative_url(
  48. video_url.replace('{DATA_MARKERS}', 'data=pc_XX__%s_0' % beeg_version), 'https:'),
  49. 'format_id': format_id,
  50. 'height': int(height),
  51. })
  52. self._sort_formats(formats)
  53. title = video['title']
  54. video_id = compat_str(video.get('id') or video_id)
  55. display_id = video.get('code')
  56. description = video.get('desc')
  57. series = video.get('ps_name')
  58. timestamp = unified_timestamp(video.get('date'))
  59. duration = int_or_none(video.get('duration'))
  60. tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
  61. return {
  62. 'id': video_id,
  63. 'display_id': display_id,
  64. 'title': title,
  65. 'description': description,
  66. 'series': series,
  67. 'timestamp': timestamp,
  68. 'duration': duration,
  69. 'tags': tags,
  70. 'formats': formats,
  71. 'age_limit': self._rta_search(webpage),
  72. }