Repository: yt-dlp/yt-dlp

Issue:
[youtube] Extract duration from upcoming premieres
### 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 requesting a site-specific feature
- [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 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 I'm willing to share it if required

### Region

_No response_

### Example URLs

https://www.youtube.com/watch?v=AtwcZeFLvpI

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

Premieres on YouTube are uploads thus have a predetermined duration, however we do not extract this duration when we scrape the video's metadata.

We can get the duration from the video details (a value called "duration") or from the microformat (a value called "lengthSeconds").

We should return this value as the duration in the resultant metainfo, rather than omitting it.

### 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: ['-vU', 'https://www.youtube.com/watch?v=AtwcZeFLvpI', '-s', '--ignore-no-f', '--print', '%(duration)s']
[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.10.04 [4e0511f] (pip) API
[debug] Python 3.10.8 (CPython 64bit) - Linux-5.15.74-1-lts-x86_64-with-glibc2.36 (glibc 2.36)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.1.2 (setts), ffprobe 5.1.2, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.12.0, brotlicffi-1.0.9.2, certifi-2022.09.24, mutagen-1.45.1, secretstorage-3.3.2, sqlite3-2.6.0, websockets-10.1
[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] [youtube] Extracting URL: https://www.youtube.com/watch?v=AtwcZeFLvpI
[youtube] AtwcZeFLvpI: Downloading webpage
[youtube] AtwcZeFLvpI: Downloading android player API JSON
WARNING: [youtube] Premieres in 19 hours
WARNING: No video formats found!
[debug] Default format spec: bestvideo*+bestaudio/best
WARNING: Requested format is not available
NA
```



Discussion:
> We can get the duration from the video details (a value called "duration") or from the microformat (a value called "lengthSeconds").

I havent checked it, but sounds like an easy fix. Can u make a PR?

Resolving patch:
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -3787,10 +3787,9 @@ def feed_entry(name):
                 return self.playlist_result(
                     entries, video_id, video_title, video_description)
 
-        duration = int_or_none(
-            get_first(video_details, 'lengthSeconds')
-            or get_first(microformats, 'lengthSeconds')
-            or parse_duration(search_meta('duration'))) or None
+        duration = (int_or_none(get_first(video_details, 'lengthSeconds'))
+                    or int_or_none(get_first(microformats, 'lengthSeconds'))
+                    or parse_duration(search_meta('duration')) or None)
 
         live_broadcast_details, live_status, streaming_data, formats, automatic_captions = \
             self._list_formats(video_id, microformats, video_details, player_responses, player_url, duration)


Test patch: