Last active
August 15, 2024 11:05
-
-
Save Xnuvers007/67ab9f62205e67502865f452abbaa892 to your computer and use it in GitHub Desktop.
y2mate Xnuvers007 Youtube Downloader with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import urllib.parse | |
from random import choice | |
urls = [ | |
'https://en.y2mate.is/v84/', | |
'https://de.y2mate.is/v84/', | |
'https://es.y2mate.is/v84/', | |
'https://tl.y2mate.is/v84/', | |
'https://fr.y2mate.is/v84/', | |
'https://hi.y2mate.is/v84/', | |
'https://id.y2mate.is/v84/', | |
'https://it.y2mate.is/v84/', | |
'https://ms.y2mate.is/v84/', | |
'https://ja.y2mate.is/v84/', | |
'https://ko.y2mate.is/v84/', | |
'https://ru.y2mate.is/v84/', | |
'https://pt.y2mate.is/v84/', | |
'https://tr.y2mate.is/v84/', | |
'https://th.y2mate.is/v84/', | |
'https://ar.y2mate.is/v84/' | |
] | |
base_url = choice(urls) | |
for_origin = f"{base_url}"[:-4] | |
cookies = { | |
'XSRF-TOKEN': 'eyJpdiI6ImZTTmliMnJweHQxODBFWDBESTQrTnc9PSIsInZhbHVlIjoidU56cm45TlNhaWNqZ0c4ZkE2eGZVdFZ4c1ZodURxSWRTaW5QZnpTcnFGRkoySWRDRk5YUEtqRzc2dDB5SmUyWG9JWHF6eWdTY29kemlYc0ZqYXdWNmZOR0dJWEtpY2dJMUdmNkxvVlNBL2xhM1JrUk5pNHpiajNyNzlJeGNPMUwiLCJtYWMiOiJiZjYwZTZlMjg0NDA3OTcxOThkNGRkNzdkZGUzNGRhMGI1OGJiODljZDU1Y2JlMzg1MjY2ZjVhYjljN2Y5OTk4IiwidGFnIjoiIn0%3D', | |
'y2mate_session': 'eyJpdiI6IjFPa2dZeG8za2crNXU3VG9yQSt2VWc9PSIsInZhbHVlIjoiaG43YU5GaFlGSjd3U1RtNzZFSEU1QUNHTVhLN2dlZ2YyYUIwYTZtbDA3My9lMmFQeEYxNmdxTGVrSGVydmxXNkhrRmMrc3hXSnczZ09CMTNrU01rLytlSUdiUDd2Y2lFMyszcDF0UElBM3dFRlpsZjdJQ3JGUW9heTRzMXRpaSsiLCJtYWMiOiJmYTdhMWYwYWJlYTQ4ODIzYTE1Njc5NzU2NzNhNGU4YjEyMmM2ZmU2YzgwNmVkMGI4YmQ2ZDQzYjNjNzZhYWYzIiwidGFnIjoiIn0%3D', | |
} | |
headers = { | |
'accept': 'application/json, text/javascript, */*; q=0.01', | |
'accept-language': 'en-US,en;q=0.9', | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'origin': for_origin, | |
'priority': 'u=1, i', | |
'referer': base_url, | |
'sec-ch-ua': '"Not)A;Brand";v="99", "Brave";v="127", "Chromium";v="127"', | |
'sec-ch-ua-mobile': '?0', | |
'sec-ch-ua-platform': '"Windows"', | |
'sec-fetch-dest': 'empty', | |
'sec-fetch-mode': 'cors', | |
'sec-fetch-site': 'same-origin', | |
'sec-gpc': '1', | |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36', | |
'x-csrf-token': '92qyQc6pdt4Xo3zbUpmfSsSkP2GNtO3U3C82Ha5A', | |
'x-requested-with': 'XMLHttpRequest', | |
} | |
data = { | |
'url': 'https://www.youtube.com/watch?v=SidSBF5GSDM', | |
} | |
try: | |
response = requests.post('https://id.y2mate.is/analyze', cookies=cookies, headers=headers, data=data) | |
response.raise_for_status() | |
result = response.json() | |
if not result.get("error"): | |
formats = result.get("formats", {}) | |
video_id = formats.get("videoId") | |
title = formats.get("title") | |
thumbnail = formats.get("thumbnail") | |
duration = formats.get("duration") | |
print(f"Video ID: {video_id}") | |
print(f"Title: {title}") | |
print(f"Thumbnail: {thumbnail}") | |
print(f"Duration: {duration}") | |
print("\nVideo Formats:") | |
video_formats = formats.get("video", []) | |
for video in video_formats: | |
hash_value = video.get("hash") | |
if hash_value: | |
cookiesconvert = { | |
'XSRF-TOKEN': 'eyJpdiI6Im83SWM3ZTh2NVNHVTdHdy9uL2N1eEE9PSIsInZhbHVlIjoiSUFpd3l0UkZNT2NjZVdOOWdoeUxLSFhTNWZyWm9hY25zZC9nWlg5WVI1U0RPcUhVdURreGl3WmlGUERDY0N6bW9hZU9jMVRMck1GVjZDRWN5WGprdEl2dzNEeUJCbnZ5ZmczdWJQVTAxK1R0Y1RBNEkxcWFHOWNwcTJUNVlFeVMiLCJtYWMiOiJiZGVlYzQ2MThlNzRjN2IyOWUyYjFlYmJjYjQzZDVlNzdhZTYwZDIzOTdlZWVmMDg2OTJkMDNmZGNmNDc1NGYxIiwidGFnIjoiIn0%3D', | |
'y2mate_session': 'eyJpdiI6Ii9UMkhvT2dzU0pwcDNrWE5iZUU2V0E9PSIsInZhbHVlIjoielJpUys0UVFOVEJlM1ZmZnZFdVVJVEJoOXZFZFMybkQ4dTNnWWIxdnY4VG1QWU5sQzBLelM3TnQrOWc0aVo1ak9VOFUraWdWMmwyWStnZkdoQ1MwVDgxbXF3TWxobmtTblVGMEc3aGZXQnJZK1E1MkJUOHJucnFOS2hHM1MzdVoiLCJtYWMiOiJhNTFhZjNiYjM1ZjVmYjIwMTM0ZDlkZDE5ZjY2NTcwNzc3YjhlOTRkMmM2ZGEzYmVhMGIwMzQ5YWM4YmJjM2E2IiwidGFnIjoiIn0%3D', | |
} | |
headersconvert = { | |
'accept': '*/*', | |
'accept-language': 'en-US,en;q=0.9', | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'origin': for_origin, | |
'priority': 'u=1, i', | |
'referer': base_url, | |
'sec-ch-ua': '"Not)A;Brand";v="99", "Brave";v="127", "Chromium";v="127"', | |
'sec-ch-ua-mobile': '?0', | |
'sec-ch-ua-platform': '"Windows"', | |
'sec-fetch-dest': 'empty', | |
'sec-fetch-mode': 'cors', | |
'sec-fetch-site': 'same-origin', | |
'sec-gpc': '1', | |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36', | |
'x-csrf-token': '92qyQc6pdt4Xo3zbUpmfSsSkP2GNtO3U3C82Ha5A', | |
'x-requested-with': 'XMLHttpRequest', | |
} | |
hash_response = requests.post('https://id.y2mate.is/convert', cookies=cookiesconvert, headers=headersconvert, data={'hash': hash_value}) | |
hash_response.raise_for_status() | |
hash_result = hash_response.json() | |
task_id = hash_result.get("taskId") | |
while task_id: | |
task_response = requests.post('https://id.y2mate.is/task', cookies=cookiesconvert, headers=headersconvert, data={'taskId': task_id}) | |
task_response.raise_for_status() | |
task_result = task_response.json() | |
status = task_result.get("status") | |
if status == "finished": | |
download_url = urllib.parse.unquote(task_result.get("download", "")) | |
print(f"Quality: {video.get('quality')}, File Type: {video.get('fileType')}, Filesize: {video.get('filesize')}") | |
print(f"File URL: {download_url}") | |
break | |
print("\nAudio Formats:") | |
audio_formats = formats.get("audio", []) | |
for audio in audio_formats: | |
hash_value = audio.get("hash") | |
if hash_value: | |
hash_response = requests.post('https://id.y2mate.is/convert', cookies=cookiesconvert, headers=headersconvert, data={'hash': hash_value}) | |
hash_response.raise_for_status() | |
hash_result = hash_response.json() | |
task_id = hash_result.get("taskId") | |
while task_id: | |
task_response = requests.post('https://id.y2mate.is/task', cookies=cookiesconvert, headers=headersconvert, data={'taskId': task_id}) | |
task_response.raise_for_status() | |
task_result = task_response.json() | |
status = task_result.get("status") | |
if status == "finished": | |
download_url = urllib.parse.unquote(task_result.get("download", "")) | |
print(f"Quality: {audio.get('quality')} kbps, File Type: {audio.get('fileType')}, Filesize: {audio.get('filesize')}") | |
print(f"File URL: {download_url}") | |
break | |
else: | |
print("Error:", result.get("error_message")) | |
except requests.RequestException as e: | |
print("An error occurred:", e) | |
except ValueError as e: | |
print("Error parsing JSON:", e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
import requests | |
import urllib.parse, random | |
# from random import choice | |
app = Flask(__name__) | |
# List of URLs to choose from | |
urls = [ | |
'https://en.y2mate.is/v84/', | |
'https://de.y2mate.is/v84/', | |
'https://es.y2mate.is/v84/', | |
'https://tl.y2mate.is/v84/', | |
'https://fr.y2mate.is/v84/', | |
'https://hi.y2mate.is/v84/', | |
'https://id.y2mate.is/v84/', | |
'https://it.y2mate.is/v84/', | |
'https://ms.y2mate.is/v84/', | |
'https://ja.y2mate.is/v84/', | |
'https://ko.y2mate.is/v84/', | |
'https://ru.y2mate.is/v84/', | |
'https://pt.y2mate.is/v84/', | |
'https://tr.y2mate.is/v84/', | |
'https://th.y2mate.is/v84/', | |
'https://ar.y2mate.is/v84/' | |
] | |
def get_base_url(): | |
return random.choice(urls) | |
@app.route('/ytdl', methods=['GET']) | |
def ytdl(): | |
user_url = request.args.get('url') | |
if not user_url: | |
return jsonify({'error': 'URL parameter is missing'}), 400 | |
base_url = get_base_url() | |
for_origin = f"{base_url}"[:-4] | |
cookies = { | |
'XSRF-TOKEN': 'eyJpdiI6ImZTTmliMnJweHQxODBFWDBESTQrTnc9PSIsInZhbHVlIjoidU56cm45TlNhaWNqZ0c4ZkE2eGZVdFZ4c1ZodURxSWRTaW5QZnpTcnFGRkoySWRDRk5YUEtqRzc2dDB5SmUyWG9JWHF6eWdTY29kemlYc0ZqYXdWNmZOR0dJWEtpY2dJMUdmNkxvVlNBL2xhM1JrUk5pNHpiajNyNzlJeGNPMUwiLCJtYWMiOiJiZjYwZTZlMjg0NDA3OTcxOThkNGRkNzdkZGUzNGRhMGI1OGJiODljZDU1Y2JlMzg1MjY2ZjVhYjljN2Y5OTk4IiwidGFnIjoiIn0%3D', | |
'y2mate_session': 'eyJpdiI6IjFPa2dZeG8za2crNXU3VG9yQSt2VWc9PSIsInZhbHVlIjoiaG43YU5GaFlGSjd3U1RtNzZFSEU1QUNHTVhLN2dlZ2YyYUIwYTZtbDA3My9lMmFQeEYxNmdxTGVrSGVydmxXNkhrRmMrc3hXSnczZ09CMTNrU01rLytlSUdiUDd2Y2lFMyszcDF0UElBM3dFRlpsZjdJQ3JGUW9heTRzMXRpaSsiLCJtYWMiOiJmYTdhMWYwYWJlYTQ4ODIzYTE1Njc5NzU2NzNhNGU4YjEyMmM2ZmU2YzgwNmVkMGI4YmQ2ZDQzYjNjNzZhYWYzIiwidGFnIjoiIn0%3D', | |
} | |
headers = { | |
'accept': 'application/json, text/javascript, */*; q=0.01', | |
'accept-language': 'en-US,en;q=0.9', | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'origin': for_origin, | |
'priority': 'u=1, i', | |
'referer': base_url, | |
'sec-ch-ua': '"Not)A;Brand";v="99", "Brave";v="127", "Chromium";v="127"', | |
'sec-ch-ua-mobile': '?0', | |
'sec-ch-ua-platform': '"Windows"', | |
'sec-fetch-dest': 'empty', | |
'sec-fetch-mode': 'cors', | |
'sec-fetch-site': 'same-origin', | |
'sec-gpc': '1', | |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36', | |
'x-csrf-token': '92qyQc6pdt4Xo3zbUpmfSsSkP2GNtO3U3C82Ha5A', | |
'x-requested-with': 'XMLHttpRequest', | |
} | |
data = { | |
'url': user_url, | |
} | |
try: | |
response = requests.post(f'{for_origin}analyze', cookies=cookies, headers=headers, data=data) | |
response.raise_for_status() | |
result = response.json() | |
if not result.get("error"): | |
formats = result.get("formats", {}) | |
video_id = formats.get("videoId") | |
title = formats.get("title") | |
thumbnail = formats.get("thumbnail") | |
duration = formats.get("duration") | |
video_formats = [] | |
video_list = formats.get("video", []) | |
for video in video_list: | |
hash_value = video.get("hash") | |
if hash_value: | |
cookiesconvert = { | |
'XSRF-TOKEN': 'eyJpdiI6Im83SWM3ZTh2NVNHVTdHdy9uL2N1eEE9PSIsInZhbHVlIjoiSUFpd3l0UkZNT2NjZVdOOWdoeUxLSFhTNWZyWm9hY25zZC9nWlg5WVI1U0RPcUhVdURreGl3WmlGUERDY0N6bW9hZU9jMVRMck1GVjZDRWN5WGprdEl2dzNEeUJCbnZ5ZmczdWJQVTAxK1R0Y1RBNEkxcWFHOWNwcTJUNVlFeVMiLCJtYWMiOiJiZGVlYzQ2MThlNzRjN2IyOWUyYjFlYmJjYjQzZDVlNzdhZTYwZDIzOTdlZWVmMDg2OTJkMDNmZGNmNDc1NGYxIiwidGFnIjoiIn0%3D', | |
'y2mate_session': 'eyJpdiI6Ii9UMkhvT2dzU0pwcDNrWE5iZUU2V0E9PSIsInZhbHVlIjoielJpUys0UVFOVEJlM1ZmZnZFdVVJVEJoOXZFZFMybkQ4dTNnWWIxdnY4VG1QWU5sQzBLelM3TnQrOWc0aVo1ak9VOFUraWdWMmwyWStnZkdoQ1MwVDgxbXF3TWxobmtTblVGMEc3aGZXQnJZK1E1MkJUOHJucnFOS2hHM1MzdVoiLCJtYWMiOiJhNTFhZjNiYjM1ZjVmYjIwMTM0ZDlkZDE5ZjY2NTcwNzc3YjhlOTRkMmM2ZGEzYmVhMGIwMzQ5YWM4YmJjM2E2IiwidGFnIjoiIn0%3D', | |
} | |
headersconvert = { | |
'accept': '*/*', | |
'accept-language': 'en-US,en;q=0.9', | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'origin': for_origin, | |
'priority': 'u=1, i', | |
'referer': base_url, | |
'sec-ch-ua': '"Not)A;Brand";v="99", "Brave";v="127", "Chromium";v="127"', | |
'sec-ch-ua-mobile': '?0', | |
'sec-ch-ua-platform': '"Windows"', | |
'sec-fetch-dest': 'empty', | |
'sec-fetch-mode': 'cors', | |
'sec-fetch-site': 'same-origin', | |
'sec-gpc': '1', | |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36', | |
'x-csrf-token': '92qyQc6pdt4Xo3zbUpmfSsSkP2GNtO3U3C82Ha5A', | |
'x-requested-with': 'XMLHttpRequest', | |
} | |
hash_response = requests.post(f'{for_origin}convert', cookies=cookiesconvert, headers=headersconvert, data={'hash': hash_value}) | |
hash_response.raise_for_status() | |
hash_result = hash_response.json() | |
task_id = hash_result.get("taskId") | |
while task_id: | |
task_response = requests.post(f'{for_origin}task', cookies=cookiesconvert, headers=headersconvert, data={'taskId': task_id}) | |
task_response.raise_for_status() | |
task_result = task_response.json() | |
status = task_result.get("status") | |
if status == "finished": | |
download_url = urllib.parse.unquote(task_result.get("download", "")) | |
video_formats.append({ | |
'quality': video.get('quality'), | |
'fileType': video.get('fileType'), | |
'filesize': video.get('filesize'), | |
'downloadUrl': download_url | |
}) | |
break | |
audio_formats = [] | |
audio_list = formats.get("audio", []) | |
for audio in audio_list: | |
hash_value = audio.get("hash") | |
if hash_value: | |
hash_response = requests.post(f'{for_origin}convert', cookies=cookiesconvert, headers=headersconvert, data={'hash': hash_value}) | |
hash_response.raise_for_status() | |
hash_result = hash_response.json() | |
task_id = hash_result.get("taskId") | |
while task_id: | |
task_response = requests.post(f'{for_origin}task', cookies=cookiesconvert, headers=headersconvert, data={'taskId': task_id}) | |
task_response.raise_for_status() | |
task_result = task_response.json() | |
status = task_result.get("status") | |
if status == "finished": | |
download_url = urllib.parse.unquote(task_result.get("download", "")) | |
audio_formats.append({ | |
'quality': f"{audio.get('quality')} kbps", | |
'fileType': audio.get('fileType'), | |
'filesize': audio.get('filesize'), | |
'downloadUrl': download_url | |
}) | |
break | |
return jsonify({ | |
'videoId': video_id, | |
'title': title, | |
'thumbnail': thumbnail, | |
'duration': duration, | |
'videoFormats': video_formats, | |
'audioFormats': audio_formats | |
}) | |
else: | |
return jsonify({'error': result.get("error_message")}), 400 | |
except requests.RequestException as e: | |
return jsonify({'error': f'An error occurred: {str(e)}'}), 500 | |
except ValueError as e: | |
return jsonify({'error': f'Error parsing JSON: {str(e)}'}), 500 | |
if __name__ == '__main__': | |
app.run(debug=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
import tkinter as tk | |
from tkinter import messagebox | |
import webbrowser | |
def get_video_id(url): | |
pattern = re.compile(r'(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})') | |
match = pattern.search(url) | |
return match.group(1) if match else None | |
def open_browser(url): | |
webbrowser.open(url) | |
def format_download_info(info): | |
return f"Download Link: {info['k']}\nresolusi: {info['q_text']}\nsize: {info['size']}\n" | |
def analyze_youtube_video(youtube_url): | |
video_id = get_video_id(youtube_url) | |
if not video_id: | |
messagebox.showerror("Error", "Invalid YouTube URL. Could not extract video ID.") | |
return | |
cookies = { | |
'_ga_PSRPB96YVC': 'GS1.1.1701089943.1.1.1701090163.0.0.0', | |
'_ga': 'GA1.1.321171632.1701089943', | |
'prefetchAd_3381349': 'true', | |
} | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0', | |
'Accept': '*/*', | |
'Accept-Language': 'id,en-US;q=0.7,en;q=0.3', | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'Referer': f'https://www.y2mate.com/youtube/{video_id}', | |
'X-Requested-With': 'XMLHttpRequest', | |
'Origin': 'https://www.y2mate.com', | |
'Sec-Fetch-Dest': 'empty', | |
'Sec-Fetch-Mode': 'cors', | |
'Sec-Fetch-Site': 'same-origin', | |
'Connection': 'keep-alive', | |
'Alt-Used': 'www.y2mate.com', | |
} | |
data = f'k_query={youtube_url}&k_page=home&hl=en&q_auto=0' | |
try: | |
response = requests.post('https://www.y2mate.com/mates/en870/analyzeV2/ajax', cookies=cookies, headers=headers, data=data, timeout=5) | |
response.raise_for_status() | |
json_data = response.json() | |
judul = f"\nTitle: {json_data['title']}" | |
high = format_download_info(json_data['links']['mp4']['22']).replace(' <span class="label label-primary"><small>m-HD</small></span>', '') | |
medium = format_download_info(json_data['links']['mp4']['18']) | |
low = format_download_info(json_data['links']['mp4']['17']) | |
music = format_download_info(json_data['links']['mp3']['mp3128']) | |
result_text = judul + '\n' + '\n'.join([high, medium, low, music]) | |
messagebox.showinfo("Video Information", result_text) | |
tanya = messagebox.askquestion("Download Link", "Do you want to open a download link in your default browser?") | |
if tanya == 'yes': | |
awto = json_data['links']['mp4']['auto']['k'] | |
data2 = {"vid": video_id, | |
"k": awto | |
} | |
response = requests.post('https://www.y2mate.com/mates/convertV2/index', cookies=cookies, headers=headers, data=data2, timeout=5) | |
response.raise_for_status() | |
json2 = response.json() | |
webbrowser.open(json2['dlink']) | |
except requests.exceptions.RequestException as e: | |
messagebox.showerror("Error", f"An error occurred: {e}") | |
def on_submit(): | |
youtube_url = entry.get() | |
analyze_youtube_video(youtube_url) | |
# GUI setup | |
root = tk.Tk() | |
root.title("YouTube Video Downloader") | |
label = tk.Label(root, text="Enter YouTube Video URL:") | |
label.pack(pady=10) | |
entry = tk.Entry(root, width=50) | |
entry.pack(pady=10) | |
submit_button = tk.Button(root, text="Submit", command=on_submit) | |
submit_button.pack(pady=10) | |
root.mainloop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import platform | |
import os | |
try: | |
import re, requests, webbrowser | |
except ModuleNotFoundError: | |
if platform == "linux" or platform == "linux2": | |
print("Installing requirements...") | |
os.system("pip3 install requests webbrowser") | |
print("Done") | |
elif platform == "darwin": | |
print("Installing requirements...") | |
os.system("pip3 install requests webbrowser") | |
print("Done") | |
elif platform == "win32": | |
print("Installing requirements...") | |
os.system("pip install requests webbrowser") | |
print("Done") | |
else: | |
print("Unknown OS") | |
exit() | |
finally: | |
import re, requests, webbrowser | |
def get_video_id(url): | |
pattern = re.compile(r'(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})') | |
match = pattern.search(url) | |
return match.group(1) if match else None | |
def analyze_youtube_video(youtube_url): | |
video_id = get_video_id(youtube_url) | |
if not video_id: | |
print("Invalid YouTube URL. Could not extract video ID.") | |
return | |
cookies = { | |
'_ga_PSRPB96YVC': 'GS1.1.1701089943.1.1.1701090163.0.0.0', | |
'_ga': 'GA1.1.321171632.1701089943', | |
'prefetchAd_3381349': 'true', | |
} | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0', | |
'Accept': '*/*', | |
'Accept-Language': 'id,en-US;q=0.7,en;q=0.3', | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'Referer': f'https://www.y2mate.com/youtube/{video_id}', | |
'X-Requested-With': 'XMLHttpRequest', | |
'Origin': 'https://www.y2mate.com', | |
'Sec-Fetch-Dest': 'empty', | |
'Sec-Fetch-Mode': 'cors', | |
'Sec-Fetch-Site': 'same-origin', | |
'Connection': 'keep-alive', | |
'Alt-Used': 'www.y2mate.com', | |
} | |
data = f'k_query={youtube_url}&k_page=home&hl=en&q_auto=0' | |
try: | |
response = requests.post('https://www.y2mate.com/mates/en870/analyzeV2/ajax', cookies=cookies, headers=headers, data=data, timeout=5) | |
response.raise_for_status() | |
json_data = response.json() | |
judul = f"\nTitle: {json_data['title']}" | |
high = f"Download Link: {json_data['links']['mp4']['22']['k']}\nresolusi: {json_data['links']['mp4']['22']['q_text']}\nsize: {json_data['links']['mp4']['22']['size']}\n".replace(' <span class="label label-primary"><small>m-HD</small></span>', '') | |
medium = f"Download Link: {json_data['links']['mp4']['18']['k']}\nresolusi: {json_data['links']['mp4']['18']['q_text']}\nsize: {json_data['links']['mp4']['18']['size']}\n" | |
low = f"Download Link: {json_data['links']['mp4']['17']['k']}\nresolusi: {json_data['links']['mp4']['17']['q_text']}\nsize: {json_data['links']['mp4']['17']['size']}\n" | |
awto = f"Download Link: {json_data['links']['mp4']['auto']['k']}ad Link: {json_data['links']['mp4']['auto']['k']}\nresolusi: {json_data['links']['mp4']['auto']['q_text']}\nsize: {json_data['links']['mp4']['auto']['size']}\n" | |
music = f"Download Link: {json_data['links']['mp3']['mp3128']['k']}\nresolusi: {json_data['links']['mp3']['mp3128']['q_text']}\nsize: {json_data['links']['mp3']['mp3128']['size']}\n" | |
print(judul) | |
counter = 0 | |
for i in [high, medium, low, awto, music]: | |
counter += 1 | |
print(counter,i) | |
tanya = str(input("Masukan Download Link yang ingin di download: ")) | |
if tanya == "1": | |
tanya = json_data['links']['mp4']['22']['k'] | |
elif tanya == "2": | |
tanya = json_data['links']['mp4']['18']['k'] | |
elif tanya == "3": | |
tanya = json_data['links']['mp4']['17']['k'] | |
elif tanya == "4": | |
tanya = json_data['links']['mp4']['auto']['k'] | |
elif tanya == "5": | |
tanya = json_data['links']['mp3']['mp3128']['k'] | |
else: | |
print("Pilihan tidak ada") | |
return | |
try: | |
data2 = {"vid": video_id, | |
"k": tanya | |
} | |
response = requests.post('https://www.y2mate.com/mates/convertV2/index', cookies=cookies, headers=headers, data=data2, timeout=5) | |
response.raise_for_status() | |
json2 = response.json() | |
print(f"Download Link: {json2['dlink']}") | |
print(f"Quality: {json2['fquality']}") | |
simpanatautidak = str(input("Simpan otomatis? (y/n): ")) | |
if simpanatautidak == "y" or simpanatautidak == "Y": | |
if platform == "linux" or platform == "linux2": | |
webbrowser.open(json2['dlink']) | |
elif platform == "darwin": | |
webbrowser.open(json2['dlink']) | |
elif platform == "win32": | |
webbrowser.open(json2['dlink']) | |
else: | |
print("Download dibatalkan") | |
return | |
except Exception as e: | |
print(e) | |
return | |
except requests.exceptions.RequestException as e: | |
print(f"An error occurred: {e}") | |
if __name__ == "__main__": | |
youtube_url = input("Enter the YouTube video URL: ") | |
analyze_youtube_video(youtube_url) |
Author
Xnuvers007
commented
Nov 27, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment