diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 10c12b87a1..c46d122ffa 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -540,6 +540,7 @@ - **natgeo:video** - **NationalGeographicTV** - **Naver** + - **Naver:live** - **NBA** - **NBC** - **NBCNews** @@ -976,6 +977,7 @@ - **twitter:amplify** - **twitter:broadcast** - **twitter:card** + - **twitter:shortener** - **udemy** - **udemy:course** - **UDNEmbed**: 聯合影音 diff --git a/youtube_dlc/extractor/extractors.py b/youtube_dlc/extractor/extractors.py index f0860e04dc..d31edd7c87 100644 --- a/youtube_dlc/extractor/extractors.py +++ b/youtube_dlc/extractor/extractors.py @@ -1268,6 +1268,7 @@ from .twitter import ( TwitterIE, TwitterAmplifyIE, TwitterBroadcastIE, + TwitterShortenerIE, ) from .udemy import ( UdemyIE, diff --git a/youtube_dlc/extractor/twitter.py b/youtube_dlc/extractor/twitter.py index 4284487db4..ca5e040c6a 100644 --- a/youtube_dlc/extractor/twitter.py +++ b/youtube_dlc/extractor/twitter.py @@ -608,3 +608,21 @@ class TwitterBroadcastIE(TwitterBaseIE, PeriscopeBaseIE): info['formats'] = self._extract_pscp_m3u8_formats( m3u8_url, broadcast_id, m3u8_id, state, width, height) return info + + +class TwitterShortenerIE(TwitterBaseIE): + IE_NAME = 'twitter:shortener' + _VALID_URL = r'https?://t.co/(?P[^?]+)|tco:(?P[^?]+)' + _BASE_URL = 'https://t.co/' + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + eid, id = mobj.group('eid', 'id') + if eid: + id = eid + url = self._BASE_URL + id + new_url = self._request_webpage(url, id, headers={'User-Agent': 'curl'}).geturl() + __UNSAFE_LINK = "https://twitter.com/safety/unsafe_link_warning?unsafe_link=" + if new_url.startswith(__UNSAFE_LINK): + new_url = new_url.replace(__UNSAFE_LINK, "") + return self.url_result(new_url)