Compare commits

...

6 Commits

Author SHA1 Message Date
bashonly
d3d8aad1f4
fix typo 2024-02-09 00:21:40 +00:00
bashonly
4af7435043
Apply suggestions from code review 2024-02-09 00:20:17 +00:00
Moritz Barsnick
94e3fa9d3a [ie/LinkedIn] revert id change 2024-02-09 00:29:23 +01:00
Moritz Barsnick
928c4e8ce9 [ie/LinkedIn] inline intermediate variables, relax regex 2024-02-09 00:29:20 +01:00
Moritz Barsnick
8eef61fbf2 [ie/LinkedIn] reduce display_id to the digit sequence of the URL 2024-02-09 00:01:32 +01:00
Moritz Barsnick
83e3487ee8 [ie/LinkedIn] relax thumbnail in TESTS by using regex 2024-02-09 00:01:29 +01:00

View File

@ -3,8 +3,8 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
extract_attributes,
ExtractorError, ExtractorError,
extract_attributes,
float_or_none, float_or_none,
int_or_none, int_or_none,
srt_subtitles_timecode, srt_subtitles_timecode,
@ -82,29 +82,27 @@ class LinkedInLearningBaseIE(LinkedInBaseIE):
class LinkedInIE(LinkedInBaseIE): class LinkedInIE(LinkedInBaseIE):
_VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/(?P<id>[^/?#]+)' _VALID_URL = r'https?://(?:www\.)?linkedin\.com/posts/[^/?#]+-(?P<id>\d+)-\w{4}/?(?:[?#]|$)'
_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': 'C4E05AQG7hCp7zIeciw', 'id': '6850898786781339649',
'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': 'https://media.licdn.com/dms/image/C4E05AQG7hCp7zIeciw/feedshare-thumbnail_720_1280/0/1633381554858?e=2147483647&v=beta&t=teGgAD-Z8A2K4UrwAtEgHz9xGMrRLmUK6cE3vm3csK0', 'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$',
'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': 'D5610AQFKo9M0zqY2_g', 'id': '7151241570371948544',
'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': 'https://media.licdn.com/dms/image/D5610AQFKo9M0zqY2_g/ads-video-thumbnail_720_1280/0/1704988806715?e=2147483647&v=beta&t=0vg-ksOY2KrL_QFlNacCv5Tmuk0tum9FJ_4dlJ56Gyw', 'thumbnail': 're:^https?://media.licdn.com/dms/image/.*$',
'like_count': int, 'like_count': int,
'subtitles': 'mincount:1' 'subtitles': 'mincount:1'
}, },
@ -114,17 +112,8 @@ 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')),
@ -136,14 +125,16 @@ 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': id, 'id': video_id,
'display_id': video_id,
'formats': formats, 'formats': formats,
'title': title, 'title': self._og_search_title(webpage, default=None) or self._html_extract_title(webpage),
'like_count': like_count, 'like_count': int_or_none(self._search_regex(
'uploader': uploader, r'\bdata-num-reactions="(\d+)"', webpage, 'reactions', default=None)),
'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': description, 'description': self._og_search_description(webpage, default=None),
'subtitles': subtitles, 'subtitles': subtitles,
} }