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.

114 lines
3.6 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import time
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. compat_urllib_parse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. )
  12. class MooshareIE(InfoExtractor):
  13. IE_NAME = 'mooshare'
  14. IE_DESC = 'Mooshare.biz'
  15. _VALID_URL = r'http://(?:www\.)?mooshare\.biz/(?P<id>[\da-z]{12})'
  16. _TESTS = [
  17. {
  18. 'url': 'http://mooshare.biz/8dqtk4bjbp8g',
  19. 'md5': '4e14f9562928aecd2e42c6f341c8feba',
  20. 'info_dict': {
  21. 'id': '8dqtk4bjbp8g',
  22. 'ext': 'mp4',
  23. 'title': 'Comedy Football 2011 - (part 1-2)',
  24. 'duration': 893,
  25. },
  26. },
  27. {
  28. 'url': 'http://mooshare.biz/aipjtoc4g95j',
  29. 'info_dict': {
  30. 'id': 'aipjtoc4g95j',
  31. 'ext': 'mp4',
  32. 'title': 'Orange Caramel Dashing Through the Snow',
  33. 'duration': 212,
  34. },
  35. 'params': {
  36. # rtmp download
  37. 'skip_download': True,
  38. }
  39. }
  40. ]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. page = self._download_webpage(url, video_id, 'Downloading page')
  44. if re.search(r'>Video Not Found or Deleted<', page) is not None:
  45. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  46. hash_key = self._html_search_regex(r'<input type="hidden" name="hash" value="([^"]+)">', page, 'hash')
  47. title = self._html_search_regex(r'(?m)<div class="blockTitle">\s*<h2>Watch ([^<]+)</h2>', page, 'title')
  48. download_form = {
  49. 'op': 'download1',
  50. 'id': video_id,
  51. 'hash': hash_key,
  52. }
  53. request = compat_urllib_request.Request(
  54. 'http://mooshare.biz/%s' % video_id, compat_urllib_parse.urlencode(download_form))
  55. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  56. self.to_screen('%s: Waiting for timeout' % video_id)
  57. time.sleep(5)
  58. video_page = self._download_webpage(request, video_id, 'Downloading video page')
  59. thumbnail = self._html_search_regex(r'image:\s*"([^"]+)",', video_page, 'thumbnail', fatal=False)
  60. duration_str = self._html_search_regex(r'duration:\s*"(\d+)",', video_page, 'duration', fatal=False)
  61. duration = int(duration_str) if duration_str is not None else None
  62. formats = []
  63. # SD video
  64. mobj = re.search(r'(?m)file:\s*"(?P<url>[^"]+)",\s*provider:', video_page)
  65. if mobj is not None:
  66. formats.append({
  67. 'url': mobj.group('url'),
  68. 'format_id': 'sd',
  69. 'format': 'SD',
  70. })
  71. # HD video
  72. mobj = re.search(r'\'hd-2\': { file: \'(?P<url>[^\']+)\' },', video_page)
  73. if mobj is not None:
  74. formats.append({
  75. 'url': mobj.group('url'),
  76. 'format_id': 'hd',
  77. 'format': 'HD',
  78. })
  79. # rtmp video
  80. mobj = re.search(r'(?m)file: "(?P<playpath>[^"]+)",\s*streamer: "(?P<rtmpurl>rtmp://[^"]+)",', video_page)
  81. if mobj is not None:
  82. formats.append({
  83. 'url': mobj.group('rtmpurl'),
  84. 'play_path': mobj.group('playpath'),
  85. 'rtmp_live': False,
  86. 'ext': 'mp4',
  87. 'format_id': 'rtmp',
  88. 'format': 'HD',
  89. })
  90. return {
  91. 'id': video_id,
  92. 'title': title,
  93. 'thumbnail': thumbnail,
  94. 'duration': duration,
  95. 'formats': formats,
  96. }