tunepk.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. int_or_none,
  5. try_get,
  6. unified_timestamp,
  7. )
  8. class TunePkIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. https?://
  11. (?:
  12. (?:www\.)?tune\.pk/(?:video/|player/embed_player.php?.*?\bvid=)|
  13. embed\.tune\.pk/play/
  14. )
  15. (?P<id>\d+)
  16. '''
  17. _TESTS = [{
  18. 'url': 'https://tune.pk/video/6919541/maudie-2017-international-trailer-1-ft-ethan-hawke-sally-hawkins',
  19. 'md5': '0c537163b7f6f97da3c5dd1e3ef6dd55',
  20. 'info_dict': {
  21. 'id': '6919541',
  22. 'ext': 'mp4',
  23. 'title': 'Maudie (2017) | International Trailer # 1 ft Ethan Hawke, Sally Hawkins',
  24. 'description': 'md5:eb5a04114fafef5cec90799a93a2d09c',
  25. 'thumbnail': r're:^https?://.*\.jpg$',
  26. 'timestamp': 1487327564,
  27. 'upload_date': '20170217',
  28. 'uploader': 'Movie Trailers',
  29. 'duration': 107,
  30. 'view_count': int,
  31. }
  32. }, {
  33. 'url': 'https://tune.pk/player/embed_player.php?vid=6919541&folder=2017/02/17/&width=600&height=350&autoplay=no',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://embed.tune.pk/play/6919541?autoplay=no&ssl=yes&inline=true',
  37. 'only_matching': True,
  38. }]
  39. def _real_extract(self, url):
  40. video_id = self._match_id(url)
  41. webpage = self._download_webpage(
  42. 'https://tune.pk/video/%s' % video_id, video_id)
  43. details = self._parse_json(
  44. self._search_regex(
  45. r'new\s+TunePlayer\(({.+?})\)\s*;\s*\n', webpage, 'tune player'),
  46. video_id)['details']
  47. video = details['video']
  48. title = video.get('title') or self._og_search_title(
  49. webpage, default=None) or self._html_search_meta(
  50. 'title', webpage, 'title', fatal=True)
  51. formats = self._parse_jwplayer_formats(
  52. details['player']['sources'], video_id)
  53. description = self._og_search_description(
  54. webpage, default=None) or self._html_search_meta(
  55. 'description', webpage, 'description')
  56. thumbnail = video.get('thumb') or self._og_search_thumbnail(
  57. webpage, default=None) or self._html_search_meta(
  58. 'thumbnail', webpage, 'thumbnail')
  59. timestamp = unified_timestamp(video.get('date_added'))
  60. uploader = try_get(
  61. video, lambda x: x['uploader']['name'],
  62. compat_str) or self._html_search_meta('author', webpage, 'author')
  63. duration = int_or_none(video.get('duration'))
  64. view_count = int_or_none(video.get('views'))
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'description': description,
  69. 'thumbnail': thumbnail,
  70. 'timestamp': timestamp,
  71. 'uploader': uploader,
  72. 'duration': duration,
  73. 'view_count': view_count,
  74. 'formats': formats,
  75. }