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

Code before:
            query.update({
                'videoSlug': video_slug,
                'resolution': '_%s' % resolution,
            })
            sub = ' %dp' % resolution
        api_url = 'https://www.linkedin.com/learning-api/detailedCourses'
        if not self._get_cookies(api_url).get('JSESSIONID'):
            self.raise_login_required()
        return self._download_json(
            api_url, video_slug, 'Downloading%s JSON metadata' % sub, headers={
                'Csrf-Token': self._get_cookies(api_url)['JSESSIONID'].value,
            }, query=query)['elements'][0]

    def _get_urn_id(self, video_data):
        urn = video_data.get('urn')
        if urn:
            mobj = re.search(r'urn:li:lyndaCourse:\d+,(\d+)', urn)
            if mobj:
                return mobj.group(1)

    def _get_video_id(self, video_data, course_slug, video_slug):
        return self._get_urn_id(video_data) or '%s/%s' % (course_slug, video_slug)


class LinkedInIE(LinkedInBaseIE):
    _VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://www.linkedin.com/posts/mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20',
        'info_dict': {
            'id': 'C4E05AQG7hCp7zIeciw',
            'display_id': 'mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20',
            'ext': 'mp4',
            'title': 'Mishal K. on LinkedIn: #sendinblueviews #toronto #digitalmarketing #nowhiring #sendinblue…',
            'description': 'md5:2998a31f6f479376dd62831f53a80f71',
            'uploader': 'Mishal K.',
            'thumbnail': 'https://media.licdn.com/dms/image/C4E05AQG7hCp7zIeciw/feedshare-thumbnail_720_1280/0/1633381554858?e=2147483647&v=beta&t=teGgAD-Z8A2K4UrwAtEgHz9xGMrRLmUK6cE3vm3csK0',
            'like_count': int
        },
    }, {
        'url': 'https://www.linkedin.com/posts/the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7',
        'info_dict': {
            'id': 'D5610AQFKo9M0zqY2_g',
            'display_id': 'the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7',
            'ext': 'mp4',
            'title': 'MathWorks on LinkedIn: What Is MathWorks Cloud Center?',
            'description': 'md5:95f9d4eeb6337882fb47eefe13d7a40c',
            'uploader': 'MathWorks',
            'thumbnail': 'https://media.licdn.com/dms/image/D5610AQFKo9M0zqY2_g/ads-video-thumbnail_720_1280/0/1704988806715?e=2147483647&v=beta&t=0vg-ksOY2KrL_QFlNacCv5Tmuk0tum9FJ_4dlJ56Gyw',
            'like_count': int,
            'subtitles': 'mincount:1'
        },

Review comment (suggestion):
we can still match the numeric id
```suggestion
    _VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/[^/?#]+-(?P<id>\d+)-\w{4}/?(?:[?#]|$)'
```

Code after:
            query.update({
                'videoSlug': video_slug,
                'resolution': '_%s' % resolution,
            })
            sub = ' %dp' % resolution
        api_url = 'https://www.linkedin.com/learning-api/detailedCourses'
        if not self._get_cookies(api_url).get('JSESSIONID'):
            self.raise_login_required()
        return self._download_json(
            api_url, video_slug, 'Downloading%s JSON metadata' % sub, headers={
                'Csrf-Token': self._get_cookies(api_url)['JSESSIONID'].value,
            }, query=query)['elements'][0]

    def _get_urn_id(self, video_data):
        urn = video_data.get('urn')
        if urn:
            mobj = re.search(r'urn:li:lyndaCourse:\d+,(\d+)', urn)
            if mobj:
                return mobj.group(1)

    def _get_video_id(self, video_data, course_slug, video_slug):
        return self._get_urn_id(video_data) or '%s/%s' % (course_slug, video_slug)


class LinkedInIE(LinkedInBaseIE):
    _VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/[^/?#]+-(?P<id>\d+)-\w{4}/?(?:[?#]|$)'
    _TESTS = [{
        'url': 'https://www.linkedin.com/posts/mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20',
        'info_dict': {
            'id': '6850898786781339649',
            'ext': 'mp4',
            'title': 'Mishal K. on LinkedIn: #sendinblueviews #toronto #digitalmarketing #nowhiring #sendinblue…',
            'description': 'md5:2998a31f6f479376dd62831f53a80f71',
            'uploader': 'Mishal K.',
            'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$',
            'like_count': int
        },
    }, {
        'url': 'https://www.linkedin.com/posts/the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7',
        'info_dict': {
            'id': '7151241570371948544',
            'ext': 'mp4',
            'title': 'MathWorks on LinkedIn: What Is MathWorks Cloud Center?',
            'description': 'md5:95f9d4eeb6337882fb47eefe13d7a40c',
            'uploader': 'MathWorks',
            'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$',
            'like_count': int,
            'subtitles': 'mincount:1'
        },
    }]