]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/gopro.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / gopro.py
index 10cc1aec1db3b25d14d3285861161e58c018c16e..9142566c35d00c78500a8acc2277f89aeb7e4f70 100644 (file)
@@ -1,6 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 from .common import InfoExtractor
 from ..utils import (
     int_or_none,
@@ -26,7 +23,7 @@ class GoProIE(InfoExtractor):
             'upload_date': '20210919',
             'uploader_id': 'fireydive30018',
             'duration': 396062,
-        }
+        },
     }, {
         'url': 'https://gopro.com/v/KRm6Vgp2peg4e',
         'info_dict': {
@@ -39,7 +36,7 @@ class GoProIE(InfoExtractor):
             'uploader_id': 'dc9bcb8b-47d2-47c6-afbc-4c48f9a3769e',
             'duration': 45187,
             'track': 'The Sky Machine',
-        }
+        },
     }, {
         'url': 'https://gopro.com/v/kVrK9wlJvBMwn',
         'info_dict': {
@@ -53,19 +50,19 @@ class GoProIE(InfoExtractor):
             'duration': 313075,
             'track': 'Battery (Live)',
             'artist': 'Metallica',
-        }
+        },
     }]
 
     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'window\.__reflectData\s*=', webpage, 'metadata', video_id)
 
         video_info = metadata['collectionMedia'][0]
         media_data = self._download_json(
-            'https://api.gopro.com/media/%s/download' % video_info['id'], video_id)
+            'https://api.gopro.com/media/{}/download'.format(video_info['id']), video_id)
 
         formats = []
         for fmt in try_get(media_data, lambda x: x['_embedded']['variations']) or []:
@@ -81,8 +78,6 @@ def _real_extract(self, url):
                 'height': int_or_none(fmt.get('height')),
             })
 
-        self._sort_formats(formats)
-
         title = str_or_none(
             try_get(metadata, lambda x: x['collection']['title'])
             or self._html_search_meta(['og:title', 'twitter:title'], webpage)
@@ -104,7 +99,7 @@ def _real_extract(self, url):
             'duration': int_or_none(
                 video_info.get('source_duration')),
             'artist': str_or_none(
-                video_info.get('music_track_artist')),
+                video_info.get('music_track_artist')) or None,
             'track': str_or_none(
-                video_info.get('music_track_name')),
+                video_info.get('music_track_name')) or None,
         }