Advertisement
drtchops

edlist

Aug 2nd, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import random
  4.  
  5.  
  6. FILE_TYPES = ('mp3', 'flac', )
  7. PLAYLIST_NAME = 'edlist.m3u8'
  8. REPEAT_PROBABILITY = 0.7
  9. INCLUDE_SUBFOLDERS = True
  10.  
  11.  
  12. def main():
  13.     '''
  14.        stick this script in your music dir
  15.        change FILE_TYPES to whatever music files you have in there
  16.        change INCLUDE_SUBFOLDERS to False if you don't want subfolders
  17.        change REPEAT_PROBABILITY to whatever probability you want
  18.        run the script and it'll create a file with name specified by PLAYLIST_NAME
  19.        drop that file into any music player
  20.    '''
  21.     base_path = os.getcwd()
  22.     music_files = []
  23.  
  24.     for root, dirs, files in os.walk(base_path):
  25.         for file in files:
  26.             extension = file.rsplit('.', 1)[1]
  27.             if extension in FILE_TYPES:
  28.                 file_path = os.path.join(root, file) + '\n'
  29.                 music_files.append(file_path)
  30.  
  31.         if not INCLUDE_SUBFOLDERS:
  32.             break
  33.  
  34.     random.shuffle(music_files)
  35.  
  36.     with open(PLAYLIST_NAME, 'w', encoding='utf-8') as outfile:
  37.         for file in music_files:
  38.             outfile.write(file)
  39.             if random.random() < REPEAT_PROBABILITY:
  40.                 outfile.write(file)
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement