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.

117 lines
3.8 KiB

10 years ago
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. int_or_none,
  12. )
  13. class GorillaVidIE(InfoExtractor):
  14. IE_DESC = 'GorillaVid.in, daclips.in, movpod.in, fastvideo.in and realvid.net'
  15. _VALID_URL = r'''(?x)
  16. https?://(?P<host>(?:www\.)?
  17. (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in|realvid\.net))/
  18. (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
  19. '''
  20. _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
  21. _TESTS = [{
  22. 'url': 'http://gorillavid.in/06y9juieqpmi',
  23. 'md5': '5ae4a3580620380619678ee4875893ba',
  24. 'info_dict': {
  25. 'id': '06y9juieqpmi',
  26. 'ext': 'flv',
  27. 'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
  28. 'thumbnail': 're:http://.*\.jpg',
  29. },
  30. }, {
  31. 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://daclips.in/3rso4kdn6f9m',
  35. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  36. 'info_dict': {
  37. 'id': '3rso4kdn6f9m',
  38. 'ext': 'mp4',
  39. 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
  40. 'thumbnail': 're:http://.*\.jpg',
  41. }
  42. }, {
  43. # video with countdown timeout
  44. 'url': 'http://fastvideo.in/1qmdn1lmsmbw',
  45. 'md5': '8b87ec3f6564a3108a0e8e66594842ba',
  46. 'info_dict': {
  47. 'id': '1qmdn1lmsmbw',
  48. 'ext': 'mp4',
  49. 'title': 'Man of Steel - Trailer',
  50. 'thumbnail': 're:http://.*\.jpg',
  51. },
  52. }, {
  53. 'url': 'http://realvid.net/ctn2y6p2eviw',
  54. 'md5': 'b2166d2cf192efd6b6d764c18fd3710e',
  55. 'info_dict': {
  56. 'id': 'ctn2y6p2eviw',
  57. 'ext': 'flv',
  58. 'title': 'rdx 1955',
  59. 'thumbnail': 're:http://.*\.jpg',
  60. },
  61. }, {
  62. 'url': 'http://movpod.in/0wguyyxi1yca',
  63. 'only_matching': True,
  64. }]
  65. def _real_extract(self, url):
  66. mobj = re.match(self._VALID_URL, url)
  67. video_id = mobj.group('id')
  68. url = 'http://%s/%s' % (mobj.group('host'), video_id)
  69. webpage = self._download_webpage(url, video_id)
  70. if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
  71. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  72. fields = self._hidden_inputs(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>', r'>Watch (.+) '],
  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. 'quality': 1,
  94. }]
  95. return {
  96. 'id': video_id,
  97. 'title': title,
  98. 'thumbnail': thumbnail,
  99. 'formats': formats,
  100. }