aliexpress.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. float_or_none,
  5. try_get,
  6. )
  7. class AliExpressLiveIE(InfoExtractor):
  8. _VALID_URL = r'https?://live\.aliexpress\.com/live/(?P<id>\d+)'
  9. _TEST = {
  10. 'url': 'https://live.aliexpress.com/live/2800002704436634',
  11. 'md5': 'e729e25d47c5e557f2630eaf99b740a5',
  12. 'info_dict': {
  13. 'id': '2800002704436634',
  14. 'ext': 'mp4',
  15. 'title': 'CASIMA7.22',
  16. 'thumbnail': r're:https?://.*\.jpg',
  17. 'uploader': 'CASIMA Official Store',
  18. 'timestamp': 1500717600,
  19. 'upload_date': '20170722',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. data = self._parse_json(
  26. self._search_regex(
  27. r'(?s)runParams\s*=\s*({.+?})\s*;?\s*var',
  28. webpage, 'runParams'),
  29. video_id)
  30. title = data['title']
  31. formats = self._extract_m3u8_formats(
  32. data['replyStreamUrl'], video_id, 'mp4',
  33. entry_protocol='m3u8_native', m3u8_id='hls')
  34. return {
  35. 'id': video_id,
  36. 'title': title,
  37. 'thumbnail': data.get('coverUrl'),
  38. 'uploader': try_get(
  39. data, lambda x: x['followBar']['name'], compat_str),
  40. 'timestamp': float_or_none(data.get('startTimeLong'), scale=1000),
  41. 'formats': formats,
  42. }