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.

93 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. parse_duration,
  11. )
  12. class ShareSixIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?sharesix\.com/(?:f/)?(?P<id>[0-9a-zA-Z]+)'
  14. _TESTS = [
  15. {
  16. 'url': 'http://sharesix.com/f/OXjQ7Y6',
  17. 'md5': '9e8e95d8823942815a7d7c773110cc93',
  18. 'info_dict': {
  19. 'id': 'OXjQ7Y6',
  20. 'ext': 'mp4',
  21. 'title': 'big_buck_bunny_480p_surround-fix.avi',
  22. 'duration': 596,
  23. 'width': 854,
  24. 'height': 480,
  25. },
  26. },
  27. {
  28. 'url': 'http://sharesix.com/lfrwoxp35zdd',
  29. 'md5': 'dd19f1435b7cec2d7912c64beeee8185',
  30. 'info_dict': {
  31. 'id': 'lfrwoxp35zdd',
  32. 'ext': 'flv',
  33. 'title': 'WhiteBoard___a_Mac_vs_PC_Parody_Cartoon.mp4.flv',
  34. 'duration': 65,
  35. 'width': 1280,
  36. 'height': 720,
  37. },
  38. }
  39. ]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. video_id = mobj.group('id')
  43. fields = {
  44. 'method_free': 'Free'
  45. }
  46. post = compat_urllib_parse.urlencode(fields)
  47. req = compat_urllib_request.Request(url, post)
  48. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  49. webpage = self._download_webpage(req, video_id,
  50. 'Downloading video page')
  51. video_url = self._search_regex(
  52. r"var\slnk1\s=\s'([^']+)'", webpage, 'video URL')
  53. title = self._html_search_regex(
  54. r'(?s)<dt>Filename:</dt>.+?<dd>(.+?)</dd>', webpage, 'title')
  55. duration = parse_duration(
  56. self._search_regex(
  57. r'(?s)<dt>Length:</dt>.+?<dd>(.+?)</dd>',
  58. webpage,
  59. 'duration',
  60. fatal=False
  61. )
  62. )
  63. m = re.search(
  64. r'''(?xs)<dt>Width\sx\sHeight</dt>.+?
  65. <dd>(?P<width>\d+)\sx\s(?P<height>\d+)</dd>''',
  66. webpage
  67. )
  68. width = height = None
  69. if m:
  70. width, height = int(m.group('width')), int(m.group('height'))
  71. formats = [{
  72. 'format_id': 'sd',
  73. 'url': video_url,
  74. 'width': width,
  75. 'height': height,
  76. }]
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'duration': duration,
  81. 'formats': formats,
  82. }