[tv5mondeplus] fix extractor
diff --git a/yt_dlp/extractor/tv5mondeplus.py b/yt_dlp/extractor/tv5mondeplus.py
index bd0be784d29..4da1b26d1a4 100644
--- a/yt_dlp/extractor/tv5mondeplus.py
+++ b/yt_dlp/extractor/tv5mondeplus.py
@@ -1,10 +1,14 @@
+import urllib.parse
+
 from .common import InfoExtractor
 from ..utils import (
     determine_ext,
     extract_attributes,
     int_or_none,
     parse_duration,
+    traverse_obj,
     try_get,
+    url_or_none,
 )
 
 
@@ -12,6 +16,36 @@ class TV5MondePlusIE(InfoExtractor):
     IE_DESC = 'TV5MONDE+'
     _VALID_URL = r'https?://(?:www\.)?(?:tv5mondeplus|revoir\.tv5monde)\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
     _TESTS = [{
+        # movie
+        'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/les-novices',
+        'md5': 'c86f60bf8b75436455b1b205f9745955',
+        'info_dict': {
+            'id': 'ZX0ipMyFQq_6D4BA7b',
+            'display_id': 'les-novices',
+            'ext': 'mp4',
+            'title': 'Les novices',
+            'description': 'md5:2e7c33ba3ad48dabfcc2a956b88bde2b',
+            'upload_date': '20230821',
+            'thumbnail': 'https://revoir.tv5monde.com/uploads/media/video_thumbnail/0738/60/01e952b7ccf36b7c6007ec9131588954ab651de9.jpeg',
+            'duration': 5177,
+            'episode': 'Les novices',
+        },
+    }, {
+        # series episode
+        'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/opj-les-dents-de-la-terre-2',
+        'info_dict': {
+            'id': 'wJ0eeEPozr_6D4BA7b',
+            'display_id': 'opj-les-dents-de-la-terre-2',
+            'ext': 'mp4',
+            'title': "OPJ - Les dents de la Terre (2)",
+            'description': 'md5:288f87fd68d993f814e66e60e5302d9d',
+            'upload_date': '20230823',
+            'series': 'OPJ',
+            'episode': 'Les dents de la Terre (2)',
+            'duration': 2877,
+            'thumbnail': 'https://dl-revoir.tv5monde.com/images/1a/5753448.jpg'
+        },
+    }, {
         # movie
         'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/ceux-qui-travaillent',
         'md5': '32fa0cde16a4480d1251502a66856d5f',
@@ -23,6 +57,7 @@ class TV5MondePlusIE(InfoExtractor):
             'description': 'md5:570e8bb688036ace873b2d50d24c026d',
             'upload_date': '20210819',
         },
+        'skip': 'no longer available',
     }, {
         # series episode
         'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/vestiaires-caro-actrice',
@@ -39,6 +74,7 @@ class TV5MondePlusIE(InfoExtractor):
         'params': {
             'skip_download': True,
         },
+        'skip': 'no longer available',
     }, {
         'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/neuf-jours-en-hiver-neuf-jours-en-hiver',
         'only_matching': True,
@@ -63,20 +99,45 @@ def _real_extract(self, url):
         video_files = self._parse_json(
             vpl_data['data-broadcast'], display_id)
         formats = []
-        for video_file in video_files:
-            v_url = video_file.get('url')
-            if not v_url:
-                continue
-            video_format = video_file.get('format') or determine_ext(v_url)
-            if video_format == 'm3u8':
-                formats.extend(self._extract_m3u8_formats(
-                    v_url, display_id, 'mp4', 'm3u8_native',
-                    m3u8_id='hls', fatal=False))
-            else:
-                formats.append({
-                    'url': v_url,
-                    'format_id': video_format,
-                })
+        video_id = None
+
+        def process_video_files(v):
+            nonlocal video_id
+            for video_file in v:
+                v_url = video_file.get('url')
+                if not v_url:
+                    continue
+                if video_file.get('type') == 'application/deferred':
+                    d_param = urllib.parse.quote(v_url)
+                    token = video_file.get('token')
+                    if not token:
+                        continue
+                    deferred_json = self._download_json(
+                        f'https://api.tv5monde.com/player/asset/{d_param}/resolve?condenseKS=true', display_id,
+                        note='Downloading deferred info', headers={'Authorization': f'Bearer {token}'}, fatal=False)
+                    v_url = traverse_obj(deferred_json, (0, 'url', {url_or_none}))
+                    if not v_url:
+                        continue
+                    # data-guid from the webpage isn't stable, use the material id from the json urls
+                    video_id = self._search_regex(
+                        r'materials/([\da-zA-Z]{10}_[\da-fA-F]{7})/', v_url, 'video id', default=None)
+                    process_video_files(deferred_json)
+
+                video_format = video_file.get('format') or determine_ext(v_url)
+                if video_format == 'm3u8':
+                    formats.extend(self._extract_m3u8_formats(
+                        v_url, display_id, 'mp4', 'm3u8_native',
+                        m3u8_id='hls', fatal=False))
+                elif video_format == 'mpd':
+                    formats.extend(self._extract_mpd_formats(
+                        v_url, display_id, fatal=False))
+                else:
+                    formats.append({
+                        'url': v_url,
+                        'format_id': video_format,
+                    })
+
+        process_video_files(video_files)
 
         metadata = self._parse_json(
             vpl_data['data-metadata'], display_id)
@@ -100,10 +161,11 @@ def _real_extract(self, url):
         if upload_date:
             upload_date = upload_date.replace('_', '')
 
-        video_id = self._search_regex(
-            (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
-             r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
-            default=display_id)
+        if not video_id:
+            video_id = self._search_regex(
+                (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
+                 r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
+                default=display_id)
 
         return {
             'id': video_id,

### Description of your *pull request* and other information

<!--

Explanation of your *pull request* in arbitrary form goes here. Please **make sure the description explains the purpose and effect** of your *pull request* and is worded well enough to be understood. Provide as much **context and examples** as possible

-->

tv5monde added a video type, which might imply a deferred json info download, to get a m3u8 URL.
Two tests updated.

FIxes #4978 

<details open><summary>Template</summary> <!-- OPEN is intentional -->

<!--

# PLEASE FOLLOW THE GUIDE BELOW

- You will be asked some questions, please read them **carefully** and answer honestly
- Put an `x` into all the boxes `[ ]` relevant to your *pull request* (like [x])
- Use *Preview* tab to see how your *pull request* will actually look like

-->

### Before submitting a *pull request* make sure you have:
- [x] At least skimmed through [contributing guidelines](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions) including [yt-dlp coding conventions](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#yt-dlp-coding-conventions)
- [x] [Searched](https://github.com/yt-dlp/yt-dlp/search?q=is%3Apr&type=Issues) the bugtracker for similar pull requests
- [x] Checked the code with [flake8](https://pypi.python.org/pypi/flake8) and [ran relevant tests](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions)

### In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under [Unlicense](http://unlicense.org/). Check all of the following options that apply:
- [x] I am the original author of this code and I am willing to release it under [Unlicense](http://unlicense.org/)
- [ ] I am not the original author of this code but it is in public domain or released under [Unlicense](http://unlicense.org/) (provide reliable evidence)

### What is the purpose of your *pull request*?
- [x] Fix or improvement to an extractor (Make sure to add/update tests)
- [ ] New extractor ([Piracy websites will not be accepted](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy))
- [ ] Core bug fix/improvement
- [ ] New feature (It is strongly [recommended to open an issue first](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#adding-new-feature-or-making-overarching-changes))


<!-- Do NOT edit/remove anything below this! -->
</details><details><summary>Copilot Summary</summary>  

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at eaeee05</samp>

### Summary
🛠️📺✅

<!--
1.  🛠️ - This emoji represents fixing or improving something, and can be used for the improved extractor and the bug fix with missing video id.
2.  📺 - This emoji represents television or video content, and can be used for the `tv5mondeplus` extractor and the deferred videos feature.
3.  ✅ - This emoji represents testing or verifying something, and can be used for the updated test cases.
-->
Improved and fixed `tv5mondeplus` extractor. The extractor can now handle deferred videos and has more robust test cases. A potential issue with missing video id was also resolved.

> _Sing, O Muse, of the skillful coder who improved the extractor_
> _Of tv5mondeplus, the splendid channel of the Francophone world_
> _He made it work for deferred videos, those that wait for their hour_
> _And updated the tests, `test_generic` and `test_tv5mondeplus`_

### Walkthrough
* Import `urllib.parse` module to encode URL parameter for deferred videos ([link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45R1-R2))
* Modify extractor to handle deferred videos by making an additional API call with token and parameter from original video file ([link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45L68-R88))
* Extract video id from resolved URL if not available from webpage ([link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45L68-R88), [link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45L103-R126))
* Check if video id is assigned before using it in API call to avoid error ([link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45L103-R126))
* Update test cases to use more recent and available videos and include more metadata fields ([link](https://github.com/yt-dlp/yt-dlp/pull/7952/files?diff=unified&w=0#diff-578b2a642fb1a755e68f970db0179c676cb9837780daed3db3d6c1d0655fed45L16-R44))



</details>
