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.

113 lines
3.6 KiB

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