Compare commits

..

No commits in common. "d3d8aad1f4243eb99b681bb0908eb6549a40d678" and "c297fec07a983a57ae967217531f614cca75146a" have entirely different histories.

View File

@ -3,8 +3,8 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError,
extract_attributes, extract_attributes,
ExtractorError,
float_or_none, float_or_none,
int_or_none, int_or_none,
srt_subtitles_timecode, srt_subtitles_timecode,
@ -82,27 +82,29 @@ class LinkedInLearningBaseIE(LinkedInBaseIE):
class LinkedInIE(LinkedInBaseIE): class LinkedInIE(LinkedInBaseIE):
_VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/[^/?#]+-(?P<id>\d+)-\w{4}/?(?:[?#]|$)' _VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/(?P<id>[^/?#]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://www.linkedin.com/posts/mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20', 'url': 'https://www.linkedin.com/posts/mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20',
'info_dict': { 'info_dict': {
'id': '6850898786781339649', 'id': 'C4E05AQG7hCp7zIeciw',
'display_id': 'mishalkhawaja_sendinblueviews-toronto-digitalmarketing-ugcPost-6850898786781339649-mM20',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Mishal K. on LinkedIn: #sendinblueviews #toronto #digitalmarketing #nowhiring #sendinblue…', 'title': 'Mishal K. on LinkedIn: #sendinblueviews #toronto #digitalmarketing #nowhiring #sendinblue…',
'description': 'md5:2998a31f6f479376dd62831f53a80f71', 'description': 'md5:2998a31f6f479376dd62831f53a80f71',
'uploader': 'Mishal K.', 'uploader': 'Mishal K.',
'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$', 'thumbnail': 'https://media.licdn.com/dms/image/C4E05AQG7hCp7zIeciw/feedshare-thumbnail_720_1280/0/1633381554858?e=2147483647&v=beta&t=teGgAD-Z8A2K4UrwAtEgHz9xGMrRLmUK6cE3vm3csK0',
'like_count': int 'like_count': int
}, },
}, { }, {
'url': 'https://www.linkedin.com/posts/the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7', 'url': 'https://www.linkedin.com/posts/the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7',
'info_dict': { 'info_dict': {
'id': '7151241570371948544', 'id': 'D5610AQFKo9M0zqY2_g',
'display_id': 'the-mathworks_2_what-is-mathworks-cloud-center-activity-7151241570371948544-4Gu7',
'ext': 'mp4', 'ext': 'mp4',
'title': 'MathWorks on LinkedIn: What Is MathWorks Cloud Center?', 'title': 'MathWorks on LinkedIn: What Is MathWorks Cloud Center?',
'description': 'md5:95f9d4eeb6337882fb47eefe13d7a40c', 'description': 'md5:95f9d4eeb6337882fb47eefe13d7a40c',
'uploader': 'MathWorks', 'uploader': 'MathWorks',
'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$', '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, 'like_count': int,
'subtitles': 'mincount:1' 'subtitles': 'mincount:1'
}, },
@ -112,8 +114,17 @@ class LinkedInIE(LinkedInBaseIE):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._og_search_title(webpage, default=None) or self._html_extract_title(webpage)
description = self._og_search_description(webpage, default=None)
json_ld_list = list(self._yield_json_ld(webpage, video_id))
uploader = traverse_obj(
json_ld_list, (lambda _, v: v['@type'] == 'SocialMediaPosting', 'author'), get_all=False).get('name')
like_count = int_or_none(self._search_regex(r'<a href=[^>]+\sdata-num-reactions="(\d+)"', webpage, 'reactions', default=None))
video_attrs = extract_attributes(self._search_regex(r'(<video[^>]+>)', webpage, 'video')) video_attrs = extract_attributes(self._search_regex(r'(<video[^>]+>)', webpage, 'video'))
print('video_attrs:', video_attrs)
sources = self._parse_json(video_attrs['data-sources'], video_id) sources = self._parse_json(video_attrs['data-sources'], video_id)
id = str(video_attrs.get('data-digitalmedia-asset-urn') or video_id).replace('urn:li:digitalmediaAsset:', '')
formats = [{ formats = [{
'url': source['src'], 'url': source['src'],
'ext': mimetype2ext(source.get('type')), 'ext': mimetype2ext(source.get('type')),
@ -125,16 +136,14 @@ class LinkedInIE(LinkedInBaseIE):
}]} if url_or_none(video_attrs.get('data-captions-url')) else {} }]} if url_or_none(video_attrs.get('data-captions-url')) else {}
return { return {
'id': video_id, 'id': id,
'display_id': video_id,
'formats': formats, 'formats': formats,
'title': self._og_search_title(webpage, default=None) or self._html_extract_title(webpage), 'title': title,
'like_count': int_or_none(self._search_regex( 'like_count': like_count,
r'\bdata-num-reactions="(\d+)"', webpage, 'reactions', default=None)), 'uploader': uploader,
'uploader': traverse_obj(
self._yield_json_ld(webpage, video_id),
(lambda _, v: v['@type'] == 'SocialMediaPosting', 'author', 'name', {str}), get_all=False),
'thumbnail': self._og_search_thumbnail(webpage), 'thumbnail': self._og_search_thumbnail(webpage),
'description': self._og_search_description(webpage, default=None), 'description': description,
'subtitles': subtitles, 'subtitles': subtitles,
} }