-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow randomized background music from user-specified dir
- Loading branch information
Showing
6 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
import random | ||
import urllib | ||
|
||
|
||
def create_randomized_playlist(input_directory, base_url): | ||
# Get all mp3 files in the given directory | ||
mp3_files = [f for f in os.listdir(input_directory) if f.endswith(".mp3")] | ||
|
||
# Shuffle the list of mp3 files | ||
random.shuffle(mp3_files) | ||
|
||
# Create the playlist | ||
playlist = [] | ||
for mp3 in mp3_files: | ||
mp3 = urllib.parse.quote(mp3.encode("utf8")) | ||
url = f"{base_url}/{mp3}" | ||
playlist.append(f"{url}") | ||
|
||
return playlist |
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters