L'oncle claude ce nulos il sait pas déterminenr combien de temps ça dure une musique
All checks were successful
ci / deploy (push) Successful in 5m53s
All checks were successful
ci / deploy (push) Successful in 5m53s
This commit is contained in:
@@ -1,8 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
import glob, os, sys
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def generate_pls(directory: str, output_file: str = None) -> None:
|
||||
def get_song_length(file: Path) -> float:
|
||||
ret = subprocess.run(
|
||||
[
|
||||
"ffprobe",
|
||||
"-i",
|
||||
str(file.absolute()),
|
||||
"-show_entries",
|
||||
"format=duration",
|
||||
"-v",
|
||||
"quiet",
|
||||
"-of",
|
||||
"csv=p=0",
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
if ret.returncode != 0:
|
||||
return -1
|
||||
|
||||
try:
|
||||
return float(ret.stdout)
|
||||
except ValueError:
|
||||
return -1
|
||||
|
||||
|
||||
def generate_pls(directory: str, output_file: str | None = None) -> None:
|
||||
"""Generate a .pls playlist file from all audio files in a directory.
|
||||
|
||||
Args:
|
||||
@@ -38,14 +66,12 @@ def generate_pls(directory: str, output_file: str = None) -> None:
|
||||
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)
|
||||
for idx, path in enumerate(audio_files, start=1):
|
||||
file = Path(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(f"File{idx}={file.absolute()}")
|
||||
pls_content.append(f"Title{idx}={file.stem.replace('_', ' ')}")
|
||||
pls_content.append(f"Length{idx}={get_song_length(file)}")
|
||||
pls_content.append("")
|
||||
|
||||
pls_content.append("Version=2")
|
||||
|
||||
Reference in New Issue
Block a user