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.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 and fastvideo.in'
  15. _VALID_URL = r'''(?x)
  16. https?://(?P<host>(?:www\.)?
  17. (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in))/
  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. 'md5': 'c9e293ca74d46cad638e199c3f3fe604',
  33. 'info_dict': {
  34. 'id': 'z08zf8le23c6',
  35. 'ext': 'mp4',
  36. 'title': 'Say something nice',
  37. 'thumbnail': 're:http://.*\.jpg',
  38. },
  39. }, {
  40. 'url': 'http://daclips.in/3rso4kdn6f9m',
  41. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  42. 'info_dict': {
  43. 'id': '3rso4kdn6f9m',
  44. 'ext': 'mp4',
  45. 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
  46. 'thumbnail': 're:http://.*\.jpg',
  47. }
  48. }, {
  49. # video with countdown timeout
  50. 'url': 'http://fastvideo.in/1qmdn1lmsmbw',
  51. 'md5': '8b87ec3f6564a3108a0e8e66594842ba',
  52. 'info_dict': {
  53. 'id': '1qmdn1lmsmbw',
  54. 'ext': 'mp4',
  55. 'title': 'Man of Steel - Trailer',
  56. 'thumbnail': 're:http://.*\.jpg',
  57. },
  58. }, {
  59. 'url': 'http://movpod.in/0wguyyxi1yca',
  60. 'only_matching': True,
  61. }]
  62. def _real_extract(self, url):
  63. mobj = re.match(self._VALID_URL, url)
  64. video_id = mobj.group('id')
  65. webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
  66. if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
  67. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  68. fields = dict(re.findall(r'''(?x)<input\s+
  69. type="hidden"\s+
  70. name="([^"]+)"\s+
  71. (?:id="[^"]+"\s+)?
  72. value="([^"]*)"
  73. ''', webpage))
  74. if fields['op'] == 'download1':
  75. countdown = int_or_none(self._search_regex(
  76. r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
  77. webpage, 'countdown', default=None))
  78. if countdown:
  79. self._sleep(countdown, video_id)
  80. post = compat_urllib_parse.urlencode(fields)
  81. req = compat_urllib_request.Request(url, post)
  82. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  83. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  84. title = self._search_regex(
  85. r'style="z-index: [0-9]+;">([^<]+)</span>',
  86. webpage, 'title', default=None) or self._og_search_title(webpage)
  87. video_url = self._search_regex(
  88. r'file\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'file url')
  89. thumbnail = self._search_regex(
  90. r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', fatal=False)
  91. formats = [{
  92. 'format_id': 'sd',
  93. 'url': video_url,
  94. 'quality': 1,
  95. }]
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'thumbnail': thumbnail,
  100. 'formats': formats,
  101. }