Showing posts with label DOS Script. Show all posts
Showing posts with label DOS Script. Show all posts

Thursday, October 21, 2010

Windows 7 laten slapen met een script

How to put windows 7 to sleep in a script
For English version, see below

In een DOS script kun je b.v. na het afronden van het script de PC laten slapen. Tot nu toe lukte dat niet omdat mijn PC steeds in hibernation ging i.p.v. slaap.

Om de PC te laten slapen moet je eerst hibernation uitschakelen. Dit kan vaak lastig zijn, maar Microsoft komt je hier te hulp. Op deze pagina zie je twee kleine programmaatjes waarmee je hibernation kunt uitschakelen en aanschakelen. Door eerst het hibernation uitschakelen programma te draaien kun je het volgende commando gebruiken om je PC te laten slapen aan het einde van een DOS script.

rundll32.exe powrprof.dll,SetSuspendState 0,1,0

Nadat je het Fixit programmaatje voor het herstellen van hibernation hebt gedraaid, zal het boven genoemde commando de PC weer in hibernation brengen.

How to put your PC to sleep through a DOS command

When I tried to put my PC to sleep through a DOS command, it used Hibernation, not the sleep (suspend) mode. In order to force the PC to use the sleep mode, you have to disable hibernation. This turning hibernation on/off has been made easy by Microsoft through two Fixit tools, which can be found here. After you ran the disable hibernation tool, the command below will put your PC to sleep. If you want to change back to use hibernation, just run the other tool and the command will put your PC back into hibernation.

Command:
rundll32.exe powrprof.dll,SetSuspendState 0,1,0

Success.

Saturday, May 15, 2010

Podcast manipulatie script


Al sinds 2005 gebruik ik Juice, nu al een paar jaar versie 2.2. Waar ik die versie vandaan heb weet ik niet meer maar op sourceforge staat nog steeds versie 2.0.
Maar goed, nadat de bestanden gedownload zijn wil ik ze eerst uniform maken.
Sommige MP3's hebben namen van meer dan 100 karakters lang.

Zoals deze van meer dan 150 tekens, waarbij de tekens in rood tracking tekens zijn:

dailysourcecode-231472-05-15-2010_pshow_352992_dopvhost_media_podshow
_com_doppl_0f98d82d4477dccd4427dc9d013759b3d0f252c2_dopsig_e2705c144
ee77c66df70c7a296d17c94.mp3

Dat vinden mijn iRivers niet zo fijn, dus breng ik die bestandsnamen terug naar maximaal 60 tekens.
Daarna maak ik de bestanden kleiner door ze naar 32kb/s mono te converteren.
De Podcasts waar ik naar luister zijn toch alleen maar gesproken woord (m.u.v. de DSC)...
Omdat Lame (bij het converteren) niet zo'n goede job doet om de podcasts allemaal even luid te laten klinken gooi ik de gekrompen bestanden door mp3gain heen. Hierdoor klinken de Podcasts allemaal even luid en hoef ik niet steeds aan de volume knopjes te zitten...
Lame verliest bij de conversie de ID3 tags, daarom kopieer ik, na de conversie, de ID3 tag van het oorspronkelijke bestand naar het nieuwe gecomprimeerde bestand.

Ik heb de programma's allemaal in "C:\Program Files\MyPrograms\" staan.
De programma's zijn:
id3.exe http://home.wanadoo.nl/squell/id3.html
lame.exe http://lame.sourceforge.net
mp3gain.exe http://mp3gain.sourceforge.net/

Processing mp3 files after downloading them with Juice.
I listen to podcasts and I want all files to be small, so I can carry many of them on my iRiver. For that reason, I reduce the file lengths to a maximum of 60 characters, then I have lame convert the files to 32kb/s mono.
In the process the ID3 tags are lost, so I resolve this by copying the ID3 tags from the original files to the reduced files. (The message from Lame.exe is: Be aware that the ID3 tag is currently lost when transcoding.)
In order to make them all sound equally loud I run them through mp3gain.

=====START PodcastScript.bat =====
@ECHO OFF

REM Move all files in TempDirectories to Temp0 directory, this can be done in Juice, but did not work for the ARGOS podcast under Win-XP as there is a >> in the path. Under Win-7, this works just fine.
REM Juice is configured to place all downloaded files in subdirectories under C:\2Podcasts\TempDirectories

REM Copy all files from the Juice temp directories to one single directory TempZero
cd C:\2Podcasts\TempDirectories
FOR /R %1 %%G IN (*.*) DO (
move "%%G" C:\2Podcasts\Temp0\
)

REM rename partially downloaded files from .mp3.partial to .mp3
REM Most partial files are actually fully downloaded, just not renamed
cd C:\2Podcasts\Temp0
FOR /R %1 %%G IN (*.partial) DO (
ren "%%G" "%%~nG"
)

REM Move mp3 files to Temp1 and then move remaining files to RemainingFiles directory
Move /Y C:\2Podcasts\Temp0\*.mp3 C:\2Podcasts\Temp1\
Move /Y C:\2Podcasts\Temp0\*.* C:\2Podcasts\RemainingFiles\

REM All active files are now in Temp1

REM Truncate filenames longer than 60 characters
setlocal EnableDelayedExpansion
cd "C:\2Podcasts\Temp1"
REM loop over all files in the cwd
for /f %%a in ('dir /a-d /b') do (
REM store this filename in a variable so we can do substringing
set ThisFileName=%%a
REM Set a filename without the extension
set ThisFileNameNOEXT=%%~na
REM now take a substring after removing the extension
set ThisShortFileName=!ThisFileNameNOEXT:~0,60!
REM finally, the rename. I use the shortfilename with an * to handle spaces in he filenames
ren !ThisShortFileName!* !ThisShortFileName!.mp3
)
:EOF
endlocal

REM All active shortnamed files are in Temp1

REM Re-encode all files to 32kbs at 32kHz sample rate from Temp1 to Temp2
REM Copy the lost ID3 Tags from the original file back to the re-encoded file.
REM ID3 is located on: http://home.wanadoo.nl/squell/id3.html
cd C:\2Podcasts\Temp1
FOR /R "C:\2Podcasts\Temp1" %1 %%G IN (*.mp3) DO (
"C:\Program Files\MyPrograms\lame.exe" -f -a -b 32 --resample 32 "%%G" "C:\2Podcasts\Temp2\%%~nxG"
"C:\Program Files\MyPrograms\id3" -D "%%G" -1 -2 "C:\2Podcasts\Temp2\%%~nxG"
)
Move /Y C:\2Podcasts\Temp1\*.mp3 C:\2Podcasts\Backup2\

REM All original shortnamed files are in Backup2
REM All reduced shortnamed files are in Temp2

REM Ensure that all mp3's sound equally loud, files will remain in Temp2
"C:\Program Files\MyPrograms\mp3gain.exe" /r /d -4 /c /p C:\2Podcasts\Temp2\*.mp3

REM All reduced shortnamed files are still in Temp2

REM Move original files to Backup2 and the re-encoded files to LeveledFiles
Move /Y C:\2Podcasts\Temp2\*.mp3 C:\2Podcasts\LevelledFiles
Move /Y C:\2Podcasts\Temp2\*.* C:\2Podcasts\Backup2\

REM Turn the system to sleep
REM echo "Puting system to sleep"

REM pause
REM ping 127.0.0.1 -n 2 -w 1000 > nul
REM %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState
REM echo "Shutting system down"
REM shutdown.exe -s -f

=====END DOS Script voor Podcasts van Juice=====


=====Start of Copy ID3 tag script=====
REM I only needed this once to catch up with previously converted mp3's.
REM Copy the ID3 tag from the original files over to the re-encoded files that lost their ID3 tag.
REM Original files: "C:\2Podcasts\Backup2"
REM Re-encoded files: "C:\2Podcasts\LevelledFiles"

cd "C:\2Podcasts\Backup2"
FOR /R "C:\2Podcasts\LevelledFiles" %1 %%G IN (*.mp3) DO (
"C:\Program Files\MyPrograms\id3" -D "C:\2Podcasts\Backup2\%%~nxG" -1 -2 "C:\2Podcasts\LevelledFiles\%%~nxG"
)

=====End of copy ID3 Tag script=====

Wednesday, December 16, 2009

Lange bestandsnamen inkorten, How to shorten long file names


Als ik via Juice podcasts download zitten er vaak bestanden bij met een gigantisch lange naam. Het laatste deel van de bestandsnaam zijn tracking markers. Mijn MP3 spelers (allemaal iRivers) kunnen die extreem lange bestandsnamen niet aan. Het gevolg is dat ze als er een lange bestandsnaam op staat die iRivers continue in een reboot loop komen. Dan moet ik ze weer even via de USB kabel aansluiten om de lange bestandsnamen in te korten.

Die bestanden zien er dan ongeveer zo uit:
PodcastBestand_nvb_20091207174750_nva_200912081757.mp3
met heel veel "nva" en "nvb" referenties.

Sinds enige tijd gebruik ik nu FileNameFixer. Dit programmatje kun je instellen op een vaste directory en een maximale bestandslengte. Nadat alle MP3 bestanden in één directory zijn verschoven (bij Juice in het [Preferences]-[Advanced] gedeelte met het volgende script: move "%f" "C:\Podcasts\TempFiles\") laat ik eerst FileNameFixer zijn werk doen alvorens een batch scriptje te draaien die alle podcasts op de zelfde geluidssterkte zet. Dat scriptje ziet er zo uit:

"C:\Program Files\MyPrograms\mp3gain.exe" /r /d -4 /c /p C:\Podcasts\TempFiles\*.mp3
Move /Y C:\Podcasts\TempFiles\*.mp3 C:\Podcasts\LevelledFiles\
Move /Y C:\Podcasts\TempFiles\*.* C:\Podcasts\RemainingFiles\
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState

De eerste regel start het programma mp3gain in command line mode en loopt alle zojuist gedownloade podcasts door om ze allemaal het zelfde geluidsniveau te geven. Daarna worden alle MP3 bestanden gekopieerd naar LeveledFiles en alle overige files (meestal video bestanden of PDF's) naar RemainingFiles. Het laatste commando zet de PC in slaap. Soms gebruik ik op de laatste regel: shutdown.exe -s -f als ik de PC na afloop wil laten afsluiten.

UPDATE: Omdat ik alles via een script wilde laten werken heb ik het inkorten van lange bestandsnamen als DOS script uitgewerkt. Ga naar het volgende artikel om te lezen hoe je dit automatisch in DOS kunt doen: Podcast-manipulatie-script

Cutting long podcast file names.
Some podcasts have long tracking postfixes in their file names which makes my iRivers contstanly reboot. A few months ago, I added an extra step in my download procedure.
I download the podcasts with Juice and within Juice I automatically copy all the files to one central directory (in Juice [Preferences]-[Advanced] add the following script: move "%f" "C:\Podcasts\TempFiles\"). Then I use FileNameFixer to automatically cut the long file names to a maximum length of 60 characters (with a default directory of C:\Podcasts\TempFiles and a default file length of 60). Ater that I run the script above to make sure all audio levels are the same, as I hate these huge variations in recording levels between different podcasts. After processing the mp3 files, the mp3's are copied to LeveledFiles and the remaining files (mostly video and pdf's) are copied to RemainingFiles. The last command line puts the PC in suspend (sleep) mode as I often run the mp3gain script at night.

UPDATE: Since I want to run everything in a script, I created a DOS script to automatically reduce long file names to a fixed maximum length. To read more about this script follow this link: Podcast manipulation script