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 ..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. 'thumbnail': 're:^http://.*\.jpg$',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. url = 'http://sockshare.com/file/%s' % video_id
  29. webpage = self._download_webpage(url, video_id)
  30. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  31. raise ExtractorError('Video %s does not exist' % video_id,
  32. expected=True)
  33. confirm_hash = self._html_search_regex(r'''(?x)<input\s+
  34. type="hidden"\s+
  35. value="([^"]*)"\s+
  36. name="hash"
  37. ''', webpage, 'hash')
  38. fields = {
  39. "hash": confirm_hash,
  40. "confirm": "Continue as Free User"
  41. }
  42. post = compat_urllib_parse.urlencode(fields)
  43. req = compat_urllib_request.Request(url, post)
  44. # Apparently, this header is required for confirmation to work.
  45. req.add_header('Host', 'www.sockshare.com')
  46. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  47. webpage = self._download_webpage(
  48. req, video_id, 'Downloading video page')
  49. video_url = self._html_search_regex(
  50. r'<a href="([^"]*)".+class="download_file_link"',
  51. webpage, 'file url')
  52. video_url = "http://www.sockshare.com" + video_url
  53. title = self._html_search_regex((
  54. r'<h1>(.+)<strong>',
  55. r'var name = "([^"]+)";'),
  56. webpage, 'title', default=None)
  57. thumbnail = self._html_search_regex(
  58. r'<img\s+src="([^"]*)".+?name="bg"',
  59. webpage, 'thumbnail')
  60. formats = [{
  61. 'format_id': 'sd',
  62. 'url': video_url,
  63. 'ext': determine_ext(title),
  64. }]
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'thumbnail': thumbnail,
  69. 'formats': formats,
  70. }