Repository: yt-dlp/yt-dlp

Issue:
Support for Telegram channels (t.me)
### Checklist

- [X] I'm reporting a new site support request
- [X] I've verified that I'm running yt-dlp version **2022.02.04**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that none of provided URLs [violate any copyrights](https://github.com/ytdl-org/youtube-dl#can-you-add-support-for-this-anime-video-site-or-site-which-shows-current-movies-for-free) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required

### Region

World

### Example URLs

- Single video: https://t.me/europa_press/613

### Description

Most content in Telegram channels, including videos that aren't too big, can be accessed directly via browser from URLs. So it would be interesting to be able to download them with `yt-dlp`.

It was suggested to use the "context" view, i.e. the URL in this form: https://t.me/s/europa_press/613. However, the `generic` extractor downloads a playlist of several videos, and not the specific video. Moreover, with this method, `yt-dlp` does not retrieve the metadata (there are on Telegram most of the time, including the date of creation of the video).

### Verbose log

```shell
[debug] Command-line config: ['-vU', 'https://t.me/europa_press/613']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, err utf-8, pref cp1252
[debug] yt-dlp version 2022.02.04 [c1653e9] (win_exe)
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.19042-SP0
[debug] exe versions: ffmpeg 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev (setts), ffprobe 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2022.02.04, Current version: 2022.02.04
yt-dlp is up to date (2022.02.04)
[debug] [generic] Extracting URL: https://t.me/europa_press/613
[generic] 613: Requesting header
WARNING: [generic] Could not send HEAD request to https://t.me/europa_press/613: HTTP Error 501: Not Implemented
[generic] 613: Downloading webpage
WARNING: [generic] Falling back on generic information extractor.
[generic] 613: Extracting information
[debug] Looking for video embeds
ERROR: Unsupported URL: https://t.me/europa_press/613
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 1381, in wrapper
  File "yt_dlp\YoutubeDL.py", line 1451, in __extract_info
  File "yt_dlp\extractor\common.py", line 612, in extract
  File "yt_dlp\extractor\generic.py", line 3986, in _real_extract
yt_dlp.utils.UnsupportedError: Unsupported URL: https://t.me/europa_press/613
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -1587,6 +1587,7 @@
 from .telebruxelles import TeleBruxellesIE
 from .telecinco import TelecincoIE
 from .telegraaf import TelegraafIE
+from .telegram import TelegramEmbedIE
 from .telemb import TeleMBIE
 from .telemundo import TelemundoIE
 from .telequebec import (
diff --git a/yt_dlp/extractor/telegram.py b/yt_dlp/extractor/telegram.py
new file mode 100644
--- /dev/null
+++ b/yt_dlp/extractor/telegram.py
@@ -0,0 +1,37 @@
+from .common import InfoExtractor
+
+
+class TelegramEmbedIE(InfoExtractor):
+    IE_NAME = 'telegram:embed'
+    _VALID_URL = r'https?://t\.me/(?P<channel_name>[^/]+)/(?P<id>\d+)'
+    _TESTS = [{
+        'url': 'https://t.me/europa_press/613',
+        'info_dict': {
+            'id': '613',
+            'ext': 'mp4',
+            'title': 'Europa Press',
+            'description': '6ce2d7e8d56eda16d80607b23db7b252',
+            'thumbnail': r're:^https?:\/\/cdn.*?telesco\.pe\/file\/\w+',
+        },
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+        webpage = self._download_webpage(url, video_id)
+        webpage_embed = self._download_webpage(f'{url}?embed=1', video_id)
+
+        formats = [{
+            'url': self._proto_relative_url(self._search_regex(
+                '<video[^>]+src="([^"]+)"', webpage_embed, 'source')),
+            'ext': 'mp4',
+        }]
+        self._sort_formats(formats)
+
+        return {
+            'id': video_id,
+            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage, fatal=True),
+            'description': self._html_search_meta(['og:description', 'twitter:description'], webpage, fatal=True),
+            'thumbnail': self._search_regex(r'tgme_widget_message_video_thumb"[^>]+background-image:url\(\'([^\']+)\'\)',
+                                            webpage_embed, 'thumbnail'),
+            'formats': formats,
+        }


Test patch: