gorillavid.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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?://(?: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. 'info_dict': {
  38. 'id': '3rso4kdn6f9m',
  39. 'ext': 'mp4',
  40. 'title': 'Micro Pig piglets ready on 16th July 2009',
  41. 'thumbnail': 're:http://.*\.jpg',
  42. },
  43. }]
  44. def _real_extract(self, url):
  45. mobj = re.match(self._VALID_URL, url)
  46. video_id = mobj.group('id')
  47. webpage = self._download_webpage(url, video_id)
  48. fields = dict(re.findall(r'''(?x)<input\s+
  49. type="hidden"\s+
  50. name="([^"]+)"\s+
  51. (?:id="[^"]+"\s+)?
  52. value="([^"]*)"
  53. ''', webpage))
  54. if fields['op'] == 'download1':
  55. post = compat_urllib_parse.urlencode(fields)
  56. req = compat_urllib_request.Request(url, post)
  57. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  58. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  59. title = self._search_regex(r'style="z-index: [0-9]+;">([0-9a-zA-Z ]+)(?:-.+)?</span>', webpage, 'title')
  60. thumbnail = self._search_regex(r'image:\'(http[^\']+)\',', webpage, 'thumbnail')
  61. url = self._search_regex(r'file: \'(http[^\']+)\',', webpage, 'file url')
  62. formats = [{
  63. 'format_id': 'sd',
  64. 'url': url,
  65. 'ext': determine_ext(url),
  66. 'quality': 1,
  67. }]
  68. return {
  69. 'id': video_id,
  70. 'title': title,
  71. 'thumbnail': thumbnail,
  72. 'formats': formats,
  73. }