Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os
- import random
- FILE_TYPES = ('mp3', 'flac', )
- PLAYLIST_NAME = 'edlist.m3u8'
- REPEAT_PROBABILITY = 0.7
- INCLUDE_SUBFOLDERS = True
- def main():
- '''
- stick this script in your music dir
- change FILE_TYPES to whatever music files you have in there
- change INCLUDE_SUBFOLDERS to False if you don't want subfolders
- change REPEAT_PROBABILITY to whatever probability you want
- run the script and it'll create a file with name specified by PLAYLIST_NAME
- drop that file into any music player
- '''
- base_path = os.getcwd()
- music_files = []
- for root, dirs, files in os.walk(base_path):
- for file in files:
- extension = file.rsplit('.', 1)[1]
- if extension in FILE_TYPES:
- file_path = os.path.join(root, file) + '\n'
- music_files.append(file_path)
- if not INCLUDE_SUBFOLDERS:
- break
- random.shuffle(music_files)
- with open(PLAYLIST_NAME, 'w', encoding='utf-8') as outfile:
- for file in music_files:
- outfile.write(file)
- if random.random() < REPEAT_PROBABILITY:
- outfile.write(file)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement