niittymaa

Download all the lyrics of the selected artist to a folder (azapi)

Jan 31st, 2023 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | Music | 0 0
  1. # Download all the lyrics of the selected artist to a folder (azapi)
  2. # ------------------------------------------------------------------
  3. # Custom script for azapi
  4. # https://github.com/elmoiv/azapi
  5. # Script by: Creatide (Sakari Niittymaa - 2023)
  6.  
  7. import os
  8. from azapi import AZlyrics
  9.  
  10. import random
  11. import time
  12.  
  13. artist_name = 'nirvana'
  14.  
  15. api = AZlyrics()
  16. api.artist = artist_name
  17. songs = api.getSongs()
  18. wait_counter = 0
  19.  
  20. # Check whether the specified path exists or not
  21. artist_folder = artist_name
  22. isExist = os.path.exists(artist_folder)
  23. if not isExist:
  24.    # Create a new directory because it does not exist
  25.    os.makedirs(artist_folder)
  26.    print('The new directory "' + artist_name + '" is created!')
  27.  
  28. # Get all exist files in artist folder
  29. exist_files = os.listdir(os.getcwd() + '/' + artist_name)
  30.  
  31. # Function to compare if song is already downloadeds
  32. def is_in_list(string, list_of_strings):
  33.     for i in list_of_strings:
  34.         string = string.casefold().strip()
  35.         i = i.casefold().strip()
  36.         if string in i:
  37.             return True
  38.     return False
  39.  
  40. # Generate random wait time in seconds to prevent ban
  41. def wait_random_seconds(min, max, long_every=0, long_duration=60,):
  42.     wait_time = round(random.uniform(min, max), 2)
  43.     print('Wait: ' + str(wait_time) + 'sec\n')
  44.     time.sleep(wait_time)
  45.     # Longer waiting time every X times
  46.     global wait_counter
  47.     wait_counter += 1
  48.     if wait_counter >= long_every:
  49.         long_duration = round(long_duration + random.uniform(1, 10), 2)
  50.         print('# LONG WAIT: ' + str(long_duration) + 'sec\n')
  51.         time.sleep(long_duration)        
  52.         wait_counter = 0
  53.  
  54. # Continue only if songs is available
  55. if type(songs) is dict:    
  56.     # Check total number of songs for selected artist
  57.     if len(songs):
  58.         print('Songs in Total: ' + str(len(songs)))
  59.    
  60.     for song in songs:
  61.         # Check if song is not downloaded already
  62.         if not is_in_list(song, exist_files):
  63.             print(song)
  64.             # Download lyrics and save to artist folder
  65.             api.getLyrics(url=songs[song]["url"], save=True, path=artist_folder)
  66.             wait_random_seconds(4, 12, random.randint(8, 12))
  67.         else:
  68.             print('Song already downloaded: ' + song)
Advertisement
Add Comment
Please, Sign In to add comment