appleconnect.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. str_to_int,
  4. ExtractorError
  5. )
  6. class AppleConnectIE(InfoExtractor):
  7. _VALID_URL = r'https?://itunes\.apple\.com/\w{0,2}/?post/(?:id)?sa\.(?P<id>[\w-]+)'
  8. _TESTS = [{
  9. 'url': 'https://itunes.apple.com/us/post/idsa.4ab17a39-2720-11e5-96c5-a5b38f6c42d3',
  10. 'md5': 'c1d41f72c8bcaf222e089434619316e4',
  11. 'info_dict': {
  12. 'id': '4ab17a39-2720-11e5-96c5-a5b38f6c42d3',
  13. 'ext': 'm4v',
  14. 'title': 'Energy',
  15. 'uploader': 'Drake',
  16. 'thumbnail': r're:^https?://.*\.jpg$',
  17. 'upload_date': '20150710',
  18. 'timestamp': 1436545535,
  19. },
  20. }, {
  21. 'url': 'https://itunes.apple.com/us/post/sa.0fe0229f-2457-11e5-9f40-1bb645f2d5d9',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. try:
  28. video_json = self._html_search_regex(
  29. r'class="auc-video-data">(\{.*?\})', webpage, 'json')
  30. except ExtractorError:
  31. raise ExtractorError('This post doesn\'t contain a video', expected=True)
  32. video_data = self._parse_json(video_json, video_id)
  33. timestamp = str_to_int(self._html_search_regex(r'data-timestamp="(\d+)"', webpage, 'timestamp'))
  34. like_count = str_to_int(self._html_search_regex(r'(\d+) Loves', webpage, 'like count', default=None))
  35. return {
  36. 'id': video_id,
  37. 'url': video_data['sslSrc'],
  38. 'title': video_data['title'],
  39. 'description': video_data['description'],
  40. 'uploader': video_data['artistName'],
  41. 'thumbnail': video_data['artworkUrl'],
  42. 'timestamp': timestamp,
  43. 'like_count': like_count,
  44. }