[lynda:course] Force log out (Closes #7361)
[youtube-dl] / youtube_dl / extractor / lynda.py
index 378117270439e7ce2669c46422f3df63caa33051..67f2025de8b0f2aa01108456da9e2443aa03f637 100644 (file)
@@ -82,6 +82,11 @@ class LyndaBaseIE(InfoExtractor):
                         expected=True)
             raise ExtractorError('Unable to log in')
 
+    def _logout(self):
+        self._download_webpage(
+            'http://www.lynda.com/ajax/logout.aspx', None,
+            'Logging out', 'Unable to log out', fatal=False)
+
 
 class LyndaIE(LyndaBaseIE):
     IE_NAME = 'lynda'
@@ -140,13 +145,14 @@ class LyndaIE(LyndaBaseIE):
 
         prioritized_streams = video_json.get('PrioritizedStreams')
         if prioritized_streams:
-            formats.extend([
-                {
-                    'url': video_url,
-                    'width': int_or_none(format_id),
-                    'format_id': format_id,
-                } for format_id, video_url in prioritized_streams['0'].items()
-            ])
+            for prioritized_stream_id, prioritized_stream in prioritized_streams.items():
+                formats.extend([
+                    {
+                        'url': video_url,
+                        'width': int_or_none(format_id),
+                        'format_id': '%s-%s' % (prioritized_stream_id, format_id),
+                    } for format_id, video_url in prioritized_stream.items()
+                ])
 
         self._check_formats(formats, video_id)
         self._sort_formats(formats)
@@ -209,6 +215,8 @@ class LyndaCourseIE(LyndaBaseIE):
             course_id, 'Downloading course JSON')
         course_json = json.loads(page)
 
+        self._logout()
+
         if 'Status' in course_json and course_json['Status'] == 'NotFound':
             raise ExtractorError(
                 'Course %s does not exist' % course_id, expected=True)