Skip to content

Commit fc08bdd

Browse files
committed
[extractor] Allow non-fatal title extraction
1 parent 2568d41 commit fc08bdd

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ For extraction to work yt-dlp relies on metadata your extractor extracts and pro
252252
- `title` (media title)
253253
- `url` (media download URL) or `formats`
254254

255-
The aforementioned metafields are the critical data that the extraction does not make any sense without and if any of them fail to be extracted then the extractor is considered completely broken. While, in fact, only `id` is technically mandatory, due to compatibility reasons, yt-dlp also treats `title` as mandatory. The extractor is allowed to return the info dict without url or formats in some special cases if it allows the user to extract usefull information with `--ignore-no-formats-error` - Eg: when the video is a live stream that has not started yet.
255+
The aforementioned metafields are the critical data that the extraction does not make any sense without and if any of them fail to be extracted then the extractor is considered completely broken. While all extractors must return a `title`, they must also allow it's extraction to be non-fatal.
256+
257+
The extractor is allowed to return the info dict without url or formats in some special cases if it allows the user to extract usefull information with `--ignore-no-formats-error` - Eg: when the video is a live stream that has not started yet.
256258

257259
[Any field](yt_dlp/extractor/common.py#219-L426) apart from the aforementioned ones are considered **optional**. That means that extraction should be **tolerant** to situations when sources for these fields can potentially be unavailable (even if they are always available at the moment) and **future-proof** in order not to break the extraction of general purpose mandatory fields.
258260

yt_dlp/YoutubeDL.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,10 +2299,15 @@ def process_video_result(self, info_dict, download=True):
22992299
self._num_videos += 1
23002300

23012301
if 'id' not in info_dict:
2302-
raise ExtractorError('Missing "id" field in extractor result')
2302+
raise ExtractorError('Missing "id" field in extractor result', ie=info_dict['extractor'])
2303+
elif not info_dict.get('id'):
2304+
raise ExtractorError('Extractor failed to obtain "id"', ie=info_dict['extractor'])
23032305
if 'title' not in info_dict:
23042306
raise ExtractorError('Missing "title" field in extractor result',
23052307
video_id=info_dict['id'], ie=info_dict['extractor'])
2308+
elif not info_dict.get('title'):
2309+
self.report_warning('Extractor failed to obtain "title". Creating a generic title instead')
2310+
info_dict['title'] = f'{info_dict["extractor"]} video #{info_dict["id"]}'
23062311

23072312
def report_force_conversion(field, field_not, conversion):
23082313
self.report_warning(

yt_dlp/extractor/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ def _og_search_description(self, html, **kargs):
12911291
return self._og_search_property('description', html, fatal=False, **kargs)
12921292

12931293
def _og_search_title(self, html, **kargs):
1294-
return self._og_search_property('title', html, **kargs)
1294+
return self._og_search_property('title', html, fatal=False, **kargs)
12951295

12961296
def _og_search_video_url(self, html, name='video url', secure=True, **kargs):
12971297
regexes = self._og_regexes('video') + self._og_regexes('video:url')

0 commit comments

Comments
 (0)