[fc2] Fix extraction (#2572)

Closes #2566
Authored by: Lesmiscore
This commit is contained in:
Lesmiscore (Naoya Ozaki) 2022-02-01 22:22:18 +09:00 committed by GitHub
parent 046cab3915
commit d6bc443bde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 32 deletions

View File

@ -1,18 +1,16 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import hashlib
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_parse_qs, compat_parse_qs,
compat_urllib_request,
compat_urlparse,
) )
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
sanitized_Request, sanitized_Request,
traverse_obj,
urlencode_postdata, urlencode_postdata,
urljoin,
) )
@ -82,41 +80,32 @@ class FC2IE(InfoExtractor):
self._downloader.cookiejar.clear_session_cookies() # must clear self._downloader.cookiejar.clear_session_cookies() # must clear
self._login() self._login()
title = 'FC2 video %s' % video_id title, thumbnail, description = None, None, None
thumbnail = None
if webpage is not None: if webpage is not None:
title = self._og_search_title(webpage) title = self._html_search_regex(
(r'<h2\s+class="videoCnt_title">([^<]+?)</h2>',
r'\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*<img',
# there's two matches in the webpage
r'\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*\1'),
webpage,
'title', fatal=False)
thumbnail = self._og_search_thumbnail(webpage) thumbnail = self._og_search_thumbnail(webpage)
refer = url.replace('/content/', '/a/content/') if '/a/content/' not in url else url description = self._og_search_description(webpage)
mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest() vidplaylist = self._download_json(
'https://video.fc2.com/api/v3/videoplaylist/%s?sh=1&fs=0' % video_id, video_id,
info_url = ( note='Downloading info page')
'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&'. vid_url = traverse_obj(vidplaylist, ('playlist', 'nq'))
format(video_id, mimi, compat_urllib_request.quote(refer, safe=b'').replace('.', '%2E'))) if not vid_url:
raise ExtractorError('Unable to extract video URL')
info_webpage = self._download_webpage( vid_url = urljoin('https://video.fc2.com/', vid_url)
info_url, video_id, note='Downloading info page')
info = compat_urlparse.parse_qs(info_webpage)
if 'err_code' in info:
# most of the time we can still download wideo even if err_code is 403 or 602
self.report_warning(
'Error code was: %s... but still trying' % info['err_code'][0])
if 'filepath' not in info:
raise ExtractorError('Cannot download file. Are you logged in?')
video_url = info['filepath'][0] + '?mid=' + info['mid'][0]
title_info = info.get('title')
if title_info:
title = title_info[0]
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'url': video_url, 'url': vid_url,
'ext': 'flv', 'ext': 'mp4',
'description': description,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
} }