[viki] Pass session token around (#6005)
authorSergey M․ <dstftw@gmail.com>
Fri, 19 Jun 2015 18:49:28 +0000 (00:49 +0600)
committerSergey M․ <dstftw@gmail.com>
Fri, 19 Jun 2015 18:49:28 +0000 (00:49 +0600)
youtube_dl/extractor/viki.py

index 52d10d2421231ab25e09ac635d5efc3477fa92e4..51cdc6b65143aaf4a0d2823ffa8c859c96e25972 100644 (file)
@@ -28,11 +28,15 @@ class VikiBaseIE(InfoExtractor):
 
     _NETRC_MACHINE = 'viki'
 
+    _token = None
+
     def _prepare_call(self, path, timestamp=None, post_data=None):
         path += '?' if '?' not in path else '&'
         if not timestamp:
             timestamp = int(time.time())
         query = self._API_QUERY_TEMPLATE % (path, self._APP, timestamp)
+        if self._token:
+            query += '&token=%s' % self._token
         sig = hmac.new(
             self._APP_SECRET.encode('ascii'),
             query.encode('ascii'),
@@ -76,10 +80,14 @@ class VikiBaseIE(InfoExtractor):
             'password': password,
         }
 
-        self._call_api(
+        login = self._call_api(
             'sessions.json', None,
             'Logging in as %s' % username, post_data=login_form)
 
+        self._token = login.get('token')
+        if not self._token:
+            self.report_warning('Unable to get session token, login has probably failed')
+
 
 class VikiIE(VikiBaseIE):
     IE_NAME = 'viki'