]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/niconico.py
46774317c9f6b47a337b20b70100a4d56e7fe022
6 from .common
import InfoExtractor
11 compat_urllib_request
,
20 class NiconicoIE(InfoExtractor
):
25 u
'url': u
'http://www.nicovideo.jp/watch/sm22312215',
26 u
'file': u
'sm22312215.mp4',
27 u
'md5': u
'd1a75c0823e2f629128c43e1212760f9',
29 u
'title': u
'Big Buck Bunny',
30 u
'uploader': u
'takuya0301',
31 u
'uploader_id': u
'2698420',
32 u
'upload_date': u
'20131123',
33 u
'description': u
'(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org',
36 u
'username': u
'ydl.niconico@gmail.com',
37 u
'password': u
'youtube-dl',
41 _VALID_URL
= r
'^https?://(?:www\.|secure\.)?nicovideo\.jp/watch/([a-z][a-z][0-9]+)(?:.*)$'
42 _NETRC_MACHINE
= 'niconico'
43 # If True it will raise an error if no login info is provided
44 _LOGIN_REQUIRED
= True
46 def _real_initialize(self
):
50 (username
, password
) = self
._get
_login
_info
()
51 # No authentication to be performed
53 if self
._LOGIN
_REQUIRED
:
54 raise ExtractorError(u
'No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True)
60 u
'password': password
,
62 # Convert to UTF-8 *before* urlencode because Python 2.x's urlencode
64 login_form
= dict((k
.encode('utf-8'), v
.encode('utf-8')) for k
,v
in login_form_strs
.items())
65 login_data
= compat_urllib_parse
.urlencode(login_form
).encode('utf-8')
66 request
= compat_urllib_request
.Request(
67 u
'https://secure.nicovideo.jp/secure/login', login_data
)
68 login_results
= self
._download
_webpage
(
69 request
, u
'', note
=u
'Logging in', errnote
=u
'Unable to log in')
70 if re
.search(r
'(?i)<h1 class="mb8p4">Log in error</h1>', login_results
) is not None:
71 self
._downloader
.report_warning(u
'unable to log in: bad username or password')
75 def _real_extract(self
, url
):
76 mobj
= re
.match(self
._VALID
_URL
, url
)
77 video_id
= mobj
.group(1)
79 # Get video webpage. We are not actually interested in it, but need
80 # the cookies in order to be able to download the info webpage
81 self
._download
_webpage
('http://www.nicovideo.jp/watch/' + video_id
, video_id
)
83 video_info
= self
._download
_xml
(
84 'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id
, video_id
,
85 note
=u
'Downloading video info page')
88 flv_info_webpage
= self
._download
_webpage
(
89 u
'http://flapi.nicovideo.jp/api/getflv?v=' + video_id
,
90 video_id
, u
'Downloading flv info')
91 video_real_url
= compat_urlparse
.parse_qs(flv_info_webpage
)['url'][0]
93 # Start extracting information
94 video_title
= video_info
.find('.//title').text
95 video_extension
= video_info
.find('.//movie_type').text
96 video_format
= video_extension
.upper()
97 video_thumbnail
= video_info
.find('.//thumbnail_url').text
98 video_description
= video_info
.find('.//description').text
99 video_uploader_id
= video_info
.find('.//user_id').text
100 video_upload_date
= unified_strdate(video_info
.find('.//first_retrieve').text
.split('+')[0])
101 video_view_count
= video_info
.find('.//view_counter').text
102 video_webpage_url
= video_info
.find('.//watch_url').text
105 video_uploader
= video_uploader_id
106 url
= 'http://seiga.nicovideo.jp/api/user/info?id=' + video_uploader_id
108 user_info
= self
._download
_xml
(
109 url
, video_id
, note
=u
'Downloading user information')
110 video_uploader
= user_info
.find('.//nickname').text
111 except (compat_urllib_error
.URLError
, compat_http_client
.HTTPException
, socket
.error
) as err
:
112 self
._downloader
.report_warning(u
'Unable to download user info webpage: %s' % compat_str(err
))
116 'url': video_real_url
,
117 'title': video_title
,
118 'ext': video_extension
,
119 'format': video_format
,
120 'thumbnail': video_thumbnail
,
121 'description': video_description
,
122 'uploader': video_uploader
,
123 'upload_date': video_upload_date
,
124 'uploader_id': video_uploader_id
,
125 'view_count': video_view_count
,
126 'webpage_url': video_webpage_url
,