(Nota: Je ne sais pas si c'est le bon endroit pour ce post, je laisse soin à un modérateur d'en décider...
Si comme moi vous disposez d'un certain nombre de musiques sur votre système, et que vous ne savez parfois pas trop quelle playlist écouter, le script batch (.bat) suivant choisi aléatoirement l'une de vos playlists.
Pour utiliser ce script à la racine d'une clé USB, enlevez le "\" de "%CD%\Playlists", à la ligne 7 (anglais) ou 5 (français).
Playlist random choice.bat (en anglais et avec commentaires) :
@echo off
setlocal EnableDelayedExpansion
:: Delete a possible "m3u_list.txt" file.
set list=%TEMP%\m3u_list.txt
if exist %list% del /f /q %list%
:: If there's a "Playlists" folder in the current folder, this script will use it; if there's no "Playlists" folder in the current folder, this script will use the "%USERPROFILE%\Music" folder (example: "C:\Users\User Name\Music").
if exist %CD%\Playlists (set musicFolder=%CD%) else (set musicFolder=%USERPROFILE%\Music)
:: Create the M3U list.
set playlists=%musicFolder%\Playlists
for /r %playlists% %%X in (*.m3u) do (echo %%X >> %list%)
:random
cls
:: Count the number of M3U.
set /a counter=0
for /f "delims=" %%i in ('type %list%') do set /a counter+=1
:: Generate a random number between 0 and the "number of M3U -1" (number 0 = line 1 of the M3U list).
set /a randomNumber=%random% %%%counter%
:: Get the playlist URL corresponding to the random number.
set playlist=
for /f "delims=" %%a in ('more /e +%randomNumber% ^< %list%') do (if not defined playlist set "playlist=%%a")
:: Count the characters in the URL of the "Playlists" folder (with the final "\").
for /f "tokens=1,* delims=[,]" %%A in ('"%comspec% /u /c echo:%playlists%|more|find /n /v """') do set /a playlistsURLcharNumber=%%A-3
:: Get the playlist name in the M3U list, by removing the URL of the "Playlists" folder (with the final "\") at the line's begining, and removing the ".m3u" extention + white space at the line's end.
set "playlist=!playlist:~playlistsURLcharNumber,-5!"
:: Escape of possible "&" and "," characters in the playlist name.
set playlist=%playlist:&=^^^&%
set playlist=%playlist:^,=^^^,%
:: Get the playlist number (line 1 of the M3U list = number 1).
set /a listLine=%randomNumber%+1
:: On screen: Playlist number / number of remaining playlists in the M3U list (see line #76 of this script) : playlist name
echo Playlist %listLine%/%counter% : !playlist!
:: What to do?
echo.
echo Possible choices:
echo.
set quit=[0] Quit.
echo %quit%
set open=[1] Open the music folder.
echo %open%
set other=[2] Select another Playlist.
echo %other%
echo [3] Start this Playlist.
echo.
choice /c 1230 /n /m "What's your choice?"
set choice=%errorlevel%
:: [1] Open the music folder, delete the "m3u_list.txt" file and close this window.
if %choice%==1 (start "%musicFolder%" "%musicFolder%" & del /f /q %list% & exit)
:: [2] Select another Playlist.
if %choice%==2 goto :anotherPlaylist
:: [3] Start the Playlist.
if %choice%==3 (start "!playlist!" "%playlists%\!playlist!.m3u" & goto :playing)
:: [0] Quit.
if %choice%==4 exit
:: On screen - choice [3]
:playing
cls
echo Playing "!playlist!"
echo (you can minimize this window)...
echo.
echo At anytime you can:
echo.
:: [0] Quit; [1] Open the music folder; [2] Select another Playlist.
echo %quit%
echo %open%
echo %other%
echo.
choice /c 120 /n /m "What's your choice?"
set choice=%errorlevel%
if %choice%==1 (start "%musicFolder%" "%musicFolder%" & del /f /q %list% & exit)
if %choice%==2 goto :anotherPlaylist
if %choice%==3 exit
:: [2] Select another Playlist.
:anotherPlaylist
cls
:: Remove the previous playlist in the M3U list.
findstr /v /c:"%playlists%\%playlist%.m3u " < %list% > %tempList%
:: Write the remaining playlists in a new M3U list, delete the old M3U list, and return to the line #11 of this script to select another playlist.
copy %tempList% %list%
del /f /q %tempList%
goto :random
Choix aléatoire d'une playlist.bat (en français, encodage "OEM 863", et sans commentaires) :
@echo off
setlocal EnableDelayedExpansion
set list=%TEMP%\liste_m3u.txt
if exist %list% del /f /q %list%
if exist %CD%\Playlists (set musicFolder=%CD%) else (set musicFolder=%USERPROFILE%\Music)
set playlists=%musicFolder%\Playlists
for /r %playlists% %%X in (*.m3u) do (echo %%X >> %list%)
:random
cls
set /a counter=0
for /f "delims=" %%i in ('type %list%') do set /a counter+=1
set /a randomNumber=%random% %%%counter%
set playlist=
for /f "delims=" %%a in ('more /e +%randomNumber% ^< %list%') do (if not defined playlist set "playlist=%%a")
for /f "tokens=1,* delims=[,]" %%A in ('"%comspec% /u /c echo:%playlists%|more|find /n /v """') do set /a playlistsURLcharNumber=%%A-3
set "playlist=!playlist:~%playlistsURLcharNumber%,-5!"
set playlist=%playlist:&=^^^&%
set playlist=%playlist:^,=^^^,%
set /a listLine=%randomNumber%+1
echo Playlist %listLine%/%counter% : !playlist!
echo.
echo Choix possibles :
echo.
set quit=[0] Quitter.
echo %quit%
set open=[1] Ouvrir le dossier de musique.
echo %open%
set other=[2] Choisir une autre Playlist.
echo %other%
echo [3] Lire cette Playlist.
echo.
choice /c 1230 /n /m "Quel est votre choix ?"
set choice=%errorlevel%
if %choice%==1 (start "%musicFolder%" "%musicFolder%" & del /f /q %list% & exit)
if %choice%==2 goto :anotherPlaylist
if %choice%==3 (start "!playlist!" "%playlists%\!playlist!.m3u" & goto :playing)
if %choice%==4 exit
:playing
cls
echo Lecture de "!playlist!" en cours
echo (vous pouvez réduire cette fenêtre)...
echo.
echo A tout moment vous pouvez :
echo.
echo %quit%
echo %open%
echo %other%
echo.
choice /c 120 /n /m "Quel est votre choix ?"
set choice=%errorlevel%
if %choice%==1 (start "%musicFolder%" "%musicFolder%" & del /f /q %list% & exit)
if %choice%==2 goto :anotherPlaylist
if %choice%==3 exit
:anotherPlaylist
cls
findstr /v /c:"%playlists%\%playlist%.m3u " < %list% > %tempList%
copy %tempList% %list%
del /f /q %tempList%
goto :random
De plus, tant qu'ils sont tous les deux dans le même dossier, il n'est plus nécessaire que le fichier .bat et le sous-dossier "Playlists" soient dans le dossier "%USERPROFILE%\Music".
Pour utiliser ce script à la racine d'une clé USB, enlevez le "\" de "%CD%\Playlists", à la ligne 7 (anglais) ou 5 (français).
Windows 7 Professionnel SP1 x64
.
[Astuce/Batch] Choix random d'une playlist
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Windows 7 Professionnel SP1 x64
.
Windows 7 Professionnel SP1 x64
.
Windows 7 Professionnel SP1 x64
.
Windows 7 Professionnel SP1 x64
.
Windows 7 Professionnel SP1 x64
.
Windows 7 Professionnel SP1 x64
.