3 from .common
import InfoExtractor
13 class MicrosoftVirtualAcademyBaseIE(InfoExtractor
):
14 def _extract_base_url(self
, course_id
, display_id
):
15 return self
._download
_json
(
16 'https://api-mlxprod.microsoft.com/services/products/anonymous/%s' % course_id
,
17 display_id
, 'Downloading course base URL')
19 def _extract_chapter_and_title(self
, title
):
22 m
= re
.search(r
'(?P<chapter>\d+)\s*\|\s*(?P<title>.+)', title
)
23 return (int(m
.group('chapter')), m
.group('title')) if m
else (None, title
)
26 class MicrosoftVirtualAcademyIE(MicrosoftVirtualAcademyBaseIE
):
28 IE_DESC
= 'Microsoft Virtual Academy videos'
29 _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
32 'url': 'https://mva.microsoft.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788?l=gfVXISmEB_6804984382',
33 'md5': '7826c44fc31678b12ad8db11f6b5abb9',
35 'id': 'gfVXISmEB_6804984382',
37 'title': 'Course Introduction',
38 'formats': 'mincount:3',
46 'url': 'mva:11788:gfVXISmEB_6804984382',
47 'only_matching': True,
50 def _real_extract(self
, url
):
51 url
, smuggled_data
= unsmuggle_url(url
, {})
53 mobj
= self
._match
_valid
_url
(url
)
54 course_id
= mobj
.group('course_id')
55 video_id
= mobj
.group('id')
57 base_url
= smuggled_data
.get('base_url') or self
._extract
_base
_url
(course_id
, video_id
)
59 settings
= self
._download
_xml
(
60 '%s/content/content_%s/videosettings.xml?v=1' % (base_url
, video_id
),
61 video_id
, 'Downloading video settings XML')
63 _
, title
= self
._extract
_chapter
_and
_title
(xpath_text(
64 settings
, './/Title', 'title', fatal
=True))
68 for sources
in settings
.findall('.//MediaSources'):
69 sources_type
= sources
.get('videoType')
70 for source
in sources
.findall('./MediaSource'):
71 video_url
= source
.text
72 if not video_url
or not video_url
.startswith('http'):
74 if sources_type
== 'smoothstreaming':
75 formats
.extend(self
._extract
_ism
_formats
(
76 video_url
, video_id
, 'mss', fatal
=False))
78 video_mode
= source
.get('videoMode')
79 height
= int_or_none(self
._search
_regex
(
80 r
'^(\d+)[pP]$', video_mode
or '', 'height', default
=None))
81 codec
= source
.get('codec')
82 acodec
, vcodec
= [None] * 2
84 codecs
= codec
.split(',')
86 acodec
, vcodec
= codecs
87 elif len(codecs
) == 1:
91 'format_id': video_mode
,
98 for source
in settings
.findall('.//MarkerResourceSource'):
99 subtitle_url
= source
.text
102 subtitles
.setdefault('en', []).append({
103 'url': '%s/%s' % (base_url
, subtitle_url
),
104 'ext': source
.get('type'),
110 'subtitles': subtitles
,
115 class MicrosoftVirtualAcademyCourseIE(MicrosoftVirtualAcademyBaseIE
):
116 IE_NAME
= 'mva:course'
117 IE_DESC
= 'Microsoft Virtual Academy courses'
118 _VALID_URL
= r
'(?:%s:|https?://(?:mva\.microsoft|(?:www\.)?microsoftvirtualacademy)\.com/[^/]+/training-courses/(?P<display_id>[^/?#&]+)-)(?P<id>\d+)' % IE_NAME
121 'url': 'https://mva.microsoft.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788',
124 'title': 'Microsoft Azure Fundamentals: Virtual Machines',
126 'playlist_count': 36,
128 # with emphasized chapters
129 'url': 'https://mva.microsoft.com/en-US/training-courses/developing-windows-10-games-with-construct-2-16335',
132 'title': 'Developing Windows 10 Games with Construct 2',
134 'playlist_count': 10,
136 'url': 'https://www.microsoftvirtualacademy.com/en-US/training-courses/microsoft-azure-fundamentals-virtual-machines-11788',
137 'only_matching': True,
139 'url': 'mva:course:11788',
140 'only_matching': True,
144 def suitable(cls
, url
):
145 return False if MicrosoftVirtualAcademyIE
.suitable(url
) else super(
146 MicrosoftVirtualAcademyCourseIE
, cls
).suitable(url
)
148 def _real_extract(self
, url
):
149 mobj
= self
._match
_valid
_url
(url
)
150 course_id
= mobj
.group('id')
151 display_id
= mobj
.group('display_id')
153 base_url
= self
._extract
_base
_url
(course_id
, display_id
)
155 manifest
= self
._download
_json
(
156 '%s/imsmanifestlite.json' % base_url
,
157 display_id
, 'Downloading course manifest JSON')['manifest']
159 organization
= manifest
['organizations']['organization'][0]
162 for chapter
in organization
['item']:
163 chapter_number
, chapter_title
= self
._extract
_chapter
_and
_title
(chapter
.get('title'))
164 chapter_id
= chapter
.get('@identifier')
165 for item
in chapter
.get('item', []):
166 item_id
= item
.get('@identifier')
169 metadata
= item
.get('resource', {}).get('metadata') or {}
170 if metadata
.get('learningresourcetype') != 'Video':
172 _
, title
= self
._extract
_chapter
_and
_title
(item
.get('title'))
173 duration
= parse_duration(metadata
.get('duration'))
174 description
= metadata
.get('description')
176 '_type': 'url_transparent',
178 'mva:%s:%s' % (course_id
, item_id
), {'base_url': base_url}
),
180 'description': description
,
181 'duration': duration
,
182 'chapter': chapter_title
,
183 'chapter_number': chapter_number
,
184 'chapter_id': chapter_id
,
187 title
= organization
.get('title') or manifest
.get('metadata', {}).get('title')
189 return self
.playlist_result(entries
, course_id
, title
)