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.

84 lines
2.6 KiB

  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. compat_urllib_request,
  8. int_or_none,
  9. urlencode_postdata,
  10. )
  11. class HostingBulkIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://(?:www\.)?hostingbulk\.com/
  14. (?:embed-)?(?P<id>[A-Za-z0-9]{12})(?:-\d+x\d+)?\.html'''
  15. _FILE_DELETED_REGEX = r'<b>File Not Found</b>'
  16. _TEST = {
  17. 'url': 'http://hostingbulk.com/n0ulw1hv20fm.html',
  18. 'md5': '6c8653c8ecf7ebfa83b76e24b7b2fe3f',
  19. 'info_dict': {
  20. 'id': 'n0ulw1hv20fm',
  21. 'ext': 'mp4',
  22. 'title': 'md5:5afeba33f48ec87219c269e054afd622',
  23. 'filesize': 6816081,
  24. 'thumbnail': 're:^http://.*\.jpg$',
  25. }
  26. }
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. url = 'http://hostingbulk.com/{0:}.html'.format(video_id)
  31. # Custom request with cookie to set language to English, so our file
  32. # deleted regex would work.
  33. request = compat_urllib_request.Request(
  34. url, headers={'Cookie': 'lang=english'})
  35. webpage = self._download_webpage(request, video_id)
  36. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  37. raise ExtractorError('Video %s does not exist' % video_id,
  38. expected=True)
  39. title = self._html_search_regex(r'<h3>(.*?)</h3>', webpage, 'title')
  40. filesize = int_or_none(
  41. self._search_regex(
  42. r'<small>\((\d+)\sbytes?\)</small>',
  43. webpage,
  44. 'filesize',
  45. fatal=False
  46. )
  47. )
  48. thumbnail = self._search_regex(
  49. r'<img src="([^"]+)".+?class="pic"',
  50. webpage, 'thumbnail', fatal=False)
  51. fields = dict(re.findall(r'''(?x)<input\s+
  52. type="hidden"\s+
  53. name="([^"]+)"\s+
  54. value="([^"]*)"
  55. ''', webpage))
  56. request = compat_urllib_request.Request(url, urlencode_postdata(fields))
  57. request.add_header('Content-type', 'application/x-www-form-urlencoded')
  58. response = self._request_webpage(request, video_id,
  59. 'Submiting download request')
  60. video_url = response.geturl()
  61. formats = [{
  62. 'format_id': 'sd',
  63. 'filesize': filesize,
  64. 'url': video_url,
  65. }]
  66. return {
  67. 'id': video_id,
  68. 'title': title,
  69. 'thumbnail': thumbnail,
  70. 'formats': formats,
  71. }