xfileshare.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. decode_packed_codes,
  6. determine_ext,
  7. int_or_none,
  8. js_to_json,
  9. urlencode_postdata,
  10. )
  11. # based on openload_decode from 2bfeee69b976fe049761dd3012e30b637ee05a58
  12. def aa_decode(aa_code):
  13. symbol_table = [
  14. ('7', '((゚ー゚) + (o^_^o))'),
  15. ('6', '((o^_^o) +(o^_^o))'),
  16. ('5', '((゚ー゚) + (゚Θ゚))'),
  17. ('2', '((o^_^o) - (゚Θ゚))'),
  18. ('4', '(゚ー゚)'),
  19. ('3', '(o^_^o)'),
  20. ('1', '(゚Θ゚)'),
  21. ('0', '(c^_^o)'),
  22. ]
  23. delim = '(゚Д゚)[゚ε゚]+'
  24. ret = ''
  25. for aa_char in aa_code.split(delim):
  26. for val, pat in symbol_table:
  27. aa_char = aa_char.replace(pat, val)
  28. aa_char = aa_char.replace('+ ', '')
  29. m = re.match(r'^\d+', aa_char)
  30. if m:
  31. ret += chr(int(m.group(0), 8))
  32. else:
  33. m = re.match(r'^u([\da-f]+)', aa_char)
  34. if m:
  35. ret += chr(int(m.group(1), 16))
  36. return ret
  37. class XFileShareIE(InfoExtractor):
  38. _SITES = (
  39. (r'aparat\.cam', 'Aparat'),
  40. (r'clipwatching\.com', 'ClipWatching'),
  41. (r'gounlimited\.to', 'GoUnlimited'),
  42. (r'govid\.me', 'GoVid'),
  43. (r'holavid\.com', 'HolaVid'),
  44. (r'streamty\.com', 'Streamty'),
  45. (r'thevideobee\.to', 'TheVideoBee'),
  46. (r'uqload\.com', 'Uqload'),
  47. (r'vidbom\.com', 'VidBom'),
  48. (r'vidlo\.us', 'vidlo'),
  49. (r'vidlocker\.xyz', 'VidLocker'),
  50. (r'vidshare\.tv', 'VidShare'),
  51. (r'vup\.to', 'VUp'),
  52. (r'wolfstream\.tv', 'WolfStream'),
  53. (r'xvideosharing\.com', 'XVideoSharing'),
  54. )
  55. IE_DESC = 'XFileShare based sites: %s' % ', '.join(list(zip(*_SITES))[1])
  56. _VALID_URL = (r'https?://(?:www\.)?(?P<host>%s)/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
  57. % '|'.join(site for site in list(zip(*_SITES))[0]))
  58. _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:%s)/embed-[0-9a-zA-Z]+.*?)\1' % '|'.join(site for site in list(zip(*_SITES))[0])]
  59. _FILE_NOT_FOUND_REGEXES = (
  60. r'>(?:404 - )?File Not Found<',
  61. r'>The file was removed by administrator<',
  62. )
  63. _TESTS = [{
  64. 'url': 'https://uqload.com/dltx1wztngdz',
  65. 'md5': '3cfbb65e4c90e93d7b37bcb65a595557',
  66. 'info_dict': {
  67. 'id': 'dltx1wztngdz',
  68. 'ext': 'mp4',
  69. 'title': 'Rick Astley Never Gonna Give You mp4',
  70. 'thumbnail': r're:https://.*\.jpg'
  71. }
  72. }, {
  73. 'url': 'http://xvideosharing.com/fq65f94nd2ve',
  74. 'md5': '4181f63957e8fe90ac836fa58dc3c8a6',
  75. 'info_dict': {
  76. 'id': 'fq65f94nd2ve',
  77. 'ext': 'mp4',
  78. 'title': 'sample',
  79. 'thumbnail': r're:http://.*\.jpg',
  80. },
  81. }, {
  82. 'url': 'https://aparat.cam/n4d6dh0wvlpr',
  83. 'only_matching': True,
  84. }, {
  85. 'url': 'https://wolfstream.tv/nthme29v9u2x',
  86. 'only_matching': True,
  87. }]
  88. def _real_extract(self, url):
  89. host, video_id = self._match_valid_url(url).groups()
  90. url = 'https://%s/' % host + ('embed-%s.html' % video_id if host in ('govid.me', 'vidlo.us') else video_id)
  91. webpage = self._download_webpage(url, video_id)
  92. if any(re.search(p, webpage) for p in self._FILE_NOT_FOUND_REGEXES):
  93. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  94. fields = self._hidden_inputs(webpage)
  95. if fields.get('op') == 'download1':
  96. countdown = int_or_none(self._search_regex(
  97. r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
  98. webpage, 'countdown', default=None))
  99. if countdown:
  100. self._sleep(countdown, video_id)
  101. webpage = self._download_webpage(
  102. url, video_id, 'Downloading video page',
  103. data=urlencode_postdata(fields), headers={
  104. 'Referer': url,
  105. 'Content-type': 'application/x-www-form-urlencoded',
  106. })
  107. title = (self._search_regex(
  108. (r'style="z-index: [0-9]+;">([^<]+)</span>',
  109. r'<td nowrap>([^<]+)</td>',
  110. r'h4-fine[^>]*>([^<]+)<',
  111. r'>Watch (.+)[ <]',
  112. r'<h2 class="video-page-head">([^<]+)</h2>',
  113. r'<h2 style="[^"]*color:#403f3d[^"]*"[^>]*>([^<]+)<', # streamin.to
  114. r'title\s*:\s*"([^"]+)"'), # govid.me
  115. webpage, 'title', default=None) or self._og_search_title(
  116. webpage, default=None) or video_id).strip()
  117. for regex, func in (
  118. (r'(eval\(function\(p,a,c,k,e,d\){.+)', decode_packed_codes),
  119. (r'(゚.+)', aa_decode)):
  120. obf_code = self._search_regex(regex, webpage, 'obfuscated code', default=None)
  121. if obf_code:
  122. webpage = webpage.replace(obf_code, func(obf_code))
  123. formats = []
  124. jwplayer_data = self._search_regex(
  125. [
  126. r'jwplayer\("[^"]+"\)\.load\(\[({.+?})\]\);',
  127. r'jwplayer\("[^"]+"\)\.setup\(({.+?})\);',
  128. ], webpage,
  129. 'jwplayer data', default=None)
  130. if jwplayer_data:
  131. jwplayer_data = self._parse_json(
  132. jwplayer_data.replace(r"\'", "'"), video_id, js_to_json)
  133. if jwplayer_data:
  134. formats = self._parse_jwplayer_data(
  135. jwplayer_data, video_id, False,
  136. m3u8_id='hls', mpd_id='dash')['formats']
  137. if not formats:
  138. urls = []
  139. for regex in (
  140. r'(?:file|src)\s*:\s*(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1',
  141. r'file_link\s*=\s*(["\'])(?P<url>http(?:(?!\1).)+)\1',
  142. r'addVariable\((\\?["\'])file\1\s*,\s*(\\?["\'])(?P<url>http(?:(?!\2).)+)\2\)',
  143. r'<embed[^>]+src=(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1'):
  144. for mobj in re.finditer(regex, webpage):
  145. video_url = mobj.group('url')
  146. if video_url not in urls:
  147. urls.append(video_url)
  148. sources = self._search_regex(
  149. r'sources\s*:\s*(\[(?!{)[^\]]+\])', webpage, 'sources', default=None)
  150. if sources:
  151. urls.extend(self._parse_json(sources, video_id))
  152. formats = []
  153. for video_url in urls:
  154. if determine_ext(video_url) == 'm3u8':
  155. formats.extend(self._extract_m3u8_formats(
  156. video_url, video_id, 'mp4',
  157. entry_protocol='m3u8_native', m3u8_id='hls',
  158. fatal=False))
  159. else:
  160. formats.append({
  161. 'url': video_url,
  162. 'format_id': 'sd',
  163. })
  164. thumbnail = self._search_regex(
  165. [
  166. r'<video[^>]+poster="([^"]+)"',
  167. r'(?:image|poster)\s*:\s*["\'](http[^"\']+)["\'],',
  168. ], webpage, 'thumbnail', default=None)
  169. return {
  170. 'id': video_id,
  171. 'title': title,
  172. 'thumbnail': thumbnail,
  173. 'formats': formats,
  174. 'http_headers': {'Referer': url}
  175. }