2022-05-16 19:28:19 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import json
|
2022-05-21 14:19:18 +00:00
|
|
|
from ..utils import url_or_none
|
2022-05-16 19:28:19 +00:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
|
|
|
|
|
|
|
class MegaCartoonsIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?megacartoons\.net/(?P<id>[a-z-]+)/'
|
|
|
|
_TEST = {
|
|
|
|
'url': 'https://www.megacartoons.net/help-wanted/',
|
|
|
|
'md5': '4ba9be574f9a17abe0c074e2f955fded',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'help-wanted',
|
2022-05-16 20:32:47 +00:00
|
|
|
'title': 'Help Wanted',
|
2022-05-16 19:28:19 +00:00
|
|
|
'ext': 'mp4',
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2022-05-21 14:19:18 +00:00
|
|
|
'description': 'md5:2c909daa6c6cb16b2d4d791dd1a31632'
|
2022-05-16 19:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-05-16 19:37:35 +00:00
|
|
|
# ID is equal to the episode name
|
2022-05-16 19:28:19 +00:00
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2022-05-16 20:32:47 +00:00
|
|
|
# Try to find a good title or fallback to the ID
|
|
|
|
title = self._og_search_title(webpage) or video_id
|
2022-05-16 19:37:35 +00:00
|
|
|
|
|
|
|
# Video data is stored in a json -> extract it from the raw html
|
2022-05-16 20:32:47 +00:00
|
|
|
url_json = json.loads(self._html_search_regex(r'<div.*data-item=["/\'](?P<videourls>{.*})["/\'].*>', webpage, 'videourls'))
|
2022-05-16 19:28:19 +00:00
|
|
|
|
2022-05-21 14:19:18 +00:00
|
|
|
video_url = url_or_none(url_json.get('sources')[0].get('src') or self._og_search_video_url(webpage)) # Get the video url
|
|
|
|
video_thumbnail = url_or_none(url_json.get('splash') or self._og_search_thumbnail(webpage)) # Get the thumbnail
|
2022-05-16 19:28:19 +00:00
|
|
|
|
2022-05-21 14:19:18 +00:00
|
|
|
# Find the <article> class in the html
|
|
|
|
article = self._search_regex(
|
|
|
|
r'(?s)<article\b[^>]*?\bclass\s*=\s*[^>]*?\bpost\b[^>]*>(.+?)</article\b', webpage, 'post', default='')
|
|
|
|
|
|
|
|
# Extract the actual description from it
|
|
|
|
video_description = (self._html_search_regex(r'(?s)<p>\s*([^<]+)\s*</p>', article, 'videodescription', fatal=False)
|
|
|
|
or self._og_search_description(webpage))
|
2022-05-16 19:28:19 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'url': video_url,
|
|
|
|
'thumbnail': video_thumbnail,
|
|
|
|
'description': video_description,
|
|
|
|
}
|