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 1 commit
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
51 changes: 51 additions & 0 deletions youtube_dl/extractor/samplefocus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import (
get_element_by_class,
extract_attributes,
get_element_by_id)
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved


class SampleFocusIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?samplefocus\.com/samples/(?P<id>[\w,\-,0-9]+)'
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
_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',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
'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')
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
tb = self._og_search_thumbnail(webpage) or extract_attributes(get_element_by_class('waveform')).get('src')
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved

mp3_url = self._html_search_regex(
r'<meta itemprop="contentUrl" content="?(.+?)"?>',
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved
webpage, 'mp3 url') or extract_attributes(get_element_by_id('sample_mp3')).get('value')
Isaac-the-Man marked this conversation as resolved.
Show resolved Hide resolved

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
}