Skin packaging script and extraction script
Posted: 04 Jan 2014 09:46
After doing the same commands over and over, packaging and testing a skin gets very tedious. Here's a script that makes it less so (for Windows).
The vlt file is actually in zip format here instead of the (usual?) .tar.gz.
VLC doesn't seem to like the flavor of tar/gzip I've been able to generate from various Windows programs, but it's ok with zip (not 7z though).
Here's an extraction script. Drag'n'drop your .vlt file onto the script and it will extract to a folder of the same name. It will try to extract using .tar.gz format first and then fall back to auto-detection if that fails. Note that I had the latest alpha version of 7zip (7z.exe) and that it gave errors when piping the tar.gz commands where the stable 9.20 version works fine (7za.exe). I have both files in the same 7zip folder now. I suppose I could do it as two steps without the pipe and then delete the intermediate file... meh...
Updates 2013-01-05:
* Updated packaging script:
** rename to _package.bat so it's at the top of the file list when sorted by name
** the error subroutine performs exit with error code 1 instead of goto:eof
** Add logging to file of the VLC session to aid troubleshooting skin errors
** Add check for whether an folder was dropped (argument was provided)
* Added extraction script
The vlt file is actually in zip format here instead of the (usual?) .tar.gz.
VLC doesn't seem to like the flavor of tar/gzip I've been able to generate from various Windows programs, but it's ok with zip (not 7z though).
Code: Select all
@echo off
echo ===============================================================================
echo :: This script provides a way to package files into a VLC skin file (.vlt)
echo :: You'll need 7zip in your path or add it explicitly using the path variable
echo :: in the script (below).
echo ::
echo :: To use...
echo :: Drag'n'drop the folder containing your skin files onto this script.
echo :: A .vlt file will be created as a sibling to the folder.
echo :: If you create a file named "_package_testVideo.txt" whose contents is
echo :: the full path and filename of a media file, VLC will start with the skin
echo :: applied and playing that file.
echo ===============================================================================
echo.
echo.
:: If you don't have 7zip or VLC in your path, uncomment and edit as needed below
set path=%path%;G:\Utility\File\7zip;G:\Media\Players\vlc
:: Read the path to the test video
set /p testVideo= <%~n0_testVideo.txt
set skinFolder=%1
set skinName=%~n1
:: in case it was in a folder unpacked by the Skin Editor
set skinName=%skinName:_unpacked=%
set folder=%~dp1
set log="%~n0_log.txt"
if (%~1) == () call :Error "You need to drop a folder on this script or send it as an argument." 1
:: variable checks
echo.
echo. skinName : %skinName%
echo. folder : %folder%
echo. testVideo : %testVideo%
echo. vltFile : %folder%%skinName%.vlt
echo. log : %log%
echo.
:: Check existence of dependencies
7za >NUL
call :CheckError "7zip was not found"
:: not a good way to do this for VLC
:: vlc --play-and-exit --version >NUL
:: call :CheckError "VLC was not found"
set zipFile="%folder%%skinName%.zip"
set tarFile="%folder%%skinName%.tar"
set gzFile="%folder%%skinName%.tar.gz"
set vltFile="%folder%%skinName%.vlt"
set bakFile="%folder%%skinName%.vlt.bak"
::if not exist "%skinFolder%\skin.dtd" (
:: call :Error "The skin.dtd file is not in the skin folder."
::)
goto :CreateZip
:: VLC doesn't work with the files created by this method for some reason.
:CreateGzip
:: Update files to the tar archive (intermediate)
echo. &echo === Creating .tar file...
7za a %tarFile% "%skinFolder%\*" -ttar
call :CheckError "An error occurred while creating the tar file."
:: Update the tar.gz file (the format vlc uses)
echo. &echo === Creating .tar.gz file...
::tar -c -f %tarFile% "%skinFolder%\"
::gzip -c %tarFile% > %gzFile%
7za a %gzFile% %tarFile% -tgzip
call :CheckError "An error occurred while creating the gzip file."
echo.
:: Transition the tar.gz file to .vlt
call :CreateBackup %gzFile% .tar.gz
goto :CheckVLC
:CreateZip
echo. &echo === Creating .zip file...
call :CheckError "An error occurred while creating the zip file."
7za a %zipFile% "%skinFolder%\*" -tzip
call :CreateBackup %zipFile% .zip
goto :CheckVLC
:CreateBackup
:: %1 is the full filename of the archive (.tar.gz or .zip)
:: %2 is the extension of the archive for messages
if not exist %1 (call :Error "The %2 file is missing.")
if exist %vltFile% (
if exist %bakFile% (
echo. &echo === Deleting old backup file...
del %bakFile%
call :CheckError "The .bak file could not be deleted."
)
echo. &echo === Backing up previous vlt file...
rename %vltFile% "%skinName%.vlt.bak"
call :CheckError "The .bak file could not be created."
)
echo. &echo === Renaming %2 -^> .vlt ...
rename %1 "%skinName%.vlt"
call :CheckError "The %2 file could not be renamed to .vlt"
goto :eof
:: We want to test the new skin in VLC, right?
:CheckVLC
color 0A
if exist "%testVideo%" (
echo. &echo === Starting VLC to test skin ...
>%log% echo vlc "%testVideo%"
>>%log% echo --extraintf=http:logger --verbose=1 --file-logging --logfile=%log%
>>%log% echo -I skins2 --skins2-last="%folder%%skinName%.vlt"
>>%log% echo.
vlc "%testVideo%" ^
--extraintf=http:logger --verbose=1 --file-logging --logfile=%log% ^
-I skins2 --skins2-last="%folder%%skinName%.vlt"
if not %errorlevel% == 0 ( type vlc-log.txt )
call :CheckError "Failed to load VLC."
)
timeout /T 3
goto:eof
:CheckError
::echo. errorlevel : '%errorlevel%'
if not %errorlevel% == 0 ( call :Error %1 )
goto:eof
:Error
:: The first argument is the message
:: If a second argument is provided, the "additional details" message is supporessed.
color 0C
set msg=%1
:: strip quotes from ends, if any
for /f "useback tokens=*" %%a in ('%msg%') do set msg=%%~a
echo.
echo ================================================================================
echo. ERROR: %msg%
if "%2"=="" (
echo. Check the execution area above for additional details.
)
echo.
pause >NUL
exit 1
:ReplaceUnpacked
set skinName=%skinName:_unpacked=%
goto:eof
Code: Select all
@echo off
echo ===============================================================================
echo :: This script provides a way to extract files to a folder.
echo :: You'll need 7zip in your path or add it explicitly.
echo :: Note: The 7-Zip 9.32 alpha exits with error code 2 for .tar.gz compressed
echo :: files.
echo :: 7-Zip 9.20 (2010-11-18) works ok (uses 7za.exe as below).
echo :: To use...
echo :: Drag'n'drop the skin file (.vlt) onto this script.
echo :: A folder with the same base name will be created as a sibling to the
echo :: skin file.
echo ===============================================================================
echo.
echo.
:: If you don't have 7zip or VLC in your path, uncomment and edit as needed below
set path=%path%;G:\Utility\File\7zip;G:\Media\Players\vlc
set skinFile="%1"
set skinName=%~n1
set skinFolder="%~dp1%skinName%"
set folder="%~dp0"
if (%~1) == () call :Error "You need to drop a file on this script or send it as an argument." 1
:: variable checks
echo.
echo. skinName : %skinName%
echo. skinFile : %skinFile%
echo. skinFolder : %skinFolder%
echo. folder : %folder%
echo.
:: Check existence of dependencies
7za >NUL
call :CheckError "7zip was not found"
:TryExtractGzip
echo. &echo === Attempting to extract as .tar.gz ...
echo 7za x %skinFile% -so ^| 7za x -aoa -si -ttar -o%skinFolder%
echo. &echo ================================================================================
7za x %skinFile% -so | 7za x -aoa -si -ttar -o%skinFolder%
echo ================================================================================
if %errorlevel% == 0 ( goto:DoneSuccess )
echo errorlevel : %errorlevel%
:TryExtractAutoDetect
echo. &echo === Attempting to extract using auto-detection ...
set cmd=7za x %skinFile% -aoa -o%skinFolder%
echo %cmd%
echo. &echo ================================================================================
%cmd%
echo ================================================================================
call :CheckError "An error occurred while extracting the skin file."
:: We want to test the new skin in VLC, right?
:DoneSuccess
color 0A
pause
timeout /T 3
goto:eof
:CheckError
::echo. errorlevel : '%errorlevel%'
if not %errorlevel% == 0 ( call :Error %1 )
goto:eof
:Error
:: The first argument is the message
:: If a second argument is provided, the "additional details" message is supporessed.
color 0C
set msg=%1
:: strip quotes from ends, if any
for /f "useback tokens=*" %%a in ('%msg%') do set msg=%%~a
echo.
echo ================================================================================
echo. ERROR: %msg%
if "%2"=="" (
echo. Check the execution area above for additional details.
)
echo.
pause >NUL
exit 1
* Updated packaging script:
** rename to _package.bat so it's at the top of the file list when sorted by name
** the error subroutine performs exit with error code 1 instead of goto:eof
** Add logging to file of the VLC session to aid troubleshooting skin errors
** Add check for whether an folder was dropped (argument was provided)
* Added extraction script