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.

88 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. compat_urllib_parse,
  8. compat_urllib_request,
  9. )
  10. class GorillaVidIE(InfoExtractor):
  11. IE_DESC = 'GorillaVid.in and daclips.in'
  12. _VALID_URL = r'''(?x)
  13. https?://(?P<host>(?:www\.)?
  14. (?:daclips\.in|gorillavid\.in))/
  15. (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
  16. '''
  17. _TESTS = [{
  18. 'url': 'http://gorillavid.in/06y9juieqpmi',
  19. 'md5': '5ae4a3580620380619678ee4875893ba',
  20. 'info_dict': {
  21. 'id': '06y9juieqpmi',
  22. 'ext': 'flv',
  23. 'title': 'Rebecca Black My Moment Official Music Video Reaction',
  24. 'thumbnail': 're:http://.*\.jpg',
  25. },
  26. }, {
  27. 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
  28. 'md5': 'c9e293ca74d46cad638e199c3f3fe604',
  29. 'info_dict': {
  30. 'id': 'z08zf8le23c6',
  31. 'ext': 'mp4',
  32. 'title': 'Say something nice',
  33. 'thumbnail': 're:http://.*\.jpg',
  34. },
  35. }, {
  36. 'url': 'http://daclips.in/3rso4kdn6f9m',
  37. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  38. 'info_dict': {
  39. 'id': '3rso4kdn6f9m',
  40. 'ext': 'mp4',
  41. 'title': 'Micro Pig piglets ready on 16th July 2009',
  42. 'thumbnail': 're:http://.*\.jpg',
  43. },
  44. }]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('id')
  48. webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
  49. fields = dict(re.findall(r'''(?x)<input\s+
  50. type="hidden"\s+
  51. name="([^"]+)"\s+
  52. (?:id="[^"]+"\s+)?
  53. value="([^"]*)"
  54. ''', webpage))
  55. if fields['op'] == 'download1':
  56. post = compat_urllib_parse.urlencode(fields)
  57. req = compat_urllib_request.Request(url, post)
  58. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  59. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  60. title = self._search_regex(r'style="z-index: [0-9]+;">([0-9a-zA-Z ]+)(?:-.+)?</span>', webpage, 'title')
  61. thumbnail = self._search_regex(r'image:\'(http[^\']+)\',', webpage, 'thumbnail')
  62. url = self._search_regex(r'file: \'(http[^\']+)\',', webpage, 'file url')
  63. formats = [{
  64. 'format_id': 'sd',
  65. 'url': url,
  66. 'ext': determine_ext(url),
  67. 'quality': 1,
  68. }]
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'thumbnail': thumbnail,
  73. 'formats': formats,
  74. }