You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

10 years ago
  1. #! -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import hashlib
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. )
  12. class FC2IE(InfoExtractor):
  13. _VALID_URL = r'^http://video\.fc2\.com/(?:[^/]+/)?content/(?P<id>[^/]+)'
  14. IE_NAME = 'fc2'
  15. _TEST = {
  16. 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs',
  17. 'md5': 'a6ebe8ebe0396518689d963774a54eb7',
  18. 'info_dict': {
  19. 'id': '20121103kUan1KHs',
  20. 'ext': 'flv',
  21. 'title': 'Boxing again with Puff',
  22. },
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. self._downloader.cookiejar.clear_session_cookies() # must clear
  28. title = self._og_search_title(webpage)
  29. thumbnail = self._og_search_thumbnail(webpage)
  30. refer = url.replace('/content/', '/a/content/')
  31. mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
  32. info_url = (
  33. "http://video.fc2.com/ginfo.php?mimi={1:s}&href={2:s}&v={0:s}&fversion=WIN%2011%2C6%2C602%2C180&from=2&otag=0&upid={0:s}&tk=null&".
  34. format(video_id, mimi, compat_urllib_request.quote(refer, safe='').replace('.', '%2E')))
  35. info_webpage = self._download_webpage(
  36. info_url, video_id, note='Downloading info page')
  37. info = compat_urlparse.parse_qs(info_webpage)
  38. if 'err_code' in info:
  39. raise ExtractorError('Error code: %s' % info['err_code'][0])
  40. video_url = info['filepath'][0] + '?mid=' + info['mid'][0]
  41. title_info = info.get('title')
  42. if title_info:
  43. title = title_info[0]
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'url': video_url,
  48. 'ext': 'flv',
  49. 'thumbnail': thumbnail,
  50. }