Advertisement
XenoTheStrange

Poorly organized script to make a list of songs from the contents of music folder

Feb 1st, 2023 (edited)
1,442
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | Source Code | 0 0
  1. import os
  2.  
  3. debug = False
  4. format = 1 #or 2
  5.  
  6. def main():
  7.     extlist = (".mp3",".m4a",".wav", ".ogg")
  8.     if debug:
  9.         index = [('/media/user/D/Commmon/Music/ZZ Top', [], ['Sharp Dressed Man.mp3', 'FakeSong - ZZ Top.ogg', '015 - Yeetus.mp3'])]
  10.     else:
  11.         index = list(os.walk("/media/user/D/Common/Music/"))# Grab list of artists and folders
  12.     file = open("songslist.txt", "w")
  13.     for entry in index:
  14.         artist = entry[0].split("/")[-1]
  15.         out = []
  16.         for i in entry[2]: #for each filename in artist folder
  17.             if i.endswith(extlist):
  18.                 name = i
  19.                 tmp = i.split(" -!- ")[0].split(".")
  20.                 if len(tmp) > 1:tmp.pop()
  21.                 name = "".join(tmp)
  22.                 try:
  23.                     isdash = name.index(" - ")
  24.                 except ValueError:
  25.                     isdash = -1
  26.                 if isdash != -1:
  27.                     name = name.split(" - ")
  28.                     if artist.lower() in name[0].lower(): choice = 1
  29.                     elif artist.lower() in name[1].lower(): choice = 0
  30.                     else: choice = -1
  31.                     if choice == -1: out.append(" - ".join(name))
  32.                     if not choice == -1: out.append(name[choice])
  33.                 else:
  34.                     out.append(name)
  35.         newlinetab = "\n    "
  36.         if len(out) > 0:
  37.             print(f"{artist}\n    {newlinetab.join(out)}")
  38.             file.write(f" -!- {artist}\n".join(out))
  39.     file.close()
  40.  
  41. if __name__ == "__main__":
  42.     main()
  43.     exit()
  44.  
  45.  
  46.         # file = open("songslist.txt", "w")
  47.         # for name in songnames:
  48.         #     file.write(f"\"{name}\" -!- {artist}")
  49.         # file.close()
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
Advertisement
Comments
  • XenoTheStrange
    142 days
    # text 0.27 KB | 0 0
    1. I slapped this together one day to try and make a list of the songs I have and deal with how the filenames and folder structure were formatted.
    2. I really need to go through and normalize all of the filenames. I might just use Den4b Renamer to do so (using wine, since I'm on Linux)
Add Comment
Please, Sign In to add comment
Advertisement