Skip to content

Instantly share code, notes, and snippets.

@adamz01h
Created April 21, 2024 02:07
Show Gist options
  • Select an option

  • Save adamz01h/c65c602451e6014d0d04410132b37202 to your computer and use it in GitHub Desktop.

Select an option

Save adamz01h/c65c602451e6014d0d04410132b37202 to your computer and use it in GitHub Desktop.
Process a folder of Windows Media Playlists to export the list to folders with files.
@echo off
setlocal
:: Check if a folder path was provided as an argument
if "%~1"=="" (
echo No folder path was provided.
pause
exit /b
)
:: Get the full path of the folder containing playlists
set "PLAYLIST_FOLDER=%~f1"
:: Iterate over all playlist files in the folder
for %%F in ("%PLAYLIST_FOLDER%\*.wpl") do (
call :ProcessPlaylist "%%F"
)
pause
exit /b
:ProcessPlaylist
:: Get the full path of the WPL file
set "WPL_FILE=%~1"
:: Get the filename without extension to use as the default folder name on the desktop
for %%A in ("%WPL_FILE%") do set "PLAYLIST_NAME=%%~nA"
set "DEFAULT_DEST=%USERPROFILE%\Desktop\PlaylistExport\%PLAYLIST_NAME%"
:: Create the destination folder if it does not exist
if not exist "%DEFAULT_DEST%" (
echo Creating folder: "%DEFAULT_DEST%"
mkdir "%DEFAULT_DEST%"
) else (
echo Folder already exists: "%DEFAULT_DEST%"
)
:: Define VBScript path
set "VBSCRIPT_PATH=%DEFAULT_DEST%\WPLParser.vbs"
echo VBScript will be created at: "%VBSCRIPT_PATH%"
:: Start VBScript creation
echo Set fso = CreateObject^("Scripting.FileSystemObject"^) > "%VBSCRIPT_PATH%"
echo Set xmlDoc = CreateObject^("Microsoft.XMLDOM"^) >> "%VBSCRIPT_PATH%"
echo xmlDoc.Async = "False" >> "%VBSCRIPT_PATH%"
echo xmlDoc.Load^(WScript.Arguments^(0^)^) >> "%VBSCRIPT_PATH%"
echo Set nodeList = xmlDoc.SelectNodes^("/smil/body/seq/media"^) >> "%VBSCRIPT_PATH%"
echo For Each node in nodeList >> "%VBSCRIPT_PATH%"
echo src = node.getAttribute^("src"^) >> "%VBSCRIPT_PATH%"
echo basePath = fso.GetParentFolderName^(WScript.Arguments^(0^)^) >> "%VBSCRIPT_PATH%"
echo resolvedPath = fso.BuildPath^(basePath, src^) >> "%VBSCRIPT_PATH%"
echo absPath = fso.GetAbsolutePathName^(resolvedPath^) >> "%VBSCRIPT_PATH%"
echo WScript.Echo absPath >> "%VBSCRIPT_PATH%"
echo Next >> "%VBSCRIPT_PATH%"
:: Execute the VBScript to get the absolute file paths
for /f "delims=" %%a in ('cscript //nologo "%VBSCRIPT_PATH%" "%WPL_FILE%"') do (
echo Copying "%%a" to "%DEFAULT_DEST%"
xcopy "%%a" "%DEFAULT_DEST%" /I /Y
)
:: Clean up the temporary VBScript file
del "%VBSCRIPT_PATH%"
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment