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

[Youvi] Add new extractor #27784

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -1567,6 +1567,7 @@
YoutubeYtUserIE,
YoutubeWatchLaterIE,
)
from .youvi import YouviIE
from .zapiks import ZapiksIE
from .zattoo import (
BBVTVIE,
Expand Down
53 changes: 53 additions & 0 deletions youtube_dl/extractor/youvi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor


class YouviIE(InfoExtractor):
_VALID_URL = r'https://youvi.ru/post/(?P<id>.*)'
_TEST = {
'url': 'https://youvi.ru/post/Ni2BmFhUwUt',
'md5': '510062b5b3f32f6ba2f6888607d7a434',
'info_dict': {
'id': 'Ni2BmFhUwUt',
'ext': 'mp4',
'title': 'TikTok показал собственный спецэффект для IPhone 12 Pro, использующий датчик LiDAR.',
}
}

def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
title = self._search_regex(
r'title:"(?P<title>[^"]+)"', webpage, 'title')

formats = []
for url_type in ('url', 'hls'):
url = self._search_regex(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not shadow outer names.

r'source_file:[^}]+(?:%s):"(?P<url>[^"]+?)"' % url_type,
webpage, 'youvi-hosted-url', fatal=False)
if url:
url = url.replace(r'\u002F', r'/')
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if there are more escape codes?

format_entry = {'url': url}
formats.append(format_entry)

if formats:
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'formats': formats,
}
else:
external_embed = self._search_regex(
r'service_type:"(?P<embed>[^"]+?)"', webpage, 'external-embed')
external_id = self._search_regex(
r'external_id:"(?P<id>[^"]+?)"', webpage, 'external-id')

if external_embed == 'youtube':
return self.url_result(external_id, 'Youtube')

elif external_embed == 'vimeo':
return self.url_result(
'https://vimeo.com/' + external_id, 'Vimeo')
Comment on lines +48 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add tests for such embeds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Extractor should not return None.