Skip to content

Commit d6bc443

Browse files
authored
[fc2] Fix extraction (yt-dlp#2572)
Closes yt-dlp#2566 Authored by: Lesmiscore
1 parent 046cab3 commit d6bc443

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

yt_dlp/extractor/fc2.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# coding: utf-8
22
from __future__ import unicode_literals
33

4-
import hashlib
5-
64
from .common import InfoExtractor
75
from ..compat import (
86
compat_parse_qs,
9-
compat_urllib_request,
10-
compat_urlparse,
117
)
128
from ..utils import (
139
ExtractorError,
1410
sanitized_Request,
11+
traverse_obj,
1512
urlencode_postdata,
13+
urljoin,
1614
)
1715

1816

@@ -82,41 +80,32 @@ def _real_extract(self, url):
8280
self._downloader.cookiejar.clear_session_cookies() # must clear
8381
self._login()
8482

85-
title = 'FC2 video %s' % video_id
86-
thumbnail = None
83+
title, thumbnail, description = None, None, None
8784
if webpage is not None:
88-
title = self._og_search_title(webpage)
85+
title = self._html_search_regex(
86+
(r'<h2\s+class="videoCnt_title">([^<]+?)</h2>',
87+
r'\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*<img',
88+
# there's two matches in the webpage
89+
r'\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*\1'),
90+
webpage,
91+
'title', fatal=False)
8992
thumbnail = self._og_search_thumbnail(webpage)
90-
refer = url.replace('/content/', '/a/content/') if '/a/content/' not in url else url
91-
92-
mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
93-
94-
info_url = (
95-
'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&'.
96-
format(video_id, mimi, compat_urllib_request.quote(refer, safe=b'').replace('.', '%2E')))
97-
98-
info_webpage = self._download_webpage(
99-
info_url, video_id, note='Downloading info page')
100-
info = compat_urlparse.parse_qs(info_webpage)
93+
description = self._og_search_description(webpage)
10194

102-
if 'err_code' in info:
103-
# most of the time we can still download wideo even if err_code is 403 or 602
104-
self.report_warning(
105-
'Error code was: %s... but still trying' % info['err_code'][0])
106-
107-
if 'filepath' not in info:
108-
raise ExtractorError('Cannot download file. Are you logged in?')
109-
110-
video_url = info['filepath'][0] + '?mid=' + info['mid'][0]
111-
title_info = info.get('title')
112-
if title_info:
113-
title = title_info[0]
95+
vidplaylist = self._download_json(
96+
'https://video.fc2.com/api/v3/videoplaylist/%s?sh=1&fs=0' % video_id, video_id,
97+
note='Downloading info page')
98+
vid_url = traverse_obj(vidplaylist, ('playlist', 'nq'))
99+
if not vid_url:
100+
raise ExtractorError('Unable to extract video URL')
101+
vid_url = urljoin('https://video.fc2.com/', vid_url)
114102

115103
return {
116104
'id': video_id,
117105
'title': title,
118-
'url': video_url,
119-
'ext': 'flv',
106+
'url': vid_url,
107+
'ext': 'mp4',
108+
'description': description,
120109
'thumbnail': thumbnail,
121110
}
122111

0 commit comments

Comments
 (0)