3 from .common
import InfoExtractor
6 get_element_by_attribute
,
11 class SampleFocusIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?:www\.)?samplefocus\.com/samples/(?P<id>[^/?&#]+)'
14 'url': 'https://samplefocus.com/samples/lil-peep-sad-emo-guitar',
15 'md5': '48c8d62d60be467293912e0e619a5120',
18 'display_id': 'lil-peep-sad-emo-guitar',
20 'title': 'Lil Peep Sad Emo Guitar',
21 'thumbnail': r
're:^https?://.+\.png',
22 'license': 'Standard License',
23 'uploader': 'CapsCtrl',
24 'uploader_id': 'capsctrl',
27 'categories': ['Samples', 'Guitar', 'Electric guitar'],
30 'url': 'https://samplefocus.com/samples/dababy-style-bass-808',
31 'only_matching': True,
33 'url': 'https://samplefocus.com/samples/young-chop-kick',
34 'only_matching': True,
37 def _real_extract(self
, url
):
38 display_id
= self
._match
_id
(url
)
39 webpage
= self
._download
_webpage
(url
, display_id
, impersonate
=True)
41 sample_id
= self
._search
_regex
(
42 r
'<input[^>]+id=(["\'])sample_id\
1[^
>]+value
=(?
:["\'])(?P<id>\d+)',
43 webpage, 'sample id', group='id')
45 title = self._og_search_title(webpage, fatal=False) or self._html_search_regex(
46 r'<h1>(.+?)</h1>', webpage, 'title')
48 mp3_url = self._search_regex(
49 r'<input[^>]+id=(["\'])sample_mp3\
1[^
>]+value
=(["\'])(?P<url>(?:(?!\2).)+)',
50 webpage, 'mp3', fatal=False, group='url') or extract_attributes(self._search_regex(
51 r'<meta[^>]+itemprop=(["\'])contentUrl\
1[^
>]*>',
52 webpage, 'mp3 url
', group=0))['content
']
54 thumbnail = self._og_search_thumbnail(webpage) or self._html_search_regex(
55 r'<img
[^
>]+class=(?
:["\'])waveform responsive-img[^>]+src=(["\'])(?P
<url
>(?
:(?
!\
1).)+)',
56 webpage, 'mp3
', fatal=False, group='url
')
59 for author_id, author, body in re.findall(r'(?s
)<p
[^
>]+class="comment-author"><a
[^
>]+href
="/users/([^"]+)">([^"]+)</a
>.+?
<p
[^
>]+class="comment-body">([^
>]+)</p
>', webpage):
62 'author_id
': author_id,
66 uploader_id = uploader = None
67 mobj = re.search(r'>By
<a
[^
>]+href
="/users/([^"]+)"[^>]*>([^<]+)', webpage)
69 uploader_id, uploader = mobj.groups()
71 breadcrumb = get_element_by_attribute('typeof', 'BreadcrumbList', webpage)
74 for _, name in re.findall(r'<span[^>]+property=(["\'])name\
1[^
>]*>([^
<]+)', breadcrumb):
75 categories.append(name)
77 def extract_count(klass):
78 return int_or_none(self._html_search_regex(
79 rf'<span
[^
>]+class=(?
:["\'])?{klass}-count[^>]*>(\d+)',
80 webpage, klass, fatal=False))
94 'display_id': display_id,
95 'thumbnail': thumbnail,
97 'license': self._html_search_regex(
98 r'<a[^>]+href=(["\'])/license\
1[^
>]*>(?P
<license
>[^
<]+)<',
99 webpage, 'license
', fatal=False, group='license
'),
100 'uploader_id
': uploader_id,
101 'like_count
': extract_count(f'sample
-{sample_id}
-favorites
'),
102 'comment_count
': extract_count('comments
'),
103 'comments
': comments,
104 'categories
': categories,