kendim kodladım youtube linkini yapiştirini sizin için indirsin
Not: kod güncellendi hatalar giderildi.. 17.09.2023
import time
import requests
 
mp3link = input("İndirmek istediginiz Youtube linkini  yapiştirin:  ")

# '&' işaretine kadar olan kısmı bul
index = mp3link.find('&')
if index != -1:
    ytblink = mp3link[:index]
else:
    print("Linkte '&' işareti bulunamadı.")
 
cookies = {
    '_ga': 'GA1.1.1788658791.1692891691',
    '_ga_MY2X5XCWJD': 'GS1.1.1692894823.2.1.1692894825.0.0.0',
}
headers = {
    'authority': 'www.y2dl.com',
    'accept': '*/*',
    'accept-language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
    'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    # 'cookie': '_ga=GA1.1.1788658791.1692891691; _ga_MY2X5XCWJD=GS1.1.1692894823.2.1.1692894825.0.0.0',
    'origin': 'https://www.y2dl.com',
    'referer': 'https://www.y2dl.com/tr63/',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
    'x-requested-with': 'XMLHttpRequest',
}
data = {
    'q': f'{ytblink}',
}
response = requests.post('https://www.y2dl.com/api/get-mp3', cookies=cookies, headers=headers, data=data)
r = response.json()
vid = r['vid']
token = r['token']
###################################################################
 
while True:
    cookies = {
        '_ga': 'GA1.1.1788658791.1692891691',
        '_ga_MY2X5XCWJD': 'GS1.1.1692894823.2.1.1692894918.0.0.0',
    }
    headers = {
        'authority': 'www.y2dl.com',
        'accept': '*/*',
        'accept-language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        # 'cookie': '_ga=GA1.1.1788658791.1692891691; _ga_MY2X5XCWJD=GS1.1.1692894823.2.1.1692894918.0.0.0',
        'origin': 'https://www.y2dl.com',
        'referer': 'https://www.y2dl.com/tr63/',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
        'x-requested-with': 'XMLHttpRequest',
    }
    data = {
        'f': '320',
        'vid': f'{vid}',
        'token': f'{token}',
    }
    responsem = requests.post('https://www.y2dl.com/api/conver-to-mp3', cookies=cookies, headers=headers, data=data)
    bilgi = responsem.json()
    mp3 = bilgi['d_url']
    print("mp3 Link: " + mp3)
    if mp3 == '':
        pass
    else:
        mp3_response = requests.get(mp3)
         
        if mp3_response.status_code == 200:
            save_path = "indirilen.mp3"
             
            with open(save_path, 'wb') as f:
                f.write(mp3_response.content)
                 
            print("MP3 dosyası başarıyla indirildi.")
            break
        else:
            print("MP3 dosyası indirilemedi. HTTP kodu:", mp3_response.status_code)
            break
 

    time.sleep(8)