Skip to content

Instantly share code, notes, and snippets.

@imansour12
Created May 14, 2022 22:36
Show Gist options
  • Save imansour12/41f42e3ad4efdefa70a95d04618e7508 to your computer and use it in GitHub Desktop.
Save imansour12/41f42e3ad4efdefa70a95d04618e7508 to your computer and use it in GitHub Desktop.
USAGE: main.py <youtube video url>
import requests
import json
import sys
print("""
_ _ _ _____ _
____ | |(_) | | | _ | | |
/ __ \ __| | _ _ __ | |_ _ _ ___ | |/' | __| | ___
/ / _` | / _` || || '__|| __|| | | | / __|| /| | / _` | / _
| | (_| || (_| || || | | |_ | |_| || (__ \ |_/ /| (_| || __/
\ \__,_| \__,_||_||_| \__| \__, | \___| \___/ \__,_| \___|
\____/ __/ |
|___/
""")
video = sys.argv[1]
url = "https://x2download.com/fr58/download-youtube-to-mp3"
print("Fetching link: ", video)
r = requests.get(url)
print(video)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0',
'Accept': 'text/css,*/*;q=0.1',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'DNT': '1',
'Connection': 'keep-alive',
'Referer': 'https://x2download.com/fr54',
'Sec-Fetch-Dest': 'style',
'Sec-Fetch-Mode': 'no-cors',
'Sec-Fetch-Site': 'same-origin',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'TE': 'trailers',
}
response = requests.get('https://x2download.com/x2download/css/style.min.css?v=15', headers=headers)
print("Fetched CSS with status code", response.status_code)
headers["Sec-Fetch-Dest"] = "script"
headers["Accept"] = "*/*"
response = requests.get('https://x2download.com/x2download/js/app.min.js?v=37', headers=headers)
print("Fetched JavaScript with Status Code: ", response.status_code)
headers["Sec-Fetch-Dest"]= "image"
headers["Referer"] = "https://x2download.com/fr54"
headers["Accept"] = "image/avif,image/webp,*/*"
response = requests.get('https://x2download.com/x2download/imgs/time.png', headers=headers)
print("Fetched Time.png Image successfully with stauts code ", response.status_code)
response = requests.get('https://x2download.com/x2download/imgs/media.png', headers=headers)
print("Fetched media.png successfullly with status code ", response.status_code)
response = requests.get('https://x2download.com/x2download/imgs/convert.png', headers=headers)
print("Fetched Convert.png with status code ", response.status_code)
response = requests.get('https://x2download.com/x2download/imgs/link-solid.png', headers=headers )
print("Fetched Link Solid Image with status code ", response.status_code)
response = requests.get('https://x2download.com/x2download/imgs/settings.png', headers=headers)
print("Fetched Settings.png with status code", response.status_code)
response = requests.get('https://x2download.com/x2download/imgs/download.png', headers=headers)
print("Fetched Download.png with status code ", response.status_code)
response = requests.get('https://x2download.com/Content/default/images/firefox.svg', headers=headers)
print("Fetched Firefox.svg with status code ", response.status_code)
headers["Accept"] = 'text/javascript, application/javascript, application/ecmascript, applicatio n/x-ecmascript, */*; q=0.01'
headers["X-Requested-With"]= "XMLHttpRequest"
headers["Sec-Fetch-Dest"] = "empty"
headers["Sec-Fetch-Mode"] = "same-origin"
response = requests.get('https://x2download.com/x2download/js/common.min.js?v=7', headers=headers)
print("Fetched more JS with status code ", response.status_code)
#HERE IS THE SHIT
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Origin': 'https://x2download.com',
'DNT': '1',
'Connection': 'keep-alive',
'Referer': 'https://x2download.com/fr54',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'TE': 'trailers',
}
response = requests.post('https://x2download.com/api/ajaxSearch', headers=headers, data=f'q={video}&vt=home')
data = json.loads(response.content)
token = data["token"]
vid = data["vid"]
expiration = data["timeExpires"]
print("Video name: ", data["title"])
print("With ID: " , vid)
headers.pop("X-Requested-With")
headers.pop("Referer")
headers["X-Requested-Key"] = "de0cfuirtgf67a"
headers["Sec-Fetch-Site"] = "cross-site"
data = f'v_id={vid}&ftype=mp3&fquality=128&token={token}&timeExpire={expiration}&client=X2Download.com'
response = requests.post('https://backend.svcenter.xyz/api/convert-by-45fc4be8916916ba3b8d61dd6e0d6994', headers=headers, data=data)
data = json.loads(response.content)
print(data["d_url"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment