mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Directly parse js.
This commit is contained in:
parent
ade82ddcf2
commit
4663fefaeb
@ -7,12 +7,12 @@ import logging
|
|||||||
|
|
||||||
# External libraries
|
# External libraries
|
||||||
import httpx
|
import httpx
|
||||||
|
import jsbeautifier
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from Src.Util.headers import get_headers
|
from Src.Util.headers import get_headers
|
||||||
from Src.Util.os import run_node_script, run_node_script_api
|
|
||||||
|
|
||||||
|
|
||||||
class VideoSource:
|
class VideoSource:
|
||||||
@ -119,14 +119,7 @@ class VideoSource:
|
|||||||
"""
|
"""
|
||||||
for script in soup.find_all("script"):
|
for script in soup.find_all("script"):
|
||||||
if "eval" in str(script):
|
if "eval" in str(script):
|
||||||
|
return jsbeautifier.beautify(script.text)
|
||||||
# WITH INSTALL NODE JS
|
|
||||||
#new_script = str(script.text).replace("eval", "var a = ")
|
|
||||||
#new_script = new_script.replace(")))", ")));console.log(a);")
|
|
||||||
#return run_node_script(new_script)
|
|
||||||
|
|
||||||
# WITH API
|
|
||||||
return run_node_script_api(script.text)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -170,13 +163,14 @@ class VideoSource:
|
|||||||
logging.error("Failed to fetch supervideo content.")
|
logging.error("Failed to fetch supervideo content.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = self.get_result_node_js(supervideo_soup)
|
# Find master playlist
|
||||||
if not result:
|
data_js = self.get_result_node_js(supervideo_soup)
|
||||||
logging.error("No video URL found in script.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
master_playlist = str(result).split(":")[3].split('"}')[0]
|
match = re.search(r'sources:\s*\[\{\s*file:\s*"([^"]+)"', data_js)
|
||||||
return f"https:{master_playlist}"
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"An error occurred: {e}")
|
logging.error(f"An error occurred: {e}")
|
||||||
|
@ -7,12 +7,12 @@ import logging
|
|||||||
|
|
||||||
# External libraries
|
# External libraries
|
||||||
import httpx
|
import httpx
|
||||||
|
import jsbeautifier
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from Src.Util.headers import get_headers
|
from Src.Util.headers import get_headers
|
||||||
from Src.Util.os import run_node_script, run_node_script_api
|
|
||||||
|
|
||||||
|
|
||||||
class VideoSource:
|
class VideoSource:
|
||||||
@ -121,14 +121,14 @@ class VideoSource:
|
|||||||
for script in soup.find_all("script"):
|
for script in soup.find_all("script"):
|
||||||
if "eval(function(p,a,c,k,e,d)" in script.text:
|
if "eval(function(p,a,c,k,e,d)" in script.text:
|
||||||
|
|
||||||
# Execute the script using the run_node_script_api function
|
# Execute the script using
|
||||||
text_run_node_js = run_node_script_api(script.text)
|
data_js = jsbeautifier.beautify(script.text)
|
||||||
|
|
||||||
# Extract the .m3u8 URL from the script's output
|
# Extract the .m3u8 URL from the script's output
|
||||||
m3u8_match = re.search(r'src:"(https://.*?\.m3u8)"', text_run_node_js)
|
match = re.search(r'sources:\s*\[\{\s*src:\s*"([^"]+)"', data_js)
|
||||||
|
|
||||||
if m3u8_match:
|
if match:
|
||||||
self.m3u8_url = m3u8_match.group(1)
|
self.m3u8_url = match.group(1)
|
||||||
logging.info(f"M3U8 URL: {self.m3u8_url}")
|
logging.info(f"M3U8 URL: {self.m3u8_url}")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
# 26.05.24
|
# 26.05.24
|
||||||
|
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
# External libraries
|
# External libraries
|
||||||
import httpx
|
import httpx
|
||||||
|
import jsbeautifier
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from Src.Util.headers import get_headers
|
from Src.Util.headers import get_headers
|
||||||
from Src.Util.os import run_node_script, run_node_script_api
|
|
||||||
|
|
||||||
|
|
||||||
class VideoSource:
|
class VideoSource:
|
||||||
@ -84,14 +85,7 @@ class VideoSource:
|
|||||||
"""
|
"""
|
||||||
for script in soup.find_all("script"):
|
for script in soup.find_all("script"):
|
||||||
if "eval" in str(script):
|
if "eval" in str(script):
|
||||||
|
return jsbeautifier.beautify(script.text)
|
||||||
# WITH INSTALL NODE JS
|
|
||||||
#new_script = str(script.text).replace("eval", "var a = ")
|
|
||||||
#new_script = new_script.replace(")))", ")));console.log(a);")
|
|
||||||
#return run_node_script(new_script)
|
|
||||||
|
|
||||||
# WITH API
|
|
||||||
return run_node_script_api(script.text)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -113,13 +107,14 @@ class VideoSource:
|
|||||||
logging.error("Failed to parse HTML content.")
|
logging.error("Failed to parse HTML content.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = self.get_result_node_js(soup)
|
# Find master playlist
|
||||||
if not result:
|
data_js = self.get_result_node_js(soup)
|
||||||
logging.error("No video URL found in script.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
master_playlist = str(result).split(":")[3].split('"}')[0]
|
match = re.search(r'sources:\s*\[\{\s*file:\s*"([^"]+)"', data_js)
|
||||||
return f"https:{master_playlist}"
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"An error occurred: {e}")
|
logging.error(f"An error occurred: {e}")
|
||||||
|
129
Src/Util/os.py
129
Src/Util/os.py
@ -341,135 +341,6 @@ def get_system_summary():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --> OS MANAGE NODE JS
|
|
||||||
def is_node_installed() -> bool:
|
|
||||||
"""
|
|
||||||
Checks if Node.js is installed on the system.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: True if Node.js is installed, False otherwise.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# Run the command 'node -v' to get the Node.js version
|
|
||||||
result = subprocess.run(['node', '-v'], capture_output=True, text=True, check=True)
|
|
||||||
|
|
||||||
# If the command runs successfully and returns a version number, Node.js is installed
|
|
||||||
if result.stdout.startswith('v'):
|
|
||||||
return True
|
|
||||||
|
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
||||||
# If there is an error running the command or the command is not found, Node.js is not installed
|
|
||||||
return False
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def run_node_script(script_content: str) -> str:
|
|
||||||
"""
|
|
||||||
Runs a Node.js script and returns its output.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
script_content (str): The content of the Node.js script to run.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: The output of the Node.js script.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Check if Node.js is installed
|
|
||||||
if not is_node_installed():
|
|
||||||
raise EnvironmentError("Node.js is not installed on the system.")
|
|
||||||
|
|
||||||
# Write the script content to a temporary file
|
|
||||||
with open('script.js', 'w') as file:
|
|
||||||
file.write(script_content)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Run the Node.js script using subprocess and capture the output
|
|
||||||
result = subprocess.run(['node', 'script.js'], capture_output=True, text=True, check=True)
|
|
||||||
return result.stdout
|
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
raise RuntimeError(f"Error running Node.js script: {e.stderr}")
|
|
||||||
|
|
||||||
finally:
|
|
||||||
# Clean up the temporary script file
|
|
||||||
import os
|
|
||||||
os.remove('script.js')
|
|
||||||
|
|
||||||
def run_node_script_api(script_content: str) -> str:
|
|
||||||
"""
|
|
||||||
Runs a Node.js script and returns its output.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
script_content (str): The content of the Node.js script to run.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: The output of the Node.js script.
|
|
||||||
"""
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
'accept': '*/*',
|
|
||||||
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
|
|
||||||
'dnt': '1',
|
|
||||||
'origin': 'https://onecompiler.com',
|
|
||||||
'priority': 'u=1, i',
|
|
||||||
'referer': 'https://onecompiler.com/javascript',
|
|
||||||
'user-agent': get_headers()
|
|
||||||
}
|
|
||||||
|
|
||||||
json_data = {
|
|
||||||
'name': 'JavaScript',
|
|
||||||
'title': '42gyum6qn',
|
|
||||||
'version': 'ES6',
|
|
||||||
'mode': 'javascript',
|
|
||||||
'description': None,
|
|
||||||
'extension': 'js',
|
|
||||||
'languageType': 'programming',
|
|
||||||
'active': False,
|
|
||||||
'properties': {
|
|
||||||
'language': 'javascript',
|
|
||||||
'docs': False,
|
|
||||||
'tutorials': False,
|
|
||||||
'cheatsheets': False,
|
|
||||||
'filesEditable': False,
|
|
||||||
'filesDeletable': False,
|
|
||||||
'files': [
|
|
||||||
{
|
|
||||||
'name': 'index.js',
|
|
||||||
'content': script_content
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'newFileOptions': [
|
|
||||||
{
|
|
||||||
'helpText': 'New JS file',
|
|
||||||
'name': 'script${i}.js',
|
|
||||||
'content': "/**\n * In main file\n * let script${i} = require('./script${i}');\n * console.log(script${i}.sum(1, 2));\n */\n\nfunction sum(a, b) {\n return a + b;\n}\n\nmodule.exports = { sum };",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'helpText': 'Add Dependencies',
|
|
||||||
'name': 'package.json',
|
|
||||||
'content': '{\n "name": "main_app",\n "version": "1.0.0",\n "description": "",\n "main": "HelloWorld.js",\n "dependencies": {\n "lodash": "^4.17.21"\n }\n}',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'_id': '42gcvpkbg_42gyuud7m',
|
|
||||||
'user': None,
|
|
||||||
'visibility': 'public',
|
|
||||||
}
|
|
||||||
|
|
||||||
# Return error
|
|
||||||
response = httpx.post('https://onecompiler.com/api/code/exec', headers=headers, json=json_data, timeout=15)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
return str(response.json()['stderr']).split("\n")[1]
|
|
||||||
|
|
||||||
else:
|
|
||||||
logging.error("Cant connect to site: onecompiler.com")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --> OS FILE VALIDATOR
|
# --> OS FILE VALIDATOR
|
||||||
|
|
||||||
# List of invalid characters for Windows filenames
|
# List of invalid characters for Windows filenames
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
"domain": "to"
|
"domain": "to"
|
||||||
},
|
},
|
||||||
"cb01": {
|
"cb01": {
|
||||||
"domain": "ventures"
|
"domain": "software"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user