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.

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