meipai.py 3.5 KB

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