mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	Download songs using YouTube URL (#135)
* Download from YouTubr URL * Slugify title only for YouTube URL's
This commit is contained in:
		
							
								
								
									
										15
									
								
								core/misc.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								core/misc.py
									
									
									
									
									
								
							| @@ -72,11 +72,16 @@ def get_arguments(): | ||||
|  | ||||
| def is_spotify(raw_song): | ||||
|     """Check if the input song is a Spotify link.""" | ||||
|     if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or \ | ||||
|             (raw_song.find('spotify') > -1): | ||||
|         return True | ||||
|     else: | ||||
|         return False | ||||
|     status = len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song | ||||
|     status = status or raw_song.find('spotify') > -1 | ||||
|     return status | ||||
|  | ||||
| def is_youtube(raw_song): | ||||
|     """Check if the input song is a YouTube link.""" | ||||
|     status = len(raw_song) == 11 and raw_song.replace(" ", "%20") == raw_song | ||||
|     status = status and not raw_song.lower() == raw_song | ||||
|     status = status or 'youtube.com/watch?v=' in raw_song | ||||
|     return status | ||||
|  | ||||
|  | ||||
| def sanitize_title(title): | ||||
|   | ||||
							
								
								
									
										19
									
								
								spotdl.py
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								spotdl.py
									
									
									
									
									
								
							| @@ -14,6 +14,7 @@ import sys | ||||
| import os | ||||
| import time | ||||
|  | ||||
|  | ||||
| def generate_songname(tags): | ||||
|     """Generate a string of the format '[artist] - [song]' for the given spotify song.""" | ||||
|     raw_song = u'{0} - {1}'.format(tags['artists'][0]['name'], tags['name']) | ||||
| @@ -147,11 +148,17 @@ def generate_youtube_url(raw_song, tries_remaining=5): | ||||
|  | ||||
| def go_pafy(raw_song): | ||||
|     """Parse track from YouTube.""" | ||||
|     track_url = generate_youtube_url(raw_song) | ||||
|     if track_url is None: | ||||
|         return None | ||||
|     if misc.is_youtube(raw_song): | ||||
|         track_info = pafy.new(raw_song) | ||||
|     else: | ||||
|         return pafy.new(track_url) | ||||
|         track_url = generate_youtube_url(raw_song) | ||||
|  | ||||
|         if track_url is None: | ||||
|             track_info = None | ||||
|         else: | ||||
|             track_info = pafy.new(track_url) | ||||
|  | ||||
|     return track_info | ||||
|  | ||||
|  | ||||
| def get_youtube_title(content, number=None): | ||||
| @@ -341,10 +348,14 @@ def grab_single(raw_song, number=None): | ||||
|         islist = True | ||||
|     else: | ||||
|         islist = False | ||||
|  | ||||
|     content = go_pafy(raw_song) | ||||
|     if content is None: | ||||
|         return | ||||
|  | ||||
|     if misc.is_youtube(raw_song): | ||||
|         raw_song = slugify(content.title).replace('-', ' ') | ||||
|  | ||||
|     # print '[number]. [artist] - [song]' if downloading from list | ||||
|     # otherwise print '[artist] - [song]' | ||||
|     print(get_youtube_title(content, number)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user