Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "_Initialize"
- {
- // Configuration .ini file
- global $g_ConfigurationFile;
- $g_ConfigurationFile = "<xyscripts>\FFmpeg.ini";
- // Execution and buffer files
- global $g_ExecutionFile;
- $g_ExecutionFile = "<xyscripts>\FFmpeg.bat";
- delete (0, 0, $g_ExecutionFile);
- global $g_DumpFileFFprobe;
- $g_DumpFileFFprobe = "<xyscripts>\FFprobe.ini";
- delete (0, 0, $g_DumpFileFFprobe);
- global $g_ExecutionFileFFprobe;
- $g_ExecutionFileFFprobe = "<xyscripts>\FFprobe.bat";
- delete (0, 0, $g_ExecutionFileFFprobe);
- // Configuration keys
- global $g_ScriptVersion;
- $g_ScriptVersion = '0.4';
- global $g_FFmpeg;
- global $g_FFprobe;
- global $g_Store;
- if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
- // Load keys
- $g_FFmpeg = getkey ('FFmpeg', 'Configuration', "$g_ConfigurationFile", );
- $g_FFprobe = getkey ('FFprobe', 'Configuration', "$g_ConfigurationFile", );
- $g_Store = getkey ('Store', 'Configuration', "$g_ConfigurationFile", );
- } else {
- msg <<<#
- Script is not configured.
- The configuration wizard will assist you.
- #;
- sub "_Configure";
- }
- }
- "_Configure"
- {
- global $g_ConfigurationFile;
- msg <<<#
- This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.
- The configuration file is located at:
- $g_ConfigurationFile
- Steps:
- 1. Select ffmpeg.exe
- 2. Select ffprobe.exe
- 3. Select location to save files
- Done!
- #;
- // Delete old configuration file
- delete (0, 0, "$g_ConfigurationFile");
- // Define parameters
- global $g_ScriptVersion;
- global $g_FFmpeg;
- global $g_FFprobe;
- $g_FFmpeg = inputfile ('C:\', 'exe', 'Select ffmpeg.exe');
- $g_FFprobe = inputfile ('C:\', 'exe', 'Select ffprobe.exe');
- $g_Store = inputfolder ('C:', 'Select location to save files');
- // Write configuration to disk
- $Configuration = <<<#
- [Configuration]
- ScriptVersion=$g_ScriptVersion
- FFmpeg=$g_FFmpeg
- FFprobe=$g_FFprobe
- Store=$g_Store
- #;
- writefile ("$g_ConfigurationFile", "$Configuration", o, t);
- msg <<<#
- Configuration completed.
- #;
- }
- "Render - Specify bit rate"
- {
- global $g_FFmpeg;
- global $g_FFprobe;
- global $g_ExecutionFile;
- $Files = get ('selecteditemspathnames', |, a);
- $Files = formatlist ($Files, q, |, );
- $Type = input('Enter desired file type', , , s, , , );
- $Parameters = input('Enter FFMpeg command options', , , s, , , );
- delete (0, 0, $g_ExecutionFile);
- foreach ($File, $Files, |){
- $Command = '"'.$g_FFmpeg.'" -i '.$File.' '.$Parameters.' '.regexreplace ($File, '[.][^."]+', ".$Type", 0);
- writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
- }
- writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
- run ($g_ExecutionFile, , 0, 1);
- }
- "Render - Copy bit rate"
- {
- global $g_FFmpeg;
- global $g_FFprobe;
- global $g_ExecutionFile;
- global $g_ExecutionFileFFprobe;
- global $g_DumpFileFFprobe;
- global $g_Store;
- $Files = get ('selecteditemspathnames', |, a);
- $Files = formatlist ($Files, q, |, );
- $Type = input('Enter desired file type', , , s, , , );
- $Parameters = input('Enter FFMpeg command options', , , s, , , );
- delete (0, 0, $g_ExecutionFile);
- delete (0, 0, $g_ExecutionFileFFprobe);
- delete (0, 0, $g_DumpFileFFprobe);
- foreach ($File, $Files, |){
- //write show format command to file ffmpeg.dump.bat
- writefile ($g_ExecutionFileFFprobe, '"'.$g_FFprobe.'" -show_format '.$File.' > "'.$g_DumpFileFFprobe.'"', o, t);
- //execute ffmpeg.dump.bat and wait for completion
- run ($g_ExecutionFileFFprobe, , 2, 1);
- //retrieve bitrate from file ffmpeg.dump.ini
- $Bitrate = getkey ('bit_rate', 'FORMAT', "$g_DumpFileFFprobe", );
- //create ffmpeg command
- $Command = '"'.$g_FFmpeg.'" -i '.$File.' -ab '.$Bitrate.' '.$Parameters.' '.regexreplace ($File, '[.][^."]+', ".$Type", 0);
- writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
- }
- writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
- delete (0, 0, $g_DumpFileFFprobe);
- delete (0, 0, $g_ExecutionFileFFprobe);
- run ($g_ExecutionFile, , 0, 1);
- }
- "Books - Rename"
- {
- $Selection = get ('SelectedItemsPathNames', |, );
- foreach ($Book, $Selection, |){
- $Index = '1';
- $Base = getpathcomponent ($Book, 'base', );
- $Author = gettoken ($Base, 1, '-', t, );
- $Title = gettoken ($Base, 2, '-', t, );
- $Files = folderreport ('files', 'return', "$Book", , ,|);
- foreach ($File, $Files, |){
- $Track = format($Index, '000');
- if ($File == ''){
- break; //empty folders are skipped
- } else {
- renameitem ("$Track $Title", "$File", 1, );
- }
- $Index++;
- }
- }
- }
- "Books - Convert"
- {
- global $g_FFmpeg;
- global $g_FFprobe;
- global $g_ExecutionFile;
- global $g_ExecutionFileFFprobe;
- global $g_DumpFileFFprobe;
- global $g_Store;
- $Selection = get ('SelectedItemsPathNames', |, );
- foreach ($Book, $Selection, |){
- $Index = '1';
- $Base = getpathcomponent ($Book, 'base', );
- $Author = gettoken ($Base, 1, '-', t, );
- $Title = gettoken ($Base, 2, '-', t, );
- $Files = folderreport ('files', 'return', "$Book", , ,|);
- $Files = formatlist ($Files, q, |, );
- new ("$g_Store".'\'."$Base", 'dir', , );
- foreach ($File, $Files, |){
- writefile ($g_ExecutionFileFFprobe, '"'.$g_FFprobe.'" -show_format '.$File.' > "'.$g_DumpFileFFprobe.'"', o, t);
- run ($g_ExecutionFileFFprobe, , 2, 1);
- $Bitrate = getkey ('bit_rate', 'FORMAT', "$g_DumpFileFFprobe", );
- $Command = '"'.$g_FFmpeg.'" -i '.$File.' -vn -ab '.$Bitrate.' -metadata Genre="Audiobook" -metadata Artist="'.$Author.'" -metadata Title="'.getpathcomponent ($File, 'base', ).'" -metadata Album="'.$Title.'" -metadata Track="'.$Index.'" "'.$g_Store.'\'.$Base.'\'.getpathcomponent ($File, 'base', ).'.m4a"';
- writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
- $Index++;
- }
- }
- writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
- delete (0, 0, $g_DumpFileFFprobe);
- delete (0, 0, $g_ExecutionFileFFprobe);
- run ($g_ExecutionFile, , 0, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement