logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

appleconnect.py (1909B)


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