meipai.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from ..utils import parse_iso8601
  4. from .common import InfoExtractor
  5. class MeipaiIE(InfoExtractor):
  6. IE_DESC = '美拍'
  7. _VALID_URL = r'https?://(?:www\.)?meipai.com/media/(?P<id>[0-9]+)'
  8. _TESTS = [
  9. {
  10. 'url': 'http://www.meipai.com/media/531697625',
  11. 'md5': 'e3e9600f9e55a302daecc90825854b4f',
  12. 'info_dict': {
  13. 'id': '531697625',
  14. 'ext': 'mp4',
  15. 'title': '#葉子##阿桑##余姿昀##超級女聲#',
  16. 'description': '#葉子##阿桑##余姿昀##超級女聲#',
  17. 'thumbnail': 're:^https?://.*\.jpg$',
  18. 'creator': '她她-TATA',
  19. 'tags': ['葉子', '阿桑', '余姿昀', '超級女聲'],
  20. 'release_date': 1465492420,
  21. }
  22. },
  23. {
  24. 'url': 'http://www.meipai.com/media/576409659',
  25. 'md5': '2e807c16ebe67b8b6b3c8dcacbc32f48',
  26. 'info_dict': {
  27. 'id': '576409659',
  28. 'ext': 'mp4',
  29. 'title': '#失語者##蔡健雅##吉他彈唱#',
  30. 'description': '#失語者##蔡健雅##吉他彈唱#',
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. 'creator': '她她-TATA',
  33. 'tags': ['失語者', '蔡健雅', '吉他彈唱'],
  34. 'release_date': 1472534847,
  35. }
  36. },
  37. # record of live streaming
  38. {
  39. 'url': 'http://www.meipai.com/media/585526361',
  40. 'md5': 'ff7d6afdbc6143342408223d4f5fb99a',
  41. 'info_dict': {
  42. 'id': '585526361',
  43. 'ext': 'mp4',
  44. 'title': '姿昀和善願 練歌練琴啦😁😁😁',
  45. 'description': '姿昀和善願 練歌練琴啦😁😁😁',
  46. 'thumbnail': 're:^https?://.*\.jpg$',
  47. 'creator': '她她-TATA',
  48. 'release_date': 1474311799,
  49. }
  50. },
  51. ]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  55. title = self._og_search_title(webpage, default=None)
  56. if title is None:
  57. # fall back to text used in title
  58. title = self._html_search_regex(
  59. r'<title[^>]*>(.+)</title>', webpage, 'title')
  60. release_date = self._og_search_property(
  61. 'video:release_date', webpage, 'release date', fatal=False)
  62. release_date = parse_iso8601(release_date)
  63. tags = self._og_search_property(
  64. 'video:tag', webpage, 'tags', default='').split(',')
  65. info = {
  66. 'id': video_id,
  67. 'title': title,
  68. 'thumbnail': self._og_search_thumbnail(webpage),
  69. 'description': self._og_search_description(webpage),
  70. 'release_date': release_date,
  71. 'creator': self._og_search_property(
  72. 'video:director', webpage, 'creator', fatal=False),
  73. 'tags': tags,
  74. }
  75. keywords = self._html_search_meta(
  76. 'keywords', webpage, 'keywords', default=[])
  77. if '直播回放' in keywords:
  78. # recorded playback of live streaming
  79. m3u8_url = self._html_search_regex(
  80. r'file:\s*encodeURIComponent\(["\'](.+)["\']\)',
  81. webpage,
  82. 'm3u8_url')
  83. info['formats'] = self._extract_m3u8_formats(
  84. m3u8_url, video_id, 'mp4', 'm3u8_native')
  85. else:
  86. # regular uploaded video
  87. info['url'] = self._og_search_video_url(webpage)
  88. return info