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. from ..utils import (
  4. ExtractorError,
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. determine_ext,
  8. )
  9. import re
  10. from .common import InfoExtractor
  11. class SockshareIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?sockshare\.com/file/(?P<id>[0-9A-Za-z]+)'
  13. _FILE_DELETED_REGEX = r'This file doesn\'t exist, or has been removed\.</div>'
  14. _TEST = {
  15. 'url': 'http://www.sockshare.com/file/437BE28B89D799D7',
  16. 'md5': '9d0bf1cfb6dbeaa8d562f6c97506c5bd',
  17. 'info_dict': {
  18. 'id': '437BE28B89D799D7',
  19. 'title': 'big_buck_bunny_720p_surround.avi',
  20. 'ext': 'avi',
  21. 'thumbnail': 're:^http://.*\.jpg$',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  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,
  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(r'<h1>(.+)<strong>', webpage, 'title')
  53. thumbnail = self._html_search_regex(
  54. r'<img\s+src="([^"]*)".+?name="bg"',
  55. webpage, 'thumbnail')
  56. formats = [{
  57. 'format_id': 'sd',
  58. 'url': video_url,
  59. 'ext': determine_ext(title),
  60. }]
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': thumbnail,
  65. 'formats': formats,
  66. }