Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/parlview.py (Python)

Code before:
            try:
                time_parts = duration_str.split(':')
                if len(time_parts) >= 3:
                    hours = int(time_parts[0])
                    minutes = int(time_parts[1])
                    seconds = int(time_parts[2])
                    duration = hours * 3600 + minutes * 60 + seconds
            except (ValueError, IndexError):
                pass

        # Parse upload date from recordingFrom
        upload_date = None
        recording_from = video_details.get('recordingFrom')
        if recording_from:
            upload_date = unified_timestamp(recording_from)

        return {
            'id': video_id,
            'title': video_details.get('parlViewTitle') or video_details.get('title'),
            'description': video_details.get('parlViewDescription'),
            'formats': formats,
            'duration': duration,
            'timestamp': upload_date,
            'uploader': 'Australian Parliament House',
            'thumbnail': video_details.get('thumbUrl'),
            'series': f"{video_details.get('eventGroup')} - {video_details.get('eventSubGroup')}" if video_details.get('eventGroup') and video_details.get('eventSubGroup') else None,
        }


Review comment (refactor):
Roll above extraction into the return value (with appropriate imports):
```suggestion
            'formats': formats,
            'uploader': 'Australian Parliament House',
            ** traverse_obj(video_details, {
                'title': (('parlViewTitle', 'title'), {str}, any),
                'description': ('parlViewDescription', {str}),
                # Parse duration from duration string (format: "HH:MM:SS:FF", ignoring FF)
                'duration': ('files', 'file', 'duration', {lambda s: ':'.join((s or '').split(':')[:3])}, {parse_duration}),
                'timestamp': ('recordingFrom', {unified_timestamp}),
                'thumbnail': ('thumbUrl', {url_or_none}),
                'series': (None, {lambda vd: join_nonempty('eventGroup', 'eventSubGroup', delim=' - ', from_dict=vd)}),
            }),
```

Code after:
import re

from .common import InfoExtractor
from ..utils import parse_duration, parse_iso8601, url_or_none
from ..utils.traversal import traverse_obj


class ParlviewIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?aph\.gov\.au/News_and_Events/Watch_Read_Listen/ParlView/video/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://www.aph.gov.au/News_and_Events/Watch_Read_Listen/ParlView/video/3406614',
        'info_dict': {
            'id': '3406614',
            'ext': 'mp4',
            'title': 'Senate Chamber',
            'description': 'Official Recording of Senate Proceedings from the Australian Parliament',
            'thumbnail': 'https://aphbroadcasting-prod.z01.azurefd.net/vod-storage/vod-logos/SenateParlview06.jpg',
            'upload_date': '20250325',
            'duration': 17999,
            'timestamp': 1742939400,
        },
        'params': {
            'skip_download': True,
        },
    }, {
        'url': 'https://www.aph.gov.au/News_and_Events/Watch_Read_Listen/ParlView/video/SV1394.dv',
        'info_dict': {
            'id': 'SV1394.dv',
            'ext': 'mp4',
            'title': 'Senate Select Committee on Uranium Mining and Milling [Part 1]',
            'description': 'Official Recording of Senate Committee Proceedings from the Australian Parliament',
            'thumbnail': 'https://aphbroadcasting-prod.z01.azurefd.net/vod-storage/vod-logos/CommitteeThumbnail06.jpg',
            'upload_date': '19960822',
            'duration': 14765,
            'timestamp': 840754200,
        },
        'params': {
            'skip_download': True,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_details = self._download_json(
            f'https://vodapi.aph.gov.au/api/search/parlview/{video_id}', video_id)['videoDetails']

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            video_details['files']['file']['url'], video_id, 'mp4')

        DURATION_RE = re.compile(r'(?P<duration>\d+:\d+:\d+):\d+')

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(video_details, {
                'title': (('parlViewTitle', 'title'), {str}, any),
                'description': ('parlViewDescription', {str}),
                'duration': ('files', 'file', 'duration', {DURATION_RE.fullmatch}, 'duration', {parse_duration}),
                'timestamp': ('recordingFrom', {parse_iso8601}),
                'thumbnail': ('thumbUrl', {url_or_none}),
            }),
        }