You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_iso8601,
  6. str_to_int,
  7. )
  8. class CrackedIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?cracked\.com/video_(?P<id>\d+)_[\da-z-]+\.html'
  10. _TEST = {
  11. 'url': 'http://www.cracked.com/video_19006_4-plot-holes-you-didnt-notice-in-your-favorite-movies.html',
  12. 'md5': '4b29a5eeec292cd5eca6388c7558db9e',
  13. 'info_dict': {
  14. 'id': '19006',
  15. 'ext': 'mp4',
  16. 'title': '4 Plot Holes You Didn\'t Notice in Your Favorite Movies',
  17. 'description': 'md5:3b909e752661db86007d10e5ec2df769',
  18. 'timestamp': 1405659600,
  19. 'upload_date': '20140718',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage(url, video_id)
  26. video_url = self._html_search_regex(
  27. [r'var\s+CK_vidSrc\s*=\s*"([^"]+)"', r'<video\s+src="([^"]+)"'], webpage, 'video URL')
  28. title = self._og_search_title(webpage)
  29. description = self._og_search_description(webpage)
  30. timestamp = self._html_search_regex(r'<time datetime="([^"]+)"', webpage, 'upload date', fatal=False)
  31. if timestamp:
  32. timestamp = parse_iso8601(timestamp[:-6])
  33. view_count = str_to_int(self._html_search_regex(
  34. r'<span class="views" id="viewCounts">([\d,\.]+) Views</span>', webpage, 'view count', fatal=False))
  35. comment_count = str_to_int(self._html_search_regex(
  36. r'<span id="commentCounts">([\d,\.]+)</span>', webpage, 'comment count', fatal=False))
  37. m = re.search(r'_(?P<width>\d+)X(?P<height>\d+)\.mp4$', video_url)
  38. if m:
  39. width = int(m.group('width'))
  40. height = int(m.group('height'))
  41. else:
  42. width = height = None
  43. return {
  44. 'id': video_id,
  45. 'url': video_url,
  46. 'title': title,
  47. 'description': description,
  48. 'timestamp': timestamp,
  49. 'view_count': view_count,
  50. 'comment_count': comment_count,
  51. 'height': height,
  52. 'width': width,
  53. }