xfileshare.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. decode_packed_codes,
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. NO_DEFAULT,
  11. sanitized_Request,
  12. urlencode_postdata,
  13. )
  14. class XFileShareIE(InfoExtractor):
  15. _SITES = (
  16. ('daclips.in', 'DaClips'),
  17. ('filehoot.com', 'FileHoot'),
  18. ('gorillavid.in', 'GorillaVid'),
  19. ('movpod.in', 'MovPod'),
  20. ('powerwatch.pw', 'PowerWatch'),
  21. ('rapidvideo.ws', 'Rapidvideo.ws'),
  22. ('thevideobee.to', 'TheVideoBee'),
  23. ('vidto.me', 'Vidto'),
  24. ('streamin.to', 'Streamin.To'),
  25. ('xvidstage.com', 'XVIDSTAGE'),
  26. )
  27. IE_DESC = 'XFileShare based sites: %s' % ', '.join(list(zip(*_SITES))[1])
  28. _VALID_URL = (r'https?://(?P<host>(?:www\.)?(?:%s))/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
  29. % '|'.join(re.escape(site) for site in list(zip(*_SITES))[0]))
  30. _FILE_NOT_FOUND_REGEXES = (
  31. r'>(?:404 - )?File Not Found<',
  32. r'>The file was removed by administrator<',
  33. )
  34. _TESTS = [{
  35. 'url': 'http://gorillavid.in/06y9juieqpmi',
  36. 'md5': '5ae4a3580620380619678ee4875893ba',
  37. 'info_dict': {
  38. 'id': '06y9juieqpmi',
  39. 'ext': 'mp4',
  40. 'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
  41. 'thumbnail': r're:http://.*\.jpg',
  42. },
  43. }, {
  44. 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://daclips.in/3rso4kdn6f9m',
  48. 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
  49. 'info_dict': {
  50. 'id': '3rso4kdn6f9m',
  51. 'ext': 'mp4',
  52. 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
  53. 'thumbnail': r're:http://.*\.jpg',
  54. }
  55. }, {
  56. 'url': 'http://movpod.in/0wguyyxi1yca',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://filehoot.com/3ivfabn7573c.html',
  60. 'info_dict': {
  61. 'id': '3ivfabn7573c',
  62. 'ext': 'mp4',
  63. 'title': 'youtube-dl test video \'äBaW_jenozKc.mp4.mp4',
  64. 'thumbnail': r're:http://.*\.jpg',
  65. },
  66. 'skip': 'Video removed',
  67. }, {
  68. 'url': 'http://vidto.me/ku5glz52nqe1.html',
  69. 'info_dict': {
  70. 'id': 'ku5glz52nqe1',
  71. 'ext': 'mp4',
  72. 'title': 'test'
  73. }
  74. }, {
  75. 'url': 'http://powerwatch.pw/duecjibvicbu',
  76. 'info_dict': {
  77. 'id': 'duecjibvicbu',
  78. 'ext': 'mp4',
  79. 'title': 'Big Buck Bunny trailer',
  80. },
  81. }, {
  82. 'url': 'http://xvidstage.com/e0qcnl03co6z',
  83. 'info_dict': {
  84. 'id': 'e0qcnl03co6z',
  85. 'ext': 'mp4',
  86. 'title': 'Chucky Prank 2015.mp4',
  87. },
  88. }, {
  89. # removed by administrator
  90. 'url': 'http://xvidstage.com/amfy7atlkx25',
  91. 'only_matching': True,
  92. }, {
  93. 'url': 'http://vidabc.com/i8ybqscrphfv',
  94. 'info_dict': {
  95. 'id': 'i8ybqscrphfv',
  96. 'ext': 'mp4',
  97. 'title': 're:Beauty and the Beast 2017',
  98. },
  99. 'params': {
  100. 'skip_download': True,
  101. },
  102. }]
  103. def _real_extract(self, url):
  104. mobj = re.match(self._VALID_URL, url)
  105. video_id = mobj.group('id')
  106. url = 'http://%s/%s' % (mobj.group('host'), video_id)
  107. webpage = self._download_webpage(url, video_id)
  108. if any(re.search(p, webpage) for p in self._FILE_NOT_FOUND_REGEXES):
  109. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  110. fields = self._hidden_inputs(webpage)
  111. if fields['op'] == 'download1':
  112. countdown = int_or_none(self._search_regex(
  113. r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
  114. webpage, 'countdown', default=None))
  115. if countdown:
  116. self._sleep(countdown, video_id)
  117. post = urlencode_postdata(fields)
  118. req = sanitized_Request(url, post)
  119. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  120. webpage = self._download_webpage(req, video_id, 'Downloading video page')
  121. title = (self._search_regex(
  122. (r'style="z-index: [0-9]+;">([^<]+)</span>',
  123. r'<td nowrap>([^<]+)</td>',
  124. r'h4-fine[^>]*>([^<]+)<',
  125. r'>Watch (.+) ',
  126. r'<h2 class="video-page-head">([^<]+)</h2>',
  127. r'<h2 style="[^"]*color:#403f3d[^"]*"[^>]*>([^<]+)<'), # streamin.to
  128. webpage, 'title', default=None) or self._og_search_title(
  129. webpage, default=None) or video_id).strip()
  130. def extract_formats(default=NO_DEFAULT):
  131. urls = []
  132. for regex in (
  133. r'file\s*:\s*(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1',
  134. r'file_link\s*=\s*(["\'])(?P<url>http(?:(?!\1).)+)\1',
  135. r'addVariable\((\\?["\'])file\1\s*,\s*(\\?["\'])(?P<url>http(?:(?!\2).)+)\2\)',
  136. r'<embed[^>]+src=(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1'):
  137. for mobj in re.finditer(regex, webpage):
  138. video_url = mobj.group('url')
  139. if video_url not in urls:
  140. urls.append(video_url)
  141. formats = []
  142. for video_url in urls:
  143. if determine_ext(video_url) == 'm3u8':
  144. formats.extend(self._extract_m3u8_formats(
  145. video_url, video_id, 'mp4',
  146. entry_protocol='m3u8_native', m3u8_id='hls',
  147. fatal=False))
  148. else:
  149. formats.append({
  150. 'url': video_url,
  151. 'format_id': 'sd',
  152. })
  153. if not formats and default is not NO_DEFAULT:
  154. return default
  155. self._sort_formats(formats)
  156. return formats
  157. formats = extract_formats(default=None)
  158. if not formats:
  159. webpage = decode_packed_codes(self._search_regex(
  160. r"(}\('(.+)',(\d+),(\d+),'[^']*\b(?:file|embed)\b[^']*'\.split\('\|'\))",
  161. webpage, 'packed code'))
  162. formats = extract_formats()
  163. thumbnail = self._search_regex(
  164. r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', default=None)
  165. return {
  166. 'id': video_id,
  167. 'title': title,
  168. 'thumbnail': thumbnail,
  169. 'formats': formats,
  170. }