logo

youtube-dl

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

meipai.py (3709B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. unified_timestamp,
  8. )
  9. class MeipaiIE(InfoExtractor):
  10. IE_DESC = '美拍'
  11. _VALID_URL = r'https?://(?:www\.)?meipai\.com/media/(?P<id>[0-9]+)'
  12. _TESTS = [{
  13. # regular uploaded video
  14. 'url': 'http://www.meipai.com/media/531697625',
  15. 'md5': 'e3e9600f9e55a302daecc90825854b4f',
  16. 'info_dict': {
  17. 'id': '531697625',
  18. 'ext': 'mp4',
  19. 'title': '#葉子##阿桑##余姿昀##超級女聲#',
  20. 'description': '#葉子##阿桑##余姿昀##超級女聲#',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'duration': 152,
  23. 'timestamp': 1465492420,
  24. 'upload_date': '20160609',
  25. 'view_count': 35511,
  26. 'creator': '她她-TATA',
  27. 'tags': ['葉子', '阿桑', '余姿昀', '超級女聲'],
  28. }
  29. }, {
  30. # record of live streaming
  31. 'url': 'http://www.meipai.com/media/585526361',
  32. 'md5': 'ff7d6afdbc6143342408223d4f5fb99a',
  33. 'info_dict': {
  34. 'id': '585526361',
  35. 'ext': 'mp4',
  36. 'title': '姿昀和善願 練歌練琴啦😁😁😁',
  37. 'description': '姿昀和善願 練歌練琴啦😁😁😁',
  38. 'thumbnail': r're:^https?://.*\.jpg$',
  39. 'duration': 5975,
  40. 'timestamp': 1474311799,
  41. 'upload_date': '20160919',
  42. 'view_count': 1215,
  43. 'creator': '她她-TATA',
  44. }
  45. }]
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. webpage = self._download_webpage(url, video_id)
  49. title = self._og_search_title(
  50. webpage, default=None) or self._html_search_regex(
  51. r'<title[^>]*>([^<]+)</title>', webpage, 'title')
  52. formats = []
  53. # recorded playback of live streaming
  54. m3u8_url = self._html_search_regex(
  55. r'file:\s*encodeURIComponent\((["\'])(?P<url>(?:(?!\1).)+)\1\)',
  56. webpage, 'm3u8 url', group='url', default=None)
  57. if m3u8_url:
  58. formats.extend(self._extract_m3u8_formats(
  59. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
  60. m3u8_id='hls', fatal=False))
  61. if not formats:
  62. # regular uploaded video
  63. video_url = self._search_regex(
  64. r'data-video=(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'video url',
  65. group='url', default=None)
  66. if video_url:
  67. formats.append({
  68. 'url': video_url,
  69. 'format_id': 'http',
  70. })
  71. timestamp = unified_timestamp(self._og_search_property(
  72. 'video:release_date', webpage, 'release date', fatal=False))
  73. tags = self._og_search_property(
  74. 'video:tag', webpage, 'tags', default='').split(',')
  75. view_count = int_or_none(self._html_search_meta(
  76. 'interactionCount', webpage, 'view count'))
  77. duration = parse_duration(self._html_search_meta(
  78. 'duration', webpage, 'duration'))
  79. creator = self._og_search_property(
  80. 'video:director', webpage, 'creator', fatal=False)
  81. return {
  82. 'id': video_id,
  83. 'title': title,
  84. 'description': self._og_search_description(webpage),
  85. 'thumbnail': self._og_search_thumbnail(webpage),
  86. 'duration': duration,
  87. 'timestamp': timestamp,
  88. 'view_count': view_count,
  89. 'creator': creator,
  90. 'tags': tags,
  91. 'formats': formats,
  92. }