36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import re
|
|
|
|
import requests
|
|
from aniworld.config import DEFAULT_REQUEST_TIMEOUT, RANDOM_USER_AGENT
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
def get_direct_link_from_vidmoly(embeded_vidmoly_link: str):
|
|
response = requests.get(
|
|
embeded_vidmoly_link,
|
|
headers={'User-Agent': RANDOM_USER_AGENT},
|
|
timeout=DEFAULT_REQUEST_TIMEOUT
|
|
)
|
|
html_content = response.text
|
|
soup = BeautifulSoup(html_content, 'html.parser')
|
|
scripts = soup.find_all('script')
|
|
|
|
# Match the ``file:"<url>"`` assignment inside the obfuscated player
|
|
# script so we can recover the direct MP4 source URL.
|
|
file_link_pattern = r'file:\s*"(https?://.*?)"'
|
|
|
|
for script in scripts:
|
|
if script.string:
|
|
match = re.search(file_link_pattern, script.string)
|
|
if match:
|
|
file_link = match.group(1)
|
|
return file_link
|
|
|
|
raise ValueError("No direct link found.")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
link = input("Enter Vidmoly Link: ")
|
|
print('Note: --referer "https://vidmoly.to"')
|
|
print(get_direct_link_from_vidmoly(embeded_vidmoly_link=link))
|