Repository: yt-dlp/yt-dlp

Issue:
Request support for swarenet.com
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a new site support request
- [X] I've verified that I'm running yt-dlp version **2022.10.04** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that none of provided URLs [violate any copyrights](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy) 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

united states/canada

### Example URLs
https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1

### Provide a description that is worded well enough to be understood

I dont know about DRM but can we add support for this site. is it DRM protected? I have an account

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
C:\Users\Laptop\Desktop>ytd -vU https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1
[debug] Command-line config: ['-vU', 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.10.04 [4e0511f] (win32_exe)
[debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22623-SP0
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 2022-10-06-git-2c2aaa5bd0-full_build-www.gyan.dev (setts), ffprobe 2022-10-06-git-2c2aaa5bd0-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.09.24, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Loaded 1690 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.10.04, Current version: 2022.10.04
yt-dlp is up to date (2022.10.04)
[debug] [generic] Extracting URL: https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1
[generic] 1: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] 1: Extracting information
[debug] Looking for Brightcove embeds
[debug] Looking for embeds
ERROR: Unsupported URL: https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 1477, in wrapper
  File "yt_dlp\YoutubeDL.py", line 1553, in __extract_info
  File "yt_dlp\extractor\common.py", line 672, in extract
  File "yt_dlp\extractor\generic.py", line 3062, in _real_extract
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1




C:\Users\Laptop\Desktop>
```



Discussion:
This site is using `vidyard` player. We can extract the video from `externalid` in webpage
```html
<script>
                    var videoheight = $('.video_embed').height();
                    var videowidth = $('.video_embed').width();
                    var externalid = "wicK2EOzjOdxkUXGDIgcPw";
                    var videourl = "//play.vidyard.com/" + externalid + ".js?v=4&type=inline&height=" + videoheight + "&width=" + videowidth;
                    $(document).ready(function() {
                      var videoplayer = document.createElement('script');
                      videoplayer.type = 'text/javascript';
                      videoplayer.id = 'vidyard_embed_code_' + externalid;
                      videoplayer.src = videourl;
                      document.getElementsByClassName('video_embed')[0].appendChild(videoplayer);
                    });
                  </script>
```
and then we can request to `https://play.vidyard.com/player/<externalid>.json` to get json data. And then from json data, we can get most of relevant information at `json_data['chapters']`. The video is in `json_data['chapters']['sources']`

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
@@ -1739,6 +1739,7 @@
     SVTPlayIE,
     SVTSeriesIE,
 )
+from .swearnet import SwearnetEpisodeIE
 from .swrmediathek import SWRMediathekIE
 from .syvdk import SYVDKIE
 from .syfy import SyfyIE
diff --git a/yt_dlp/extractor/swearnet.py b/yt_dlp/extractor/swearnet.py
new file mode 100644
--- /dev/null
+++ b/yt_dlp/extractor/swearnet.py
@@ -0,0 +1,73 @@
+from .common import InfoExtractor
+from ..utils import int_or_none, traverse_obj
+
+
+class SwearnetEpisodeIE(InfoExtractor):
+    _VALID_URL = r'https?://www\.swearnet\.com/shows/(?P<id>[\w-]+)/seasons/(?P<season_num>\d+)/episodes/(?P<episode_num>\d+)'
+    _TESTS = [{
+        'url': 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1',
+        'info_dict': {
+            'id': '232819',
+            'ext': 'mp4',
+            'episode_number': 1,
+            'episode': 'Episode 1',
+            'duration': 719,
+            'description': 'md5:c48ef71440ce466284c07085cd7bd761',
+            'season': 'Season 1',
+            'title': 'Episode 1 - Grilled Cheese Sammich',
+            'season_number': 1,
+            'thumbnail': 'https://cdn.vidyard.com/thumbnails/232819/_RX04IKIq60a2V6rIRqq_Q_small.jpg',
+        }
+    }]
+
+    def _get_formats_and_subtitle(self, video_source, video_id):
+        video_source = video_source or {}
+        formats, subtitles = [], {}
+        for key, value in video_source.items():
+            if key == 'hls':
+                for video_hls in value:
+                    fmts, subs = self._extract_m3u8_formats_and_subtitles(video_hls.get('url'), video_id)
+                    formats.extend(fmts)
+                    self._merge_subtitles(subs, target=subtitles)
+            else:
+                formats.extend({
+                    'url': video_mp4.get('url'),
+                    'ext': 'mp4'
+                } for video_mp4 in value)
+
+        return formats, subtitles
+
+    def _get_direct_subtitle(self, caption_json):
+        subs = {}
+        for caption in caption_json:
+            subs.setdefault(caption.get('language') or 'und', []).append({
+                'url': caption.get('vttUrl'),
+                'name': caption.get('name')
+            })
+
+        return subs
+
+    def _real_extract(self, url):
+        display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
+        webpage = self._download_webpage(url, display_id)
+
+        external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
+        json_data = self._download_json(
+            f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]
+
+        formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
+        self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles)
+
+        return {
+            'id': str(json_data['videoId']),
+            'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
+            'description': (json_data.get('description')
+                            or self._html_search_meta(['og:description', 'twitter:description'])),
+            'duration': int_or_none(json_data.get('seconds')),
+            'formats': formats,
+            'subtitles': subtitles,
+            'season_number': int_or_none(season_number),
+            'episode_number': int_or_none(episode_number),
+            'thumbnails': [{'url': thumbnail_url}
+                           for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]
+        }


Test patch: