Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GoPro extractor. #9019

Merged
merged 5 commits into from Jan 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions yt_dlp/extractor/gopro.py
Expand Up @@ -3,12 +3,20 @@
int_or_none,
remove_end,
str_or_none,
strip_or_none,
try_get,
unified_timestamp,
url_or_none,
)


# gopro.com returns empty string as author/track for some video. Treat it as
# if it were null.
def nonempty_or_none(s):
v = strip_or_none(s)
return None if v == '' else v


class GoProIE(InfoExtractor):
_VALID_URL = r'https?://(www\.)?gopro\.com/v/(?P<id>[A-Za-z0-9]+)'

Expand Down Expand Up @@ -57,8 +65,8 @@ def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)

metadata = self._parse_json(
self._html_search_regex(r'window\.__reflectData\s*=\s*([^;]+)', webpage, 'metadata'), video_id)
metadata = self._search_json(r'<script>window\.__reflectData\s*=',
webpage, 'metadata', video_id)

video_info = metadata['collectionMedia'][0]
media_data = self._download_json(
Expand Down Expand Up @@ -98,8 +106,8 @@ def _real_extract(self, url):
try_get(metadata, lambda x: x['account']['nickname'])),
'duration': int_or_none(
video_info.get('source_duration')),
'artist': str_or_none(
'artist': nonempty_or_none(
video_info.get('music_track_artist')),
'track': str_or_none(
'track': nonempty_or_none(
video_info.get('music_track_name')),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just do:

            'artist': str_or_none(
                video_info.get('music_track_artist')) or None,
            'track': str_or_none(
                video_info.get('music_track_name')) or None,

}