hostingbulk.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. rand = self._search_regex(
  52. r'<input.+?name="rand" value="([^"]+)">', webpage, 'rand')
  53. fields = {
  54. 'id': video_id,
  55. 'method_free': '',
  56. 'method_premium': '',
  57. 'op': 'download2',
  58. 'rand': rand,
  59. 'referer': '',
  60. }
  61. request = compat_urllib_request.Request(url, urlencode_postdata(fields))
  62. request.add_header('Content-type', 'application/x-www-form-urlencoded')
  63. response = self._request_webpage(request, video_id,
  64. 'Submiting download request')
  65. video_url = response.geturl()
  66. formats = [{
  67. 'format_id': 'sd',
  68. 'filesize': filesize,
  69. 'url': video_url,
  70. }]
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'thumbnail': thumbnail,
  75. 'formats': formats,
  76. }