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.

83 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. determine_ext,
  10. ExtractorError,
  11. )
  12. from .common import InfoExtractor
  13. class SockshareIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?sockshare\.com/file/(?P<id>[0-9A-Za-z]+)'
  15. _FILE_DELETED_REGEX = r'This file doesn\'t exist, or has been removed\.</div>'
  16. _TEST = {
  17. 'url': 'http://www.sockshare.com/file/437BE28B89D799D7',
  18. 'md5': '9d0bf1cfb6dbeaa8d562f6c97506c5bd',
  19. 'info_dict': {
  20. 'id': '437BE28B89D799D7',
  21. 'title': 'big_buck_bunny_720p_surround.avi',
  22. 'ext': 'avi',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. url = 'http://sockshare.com/file/%s' % video_id
  28. webpage = self._download_webpage(url, video_id)
  29. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  30. raise ExtractorError('Video %s does not exist' % video_id,
  31. expected=True)
  32. confirm_hash = self._html_search_regex(r'''(?x)<input\s+
  33. type="hidden"\s+
  34. value="([^"]*)"\s+
  35. name="hash"
  36. ''', webpage, 'hash')
  37. fields = {
  38. "hash": confirm_hash.encode('utf-8'),
  39. "confirm": "Continue as Free User"
  40. }
  41. post = compat_urllib_parse.urlencode(fields)
  42. req = compat_urllib_request.Request(url, post)
  43. # Apparently, this header is required for confirmation to work.
  44. req.add_header('Host', 'www.sockshare.com')
  45. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  46. webpage = self._download_webpage(
  47. req, video_id, 'Downloading video page')
  48. video_url = self._html_search_regex(
  49. r'<a href="([^"]*)".+class="download_file_link"',
  50. webpage, 'file url')
  51. video_url = "http://www.sockshare.com" + video_url
  52. title = self._html_search_regex((
  53. r'<h1>(.+)<strong>',
  54. r'var name = "([^"]+)";'),
  55. webpage, 'title', default=None)
  56. thumbnail = self._html_search_regex(
  57. r'<img\s+src="([^"]*)".+?name="bg"',
  58. webpage, 'thumbnail', default=None)
  59. formats = [{
  60. 'format_id': 'sd',
  61. 'url': video_url,
  62. 'ext': determine_ext(title),
  63. }]
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'thumbnail': thumbnail,
  68. 'formats': formats,
  69. }