init liquidsoap. We thank our uncle Claude, gave him 1.74$ so he can buy a beer. He got drunk on wine and we had to clean the mess ourselves. Sacré oncle Claude !
This commit is contained in:
70
je_te_met_en_pls.py
Executable file
70
je_te_met_en_pls.py
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
import glob, os, sys
|
||||
|
||||
|
||||
def generate_pls(directory: str, output_file: str = None) -> None:
|
||||
"""Generate a .pls playlist file from all audio files in a directory.
|
||||
|
||||
Args:
|
||||
directory: Path to directory containing audio files
|
||||
output_file: Path to output .pls file (default: directory/playlist.pls)
|
||||
"""
|
||||
if not os.path.isdir(directory):
|
||||
print(f"Error: Directory '{directory}' does not exist")
|
||||
sys.exit(1)
|
||||
|
||||
# Audio file extensions to search for
|
||||
audio_extensions = ["*.mp3", "*.ogg", "*.flac", "*.wav", "*.m4a", "*.aac", "*.opus"]
|
||||
|
||||
# Collect all audio files
|
||||
audio_files = []
|
||||
for ext in audio_extensions:
|
||||
pattern = os.path.join(directory, ext)
|
||||
audio_files.extend(glob.glob(pattern))
|
||||
|
||||
if not audio_files:
|
||||
print(f"Warning: No audio files found in '{directory}'")
|
||||
return
|
||||
|
||||
# Sort files alphabetically
|
||||
audio_files.sort()
|
||||
|
||||
# Determine output file path
|
||||
if output_file is None:
|
||||
output_file = os.path.join(directory, "playlist.pls")
|
||||
|
||||
# Generate .pls content
|
||||
pls_content = ["[playlist]"]
|
||||
pls_content.append(f"NumberOfEntries={len(audio_files)}")
|
||||
pls_content.append("")
|
||||
|
||||
for idx, file_path in enumerate(audio_files, start=1):
|
||||
# Get absolute path
|
||||
abs_path = os.path.abspath(file_path)
|
||||
filename = os.path.basename(file_path)
|
||||
|
||||
pls_content.append(f"File{idx}={abs_path}")
|
||||
pls_content.append(f"Title{idx}={filename}")
|
||||
pls_content.append(f"Length{idx}=-1")
|
||||
pls_content.append("")
|
||||
|
||||
pls_content.append("Version=2")
|
||||
|
||||
# Write to file
|
||||
with open(output_file, "w") as f:
|
||||
f.write("\n".join(pls_content))
|
||||
|
||||
print(f"Generated '{output_file}' with {len(audio_files)} entries")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: je_te_met_en_pls.py <directory> [output_file.pls]")
|
||||
print("Example: je_te_met_en_pls.py /songs")
|
||||
print("Example: je_te_met_en_pls.py /songs /tmp/my_playlist.pls")
|
||||
sys.exit(1)
|
||||
|
||||
directory = sys.argv[1]
|
||||
output_file = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
|
||||
generate_pls(directory, output_file)
|
||||
Reference in New Issue
Block a user