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.

118 lines
3.9 KiB

10 years ago
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. determine_ext,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. int_or_none,
  11. )
  12. class GorillaVidIE(InfoExtractor):
  13. IE_DESC = 'GorillaVid.in, daclips.in, movpod.in and fastvideo.in'
  14. _VALID_URL = r'''(?x)
  15. https?://(?P<host>(?:www\.)?
  16. (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in))/
  17. (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
  18. '''
  19. _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
  20. _TESTS = [{
  21. 'url': 'http://gorillavid.in/06y9juieqpmi',
  22. 'md5': '5ae4a3580620380619678ee4875893ba',
  23. 'info_dict': {
  24. 'id': '06y9juieqpmi',
  25. 'ext': 'flv',
  26. 'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
  27. 'thumbnail': 're:http://.*\.jpg',
  28. },
  29. }, {
  30. 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
  31. 'md5': 'c9e293ca74d46cad638e199c3f3fe604',
  32. 'info_dict': {
  33. 'id': 'z08zf8le23c6',
  34. 'ext': 'mp4',
  35. 'title': 'Say something nice',
  36. 'thumbnail': 're:http://.*\.jpg',
  37. },
  38. }, {
  39. 'url': 'http://daclips.in/3rso4kdn6f9m',
  40. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  41. 'info_dict': {
  42. 'id': '3rso4kdn6f9m',
  43. 'ext': 'mp4',
  44. 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
  45. 'thumbnail': 're:http://.*\.jpg',
  46. }
  47. }, {
  48. # video with countdown timeout
  49. 'url': 'http://fastvideo.in/1qmdn1lmsmbw',
  50. 'md5': '8b87ec3f6564a3108a0e8e66594842ba',
  51. 'info_dict': {
  52. 'id': '1qmdn1lmsmbw',
  53. 'ext': 'mp4',
  54. 'title': 'Man of Steel - Trailer',
  55. 'thumbnail': 're:http://.*\.jpg',
  56. },
  57. }, {
  58. 'url': 'http://movpod.in/0wguyyxi1yca',
  59. 'only_matching': True,
  60. }]
  61. def _real_extract(self, url):
  62. mobj = re.match(self._VALID_URL, url)
  63. video_id = mobj.group('id')
  64. webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
  65. if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
  66. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  67. fields = dict(re.findall(r'''(?x)<input\s+
  68. type="hidden"\s+
  69. name="([^"]+)"\s+
  70. (?:id="[^"]+"\s+)?
  71. value="([^"]*)"
  72. ''', webpage))
  73. if fields['op'] == 'download1':
  74. countdown = int_or_none(self._search_regex(
  75. r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
  76. webpage, 'countdown', default=None))
  77. if countdown:
  78. self._sleep(countdown, video_id)
  79. post = compat_urllib_parse.urlencode(fields)
  80. req = compat_urllib_request.Request(url, post)
  81. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  82. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  83. title = self._search_regex(
  84. r'style="z-index: [0-9]+;">([^<]+)</span>',
  85. webpage, 'title', default=None) or self._og_search_title(webpage)
  86. video_url = self._search_regex(
  87. r'file\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'file url')
  88. thumbnail = self._search_regex(
  89. r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', fatal=False)
  90. formats = [{
  91. 'format_id': 'sd',
  92. 'url': video_url,
  93. 'ext': determine_ext(video_url),
  94. 'quality': 1,
  95. }]
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'thumbnail': thumbnail,
  100. 'formats': formats,
  101. }