Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[samplefocus] Add new extractor #27763

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions youtube_dl/extractor/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@
SafariApiIE,
SafariCourseIE,
)
from .samplefocus import SampleFocusIE
from .sapo import SapoIE
from .savefrom import SaveFromIE
from .sbs import SBSIE
Expand Down
52 changes: 52 additions & 0 deletions youtube_dl/extractor/samplefocus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor


class SampleFocusIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?samplefocus\.com/samples/(?P<id>[^/?&#]+)'
_TESTS = [{
'url': 'https://samplefocus.com/samples/lil-peep-sad-emo-guitar',
'md5': '48c8d62d60be467293912e0e619a5120',
'info_dict': {
'id': 'lil-peep-sad-emo-guitar',
'ext': 'mp3',
'title': 'Lil Peep Sad Emo Guitar',
'description': 'Listen to Lil Peep Sad Emo Guitar. Royalty-Free sound that is tagged as electric guitar, emo, guitar, and lil peep. Download for FREE + discover 1000\'s of sounds.',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
'thumbnail': r're:^https?://.+\.png',
'license': 'Standard License'
}
}, {
'url': 'https://samplefocus.com/samples/dababy-style-bass-808',
'only_matching': True
}, {
'url': 'https://samplefocus.com/samples/young-chop-kick',
'only_matching': True
}]

def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)

title = self._og_search_title(webpage) or self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title', default=video_id)
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved

mp3_url = self._html_search_regex(
r'<input type="hidden" name="sample_mp3" id="sample_mp3" value="(.+\.mp3\?[0-9]+)" class="sample-mp3" />',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use _hidden_inputs method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values returned from _hidden_inputs will be overwritten by the last value if multiple <inputs type="hidden"/> are present.

webpage, 'mp3', fatal=False) or self._html_search_regex(
r'<meta itemprop="contentUrl" content="?(.+\.mp3\?[0-9]+)"?>',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
webpage, 'mp3 url')

tb = self._og_search_thumbnail(webpage) or self._html_search_regex(
r'<img class="waveform" style="background-color: #(?:[\w,0-9]{6})" src="(.+?)" />',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
webpage, 'mp3', fatal=False)

return {
'id': video_id,
'title': title,
'url': mp3_url,
'ext': 'mp3',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
'thumbnail': tb,
'description': self._html_search_meta('description', webpage),
'license': self._html_search_regex(r'<a href="/license">(.+?)</a>', webpage, 'license')
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
}