Add rotateMusic.py
This commit is contained in:
parent
329e93128c
commit
07e1388b7b
47
rotateMusic.py
Normal file
47
rotateMusic.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import os
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def get_dir_size(path):
|
||||
total = 0
|
||||
with os.scandir(path) as it:
|
||||
for entry in it:
|
||||
if entry.is_file():
|
||||
total += entry.stat().st_size
|
||||
elif entry.is_dir():
|
||||
total += get_dir_size(entry.path)
|
||||
return total
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 4:
|
||||
return
|
||||
library = sys.argv[1]
|
||||
player = sys.argv[2]
|
||||
amount = int(sys.argv[3])
|
||||
libraryArtists = os.listdir(library)
|
||||
playerArtists = os.listdir(player)
|
||||
librarySpace = {}
|
||||
for item in libraryArtists:
|
||||
librarySpace[item] = get_dir_size(library+"/"+item)
|
||||
shutil.rmtree(player)
|
||||
os.mkdir(player)
|
||||
cumulativeTotal = 0
|
||||
chosenArtists = []
|
||||
while True:
|
||||
artist = random.choice(libraryArtists)
|
||||
libraryArtists.remove(artist)
|
||||
if artist in playerArtists:
|
||||
continue
|
||||
if cumulativeTotal + librarySpace[artist] >= amount:
|
||||
break
|
||||
cumulativeTotal += librarySpace[artist]
|
||||
shutil.copytree(library+"/"+artist, player+"/"+artist)
|
||||
chosenArtists.append(artist)
|
||||
print(100 * cumulativeTotal / amount)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user