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.

80 lines
2.5 KiB

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