logo

youtube-dl

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

tunepk.py (3200B)


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