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.

63 lines
2.0 KiB

  1. #! -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. import hashlib
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. compat_urllib_request,
  9. compat_urlparse,
  10. )
  11. class FC2IE(InfoExtractor):
  12. _VALID_URL = r'^http://video\.fc2\.com/((?P<lang>[^/]+)/)?content/(?P<id>[^/]+)'
  13. IE_NAME = 'fc2'
  14. _TEST = {
  15. 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs',
  16. 'md5': 'a6ebe8ebe0396518689d963774a54eb7',
  17. 'info_dict': {
  18. 'id': '20121103kUan1KHs',
  19. 'ext': 'flv',
  20. 'title': 'Boxing again with Puff',
  21. },
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  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. }