Skip to content

Commit

Permalink
Commit suggested changes.
Browse files Browse the repository at this point in the history
- Verify description through md5
- Implement suffisticated detection of description
- Remove format attribute to allow auto detection
- Allow conditioning of URLs
  • Loading branch information
Daenges committed May 21, 2022
1 parent 041abb9 commit 0b5477e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions youtube_dl/extractor/megacartoons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import json
from ..utils import url_or_none

from .common import InfoExtractor

Expand All @@ -16,12 +17,7 @@ class MegaCartoonsIE(InfoExtractor):
'title': 'Help Wanted',
'ext': 'mp4',
'thumbnail': r're:^https?://.*\.jpg$',
'description': 'Help Wanted: Encouraged by his best friend, Patrick Starfish, '
'SpongeBob overcomes his fears and finally applies for that '
'dream job as a fry cook at the Krusty Krab. Challenged by the '
'owner, Mr. Krabs, and his assistant Squidward, to prove himself '
'worthy of the job, SpongeBob rises to the occasion, with the help '
'of one very special spatula, by feeding a sea of ravenous anchovies.'
'description': 'md5:2c909daa6c6cb16b2d4d791dd1a31632'
}
}

Expand All @@ -36,17 +32,20 @@ def _real_extract(self, url):
# Video data is stored in a json -> extract it from the raw html
url_json = json.loads(self._html_search_regex(r'<div.*data-item=["/\'](?P<videourls>{.*})["/\'].*>', webpage, 'videourls'))

video_url = url_json.get('sources')[0].get('src') or self._og_search_video_url(webpage) # Get the video url
video_type = url_json.get('sources')[0].get('type') # Get the video type -> 'video/mp4'
video_thumbnail = url_json.get('splash') or self._og_search_thumbnail(webpage) # Get the thumbnail
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

# Every video has a short summary -> save it as description
video_description = self._html_search_regex(r'<p>(?P<videodescription>.*)</p>', webpage, 'videodescription', fatal=False) or self._og_search_description(webpage)
# 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))

return {
'id': video_id,
'title': title,
'format': video_type,
'url': video_url,
'thumbnail': video_thumbnail,
'description': video_description,
Expand Down

0 comments on commit 0b5477e

Please sign in to comment.