xfileshare.py 6.6 KB

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