miaopai.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import sanitized_Request
  5. class MiaoPaiIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?miaopai\.com/show/(?P<id>[-A-Za-z0-9~_]+).htm'
  7. _TEST = {
  8. 'url': 'http://www.miaopai.com/show/n~0hO7sfV1nBEw4Y29-Hqg__.htm',
  9. 'md5': '095ed3f1cd96b821add957bdc29f845b',
  10. 'info_dict': {
  11. 'id': 'n~0hO7sfV1nBEw4Y29-Hqg__',
  12. 'ext': 'mp4',
  13. 'title': '西游记音乐会的秒拍视频',
  14. 'thumbnail': 're:^https?://.*/n~0hO7sfV1nBEw4Y29-Hqg___m.jpg',
  15. }
  16. }
  17. _USER_AGENT_IPAD = 'User-Agent:Mozilla/5.0 ' \
  18. '(iPad; CPU OS 9_1 like Mac OS X) ' \
  19. 'AppleWebKit/601.1.46 (KHTML, like Gecko) ' \
  20. 'Version/9.0 Mobile/13B143 Safari/601.1'
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. request = sanitized_Request(url)
  24. request.add_header('User-Agent', self._USER_AGENT_IPAD)
  25. webpage = self._download_webpage(request, video_id)
  26. title = self._html_search_regex(r'<title>([^<]*)</title>',
  27. webpage,
  28. 'title')
  29. regex = r"""<div *class=['"]video_img[^>]*data-url=['"]([^'"]*\.jpg)['"]"""
  30. thumbnail = self._html_search_regex(regex, webpage, '')
  31. regex = r"""<video *[^>]*src=['"]([^'"]*)['"]""",
  32. video_url = self._html_search_regex(regex, webpage, '')
  33. return {'id': video_id,
  34. 'title': title,
  35. 'url': video_url,
  36. 'thumbnail': thumbnail,
  37. }