Repository: yt-dlp/yt-dlp

Issue:
TV 2's new video URLs cause "Unsupported URL"
### 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 broken site
- [X] I've verified that I'm running yt-dlp version **2022.09.01** ([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 all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [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)
- [X] 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 I'm willing to share it if required

### Region

_No response_

### Provide a description that is worded well enough to be understood

TV 2 Norway has introduced a new URL format, and it is not picked up by the extractor. Eg.:
[https://www.tv2.no/video/nyhetene/tv-2-hjelper-deg/saa-mye-kan-du-spare-paa-klesvasken/1787176/](https://www.tv2.no/video/nyhetene/tv-2-hjelper-deg/saa-mye-kan-du-spare-paa-klesvasken/1787176/)

But manually changing the URL back to the old format works:
[https://www.tv2.no/v/1787176/](https://www.tv2.no/v/1787176/)



### 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
[debug] Command-line config: ['https://www.tv2.no/video/sport/carlsen-ga-seg-etter-to-trekk-fullstendig-uakseptabel-oppfoersel/1788052/', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.09.01 [5d7c7d6] (pip)
[debug] Python 3.8.9 (CPython 64bit) - macOS-12.5.1-arm64-arm-64bit 
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.1 (setts)
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Loaded 1670 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.09.01, Current version: 2022.09.01
yt-dlp is up to date (2022.09.01)
[debug] [generic] Extracting URL: https://www.tv2.no/video/sport/carlsen-ga-seg-etter-to-trekk-fullstendig-uakseptabel-oppfoersel/1788052/
[generic] 1788052: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] 1788052: Extracting information
[debug] Looking for Brightcove embeds
[debug] Looking for embeds
WARNING: [generic] 1788052: Failed to parse JSON: Extra data: line 18 column 7 (char 876)
[debug] Identified a twitter:player iframe
[debug] [generic] Extracting URL: https://www.tv2.no/video/sport/carlsen-ga-seg-etter-to-trekk-fullstendig-uakseptabel-oppfoersel/1788052/?wf=ext
[generic] ?wf=ext: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] ?wf=ext: Extracting information
[debug] Looking for Brightcove embeds
[debug] Looking for embeds
WARNING: [generic] ?wf=ext: Failed to parse JSON: Extra data: line 18 column 7 (char 876)
ERROR: Unsupported URL: https://www.tv2.no/video/sport/carlsen-ga-seg-etter-to-trekk-fullstendig-uakseptabel-oppfoersel/1788052/?wf=ext
Traceback (most recent call last):
  File "/Users/krhah771/Library/Python/3.8/lib/python/site-packages/yt_dlp/YoutubeDL.py", line 1459, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/krhah771/Library/Python/3.8/lib/python/site-packages/yt_dlp/YoutubeDL.py", line 1535, in __extract_info
    ie_result = ie.extract(url)
  File "/Users/krhah771/Library/Python/3.8/lib/python/site-packages/yt_dlp/extractor/common.py", line 670, in extract
    ie_result = self._real_extract(url)
  File "/Users/krhah771/Library/Python/3.8/lib/python/site-packages/yt_dlp/extractor/generic.py", line 3078, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.tv2.no/video/sport/carlsen-ga-seg-etter-to-trekk-fullstendig-uakseptabel-oppfoersel/1788052/?wf=ext
```



Discussion:
Just changing the `_VALID_URL` pattern fixes this.

Is there any view as to whether the pattern `/video/category/subcat/item/id` (if my scarcely existent Norwegian is right) is always used? Do the new URLs have all these path components? Are there `/audio/...` URLs? And so on.

Also, the patterns for the TV2ArticleIE don't seem to be used now, but videos from a URL like https://www.tv2.no/mening_og_analyse/dette-er-ikke-laerernes-ansvar/15120661/ can be grabbed from the `assetId` inside a `TV2.TV2Video({...})` JS fragment. The IE's pattern should probably be extended to cover tv2.no pages not handled by TV2IE.
The old format,`tv2.no/v/[id]` is still in use, for example on [this overview page](https://www.tv2.no/v/)

It seems just `/video/category/id`is in use in some places, eg. [https://www.tv2.no/video/nyhetene/venter-paa-groent-lys-saa-skjer-dette/1790240/](https://www.tv2.no/video/nyhetene/venter-paa-groent-lys-saa-skjer-dette/1790240/).

And `/video/absolutely/anything/here/without/any/limits/id` works, so from what I can tell, just ignoring anything between `video`and `id` could be the safest option.

`/audio/...` is not a thing.

Resolving patch:
diff --git a/yt_dlp/extractor/tv2.py b/yt_dlp/extractor/tv2.py
--- a/yt_dlp/extractor/tv2.py
+++ b/yt_dlp/extractor/tv2.py
@@ -16,23 +16,27 @@
 
 
 class TV2IE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?tv2\.no/v\d*/(?P<id>\d+)'
+    _VALID_URL = r'https?://(?:www\.)?tv2\.no/v(?:ideo)?\d*/(?:[^?#]+/)*(?P<id>\d+)'
     _TESTS = [{
-        'url': 'http://www.tv2.no/v/916509/',
+        'url': 'http://www.tv2.no/v/1791207/',
         'info_dict': {
-            'id': '916509',
+            'id': '1791207',
             'ext': 'mp4',
-            'title': 'Se Frode Gryttens hyllest av Steven Gerrard',
-            'description': 'TV 2 Sportens huspoet tar avskjed med Liverpools kaptein Steven Gerrard.',
-            'timestamp': 1431715610,
-            'upload_date': '20150515',
-            'duration': 157,
+            'title': 'Her kolliderer romsonden med asteroiden ',
+            'description': 'En romsonde har krasjet inn i en asteroide i verdensrommet. Kollisjonen skjedde klokken 01:14 natt til tirsdag 27. september norsk tid. \n\nNasa kaller det sitt første forsøk på planetforsvar.',
+            'timestamp': 1664238190,
+            'upload_date': '20220927',
+            'duration': 146,
+            'thumbnail': r're:^https://.*$',
             'view_count': int,
             'categories': list,
         },
     }, {
         'url': 'http://www.tv2.no/v2/916509',
         'only_matching': True,
+    }, {
+        'url': 'https://www.tv2.no/video/nyhetene/her-kolliderer-romsonden-med-asteroiden/1791207/',
+        'only_matching': True,
     }]
     _PROTOCOLS = ('HLS', 'DASH')
     _GEO_COUNTRIES = ['NO']
@@ -114,13 +118,13 @@ def _real_extract(self, url):
 
 
 class TV2ArticleIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?tv2\.no/(?:a|\d{4}/\d{2}/\d{2}(/[^/]+)+)/(?P<id>\d+)'
+    _VALID_URL = r'https?://(?:www\.)?tv2\.no/(?!v(?:ideo)?\d*/)[^?#]+/(?P<id>\d+)'
     _TESTS = [{
-        'url': 'http://www.tv2.no/2015/05/16/nyheter/alesund/krim/pingvin/6930542',
+        'url': 'https://www.tv2.no/underholdning/forraeder/katarina-flatland-angrer-etter-forraeder-exit/15095188/',
         'info_dict': {
-            'id': '6930542',
-            'title': 'Russen hetses etter pingvintyveri - innrømmer å ha åpnet luken på buret',
-            'description': 'De fire siktede nekter fortsatt for å ha stjålet pingvinbabyene, men innrømmer å ha åpnet luken til de små kyllingene.',
+            'id': '15095188',
+            'title': 'Katarina Flatland angrer etter Forræder-exit',
+            'description': 'SANDEFJORD (TV 2): Katarina Flatland (33) måtte følge i sine fars fotspor, da hun ble forvist fra Forræder.',
         },
         'playlist_count': 2,
     }, {
@@ -138,7 +142,7 @@ def _real_extract(self, url):
 
         if not assets:
             # New embed pattern
-            for v in re.findall(r'(?s)TV2ContentboxVideo\(({.+?})\)', webpage):
+            for v in re.findall(r'(?s)(?:TV2ContentboxVideo|TV2\.TV2Video)\(({.+?})\)', webpage):
                 video = self._parse_json(
                     v, playlist_id, transform_source=js_to_json, fatal=False)
                 if not video:


Test patch: