1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class MicrosoftVirtualAcademyBaseIE(InfoExtractor
):
16 def _extract_base_url(self
, course_id
, display_id
):
17 return self
._download
_json
(
18 'https://api-mlxprod.microsoft.com/services/products/anonymous/%s' % course_id
,
19 display_id
, 'Downloading course base URL')
21 def _extract_chapter_and_title(self
, title
):
24 m
= re
.search(r
'(?P<chapter>\d+)\s*\|\s*(?P<title>.+)', title
)
25 return (int(m
.group('chapter')), m
.group('title')) if m
else (None, title
)
28 class MicrosoftVirtualAcademyIE(MicrosoftVirtualAcademyBaseIE
):
30 IE_DESC
= 'Microsoft Virtual Academy videos'
31 _VALID_URL
= r
'(?:%s:|https?://(?:mva\.microsoft|(?:www\.)?microsoftvirtualacademy)\.com/[^/]+/training-courses/[^/?#&]+-)(?P<course_id>\d+)(?::|\?l=)(?P<id>[\da-zA-Z]+_\d+)' % IE_NAME
34 'url': 'https://mva.microsoft.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788?l=gfVXISmEB_6804984382',
35 'md5': '7826c44fc31678b12ad8db11f6b5abb9',
37 'id': 'gfVXISmEB_6804984382',
39 'title': 'Course Introduction',
40 'formats': 'mincount:3',
48 'url': 'mva:11788:gfVXISmEB_6804984382',
49 'only_matching': True,
52 def _real_extract(self
, url
):
53 url
, smuggled_data
= unsmuggle_url(url
, {})
55 mobj
= self
._match
_valid
_url
(url
)
56 course_id
= mobj
.group('course_id')
57 video_id
= mobj
.group('id')
59 base_url
= smuggled_data
.get('base_url') or self
._extract
_base
_url
(course_id
, video_id
)
61 settings
= self
._download
_xml
(
62 '%s/content/content_%s/videosettings.xml?v=1' % (base_url
, video_id
),
63 video_id
, 'Downloading video settings XML')
65 _
, title
= self
._extract
_chapter
_and
_title
(xpath_text(
66 settings
, './/Title', 'title', fatal
=True))
70 for sources
in settings
.findall('.//MediaSources'):
71 sources_type
= sources
.get('videoType')
72 for source
in sources
.findall('./MediaSource'):
73 video_url
= source
.text
74 if not video_url
or not video_url
.startswith('http'):
76 if sources_type
== 'smoothstreaming':
77 formats
.extend(self
._extract
_ism
_formats
(
78 video_url
, video_id
, 'mss', fatal
=False))
80 video_mode
= source
.get('videoMode')
81 height
= int_or_none(self
._search
_regex
(
82 r
'^(\d+)[pP]$', video_mode
or '', 'height', default
=None))
83 codec
= source
.get('codec')
84 acodec
, vcodec
= [None] * 2
86 codecs
= codec
.split(',')
88 acodec
, vcodec
= codecs
89 elif len(codecs
) == 1:
93 'format_id': video_mode
,
98 self
._sort
_formats
(formats
)
101 for source
in settings
.findall('.//MarkerResourceSource'):
102 subtitle_url
= source
.text
105 subtitles
.setdefault('en', []).append({
106 'url': '%s/%s' % (base_url
, subtitle_url
),
107 'ext': source
.get('type'),
113 'subtitles': subtitles
,
118 class MicrosoftVirtualAcademyCourseIE(MicrosoftVirtualAcademyBaseIE
):
119 IE_NAME
= 'mva:course'
120 IE_DESC
= 'Microsoft Virtual Academy courses'
121 _VALID_URL
= r
'(?:%s:|https?://(?:mva\.microsoft|(?:www\.)?microsoftvirtualacademy)\.com/[^/]+/training-courses/(?P<display_id>[^/?#&]+)-)(?P<id>\d+)' % IE_NAME
124 'url': 'https://mva.microsoft.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788',
127 'title': 'Microsoft Azure Fundamentals: Virtual Machines',
129 'playlist_count': 36,
131 # with emphasized chapters
132 'url': 'https://mva.microsoft.com/en-US/training-courses/developing-windows-10-games-with-construct-2-16335',
135 'title': 'Developing Windows 10 Games with Construct 2',
137 'playlist_count': 10,
139 'url': 'https://www.microsoftvirtualacademy.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788',
140 'only_matching': True,
142 'url': 'mva:course:11788',
143 'only_matching': True,
147 def suitable(cls
, url
):
148 return False if MicrosoftVirtualAcademyIE
.suitable(url
) else super(
149 MicrosoftVirtualAcademyCourseIE
, cls
).suitable(url
)
151 def _real_extract(self
, url
):
152 mobj
= self
._match
_valid
_url
(url
)
153 course_id
= mobj
.group('id')
154 display_id
= mobj
.group('display_id')
156 base_url
= self
._extract
_base
_url
(course_id
, display_id
)
158 manifest
= self
._download
_json
(
159 '%s/imsmanifestlite.json' % base_url
,
160 display_id
, 'Downloading course manifest JSON')['manifest']
162 organization
= manifest
['organizations']['organization'][0]
165 for chapter
in organization
['item']:
166 chapter_number
, chapter_title
= self
._extract
_chapter
_and
_title
(chapter
.get('title'))
167 chapter_id
= chapter
.get('@identifier')
168 for item
in chapter
.get('item', []):
169 item_id
= item
.get('@identifier')
172 metadata
= item
.get('resource', {}).get('metadata') or {}
173 if metadata
.get('learningresourcetype') != 'Video':
175 _
, title
= self
._extract
_chapter
_and
_title
(item
.get('title'))
176 duration
= parse_duration(metadata
.get('duration'))
177 description
= metadata
.get('description')
179 '_type': 'url_transparent',
181 'mva:%s:%s' % (course_id
, item_id
), {'base_url': base_url}
),
183 'description': description
,
184 'duration': duration
,
185 'chapter': chapter_title
,
186 'chapter_number': chapter_number
,
187 'chapter_id': chapter_id
,
190 title
= organization
.get('title') or manifest
.get('metadata', {}).get('title')
192 return self
.playlist_result(entries
, course_id
, title
)