cracked.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. youtube_url = self._search_regex(
  27. r'<iframe[^>]+src="((?:https?:)?//www\.youtube\.com/embed/[^"]+)"',
  28. webpage, 'youtube url', default=None)
  29. if youtube_url:
  30. return self.url_result(youtube_url)
  31. video_url = self._html_search_regex(
  32. [r'var\s+CK_vidSrc\s*=\s*"([^"]+)"', r'<video\s+src="([^"]+)"'],
  33. webpage, 'video URL')
  34. title = self._search_regex(
  35. [r'property="?og:title"?\s+content="([^"]+)"', r'class="?title"?>([^<]+)'],
  36. webpage, 'title')
  37. description = self._search_regex(
  38. r'name="?(?:og:)?description"?\s+content="([^"]+)"',
  39. webpage, 'description', default=None)
  40. timestamp = self._html_search_regex(
  41. r'"date"\s*:\s*"([^"]+)"', webpage, 'upload date', fatal=False)
  42. if timestamp:
  43. timestamp = parse_iso8601(timestamp[:-6])
  44. view_count = str_to_int(self._html_search_regex(
  45. r'<span\s+class="?views"? id="?viewCounts"?>([\d,\.]+) Views</span>',
  46. webpage, 'view count', fatal=False))
  47. comment_count = str_to_int(self._html_search_regex(
  48. r'<span\s+id="?commentCounts"?>([\d,\.]+)</span>',
  49. webpage, 'comment count', fatal=False))
  50. m = re.search(r'_(?P<width>\d+)X(?P<height>\d+)\.mp4$', video_url)
  51. if m:
  52. width = int(m.group('width'))
  53. height = int(m.group('height'))
  54. else:
  55. width = height = None
  56. return {
  57. 'id': video_id,
  58. 'url': video_url,
  59. 'title': title,
  60. 'description': description,
  61. 'timestamp': timestamp,
  62. 'view_count': view_count,
  63. 'comment_count': comment_count,
  64. 'height': height,
  65. 'width': width,
  66. }