├── reqs.txt ├── url.py ├── README.md ├── ytb.py ├── main.py └── sptf.py /reqs.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aceiny/spotifty-playlist-downloader/HEAD/reqs.txt -------------------------------------------------------------------------------- /url.py: -------------------------------------------------------------------------------- 1 | def get_playlist_id_from_url(url) : 2 | try : 3 | return url.split('/')[::-1][0].split('?')[0] 4 | except : 5 | return 'Not valid url' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | this script uses spotify api to retrive all playlist tracks 2 | then search for the tracks on youtube and downlaod them to the local machine 3 | ## you will first need to run 4 | ``` 5 | pip install -r reqs.txt 6 | 7 | ```` 8 | ## then you will need to run the main file and input your playlist or any playlist you want to download url 9 | -------------------------------------------------------------------------------- /ytb.py: -------------------------------------------------------------------------------- 1 | from pytube import YouTube 2 | from youtubesearchpython import VideosSearch 3 | 4 | def get_video_url_by_name(video_name): 5 | search = VideosSearch(video_name, limit = 1) 6 | results = search.result() 7 | 8 | if results: 9 | video_url = results['result'][0]['link'] 10 | return video_url 11 | else: 12 | return "Video not found" 13 | 14 | 15 | def download_youtube_audio(video_url): 16 | yt = YouTube(video_url) 17 | audio_stream = yt.streams.filter(only_audio=True).first() 18 | audio_stream.download(output_path='./audio') -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from sptf import get_playlist_tracks 2 | from ytb import get_video_url_by_name, download_youtube_audio 3 | from url import get_playlist_id_from_url 4 | 5 | playlist_url = input('Enter playlist url: ') 6 | 7 | playlist_id = get_playlist_id_from_url(playlist_url) 8 | 9 | if playlist_id == 'Not valid url': 10 | print('Not valid url') 11 | exit() 12 | 13 | playlist_tracks = get_playlist_tracks(playlist_id) 14 | print(playlist_tracks) 15 | for track in playlist_tracks: 16 | try : 17 | video_url = get_video_url_by_name(track) 18 | download_youtube_audio(video_url) 19 | print('downloaded ' + track) 20 | except: 21 | print('Error') 22 | continue 23 | -------------------------------------------------------------------------------- /sptf.py: -------------------------------------------------------------------------------- 1 | import spotipy 2 | from spotipy.oauth2 import SpotifyClientCredentials 3 | 4 | client_id = '59238d4dbcda4cf6a06bbf0f4ebeddfb' 5 | client_secret = '141c33ef50b044699465be00dc25ed02' 6 | 7 | sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)) 8 | 9 | def get_playlist_tracks(playlist_id): 10 | l = [] 11 | offset = 0 12 | 13 | while True: 14 | results = sp.playlist_tracks(playlist_id, offset=offset) 15 | if not results or not results.get('items'): 16 | break 17 | 18 | for track in results['items']: 19 | if track and track.get('track') and track['track'].get('artists') and track['track']['artists']: 20 | l.append(track['track']['artists'][0]['name'] + ' - ' + track['track']['name']) 21 | 22 | offset += len(results['items']) 23 | 24 | return l 25 | 26 | 27 | --------------------------------------------------------------------------------