NextPVR Forums
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums General General Discussion v
« Previous 1 … 14 15 16 17 18 … 157 Next »
get working/batch/file dirs from one line[any dir of it's path too!]

 
  • 0 Vote(s) - 0 Average
get working/batch/file dirs from one line[any dir of it's path too!]
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#1
2011-01-24, 11:28 AM (This post was last modified: 2011-02-07, 01:08 PM by pBS.)
Get working/batch/file dirs from one line[any dir of it's path too!]
here's a little tool to use from batch files, how to get the current dir only, or any level of it's path.. [2 dirs up,3 up, 4 etc] not the whole path, just one part...
so if in c:\winnt\system32: "for %%A in ("..") do @echo %%~nA" would echo "winnt" Smile [one . would =system32]

Code:
for %%A in ("[color=blue]..\..\..\..[/color]") do  set dir4upworking=%%~nA
@echo %dir4upworking%
goes up 4 dirs from working dir.. go up as many as you want...Smile
or relative to batch file itself:
Code:
for %%A in ("[color=blue]%~dp0\[COLOR="deepskyblue"]..\..\..\..[/color][/COLOR]") do set dir4upbat=%%~nA
echo %dir4upbat%
to get a part of path for a file, call a Confusedubroutine inside batch with above line and filename as param, but use %~dp1 instead...[and of course a set statement or something instead of echo]

it's:
.= file's/current dir [or ".\" ]
..=1 up, parent dir [or ".\.."]
..\..=2 up [the parent dirs parent dir] [or ".\..\.."]
..\..\..=3 up etc etc..

that one surprised me..nice n short too..

from cmdline try it out:
Code:
for %a in (".\..") do @echo %~na
for %a in ("%~dpn0\..\..") do @echo %~na

use "set somevar=" in place of echo to use it for real in batches..

can be used to say, keep your dir structure when copying/encoding files to another location, among other things..
basically, easy relative paths for batches..
Enjoy
Big Grin
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
Northpole
Offline

Senior Member

Posts: 333
Threads: 34
Joined: Aug 2007
#2
2011-01-25, 01:48 AM
Thanks you for the useful tips! I can't tell you how many of your tricks I've use.
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#3
2011-01-29, 02:19 AM (This post was last modified: 2012-06-16, 07:16 AM by pBS.)
here's a way to detect if a program is running or not from batches..
Code:
set [color=blue]image[/color]=ffmpeg.exe
rem checks if [color=blue]%image%[/color] is running, and only runs [color=#FF0000]command [/color]after if it isn't...

@TASKLIST|findstr /I /B /c:"%image% ">NUL
@if %errorlevel% equ 1 ([color=#FF0000]@echo %image% is NOT Running!!![/color]) else @echo %image% IS running!!
[note space after %image% in "%image% "]
errorlevel is 0 if running, 1 if not...
replace ffmpeg.exe with process name you're checking for..[and "@echo %image% Is NOT Running!!" with your program]
Big Grin
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#4
2011-02-07, 07:28 AM (This post was last modified: 2011-02-28, 02:02 AM by pBS.)

  1. Relative HTML Links w/port
    Code to place relative html link with port..for gbpvr server type addresses..http://host:7647/gbpvr
    Usually relative links are no problem, unless you need to add port..then really no other way to do it..
    Code:
    [color=red]<script language=javascript>[/color]document.writeln('<A HREF="http://' + location.host + '[color=blue]:7647/gbpvr[/color]">[color=blue]GBPVR[/color]</A>')[color=red]</script>[/color]
    only change parts in blue..
    so,
    1. If you came to the page with an ip number [xxx.xxx.xxx.xxx]
    2. Or if it's using dns name [http://www.host.org]
    3. Or if you have multiple domain names pointing to same page, this will let all of them work, links will look like they are relative to whatever page they come in on...
    4. Or if you came to it through the local network [//LocalServerName:7647] it will work also..Big Grin
    But it's really only useful if you need to specify a port, like a link to ftp server on same server[:21] Otherwise use a normal relative link..

    wow, 4000+ posts...lol Big Grin


  2. Here's a link to page with ffmpeg cmd to alter audio sync..
    http://forums.nextpvr.com/showthread.php...ith-ffmpeg!


  3. Plus, for an interesting take on ffmpeg, try ffmbc...'FFMpeg Broadcast Quality'
    has -vfilters like mencoder, some other pro format stuff, and other tweaks....works well..
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#5
2011-03-16, 08:44 AM (This post was last modified: 2012-06-16, 07:02 AM by pBS.)
here's a cmd to make any batch file self-minimizing...Big Grin
Code:
@if not "%~1" == "$" start "%~nx0" /min cmd /c "%~f0" $ %* && exit
@shift /1
rem Your code goes here...

as long as you don't need to use "$" as first param it will work fine, tho you can change that to any char that wouldn't conflict with params you wish to use..

just stick it at top of any batch file and watch it minimize itself immediately and continue running..Smile

About the 'shift':
works with all params as original number, the 'shift' shifting them back into %1 %2 %3 etc., removing the "$" from original params...
example, run batch with: "batchfile.bat a b c d"
When it REruns, the $ will get 'shifted' out, and params will still be %1=a %2=b %3=c etc., but without shift: %1=$ %2=a %3=b etc.....
fixed to correct %~dpnx0 processing [shift /1 instead of just shift, so it'll keep %0 intact]
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#6
2011-08-02, 08:52 PM (This post was last modified: 2011-08-03, 08:25 AM by pBS.)
Here's a batch file that will help you search/replace a line in a text file, including .xml!
you need to supply the full line for both search and replacement..
params are "filename" "line to be replaced" "line to replace it with"
to use spaces/tabs in query, muct use batch file to call this one, can't use tabs on commandline...

Save this as editall.bat
Code:
@echo off
cls
if "%~3"=="" echo Needs 3 params: file to edit, line to replace, new line, to work.. && goto :eof
;set file=%~1
del /q "%file:~0,-2%" >NUL 2>&1
set new=%3
set new=%new:<=^<%
set new=%new:>=^>%
set new=%new:|=^|%

for /f "skip=2 tokens=1,* delims=]" %%g in (`"findstr /n ^^ %1"`) do (
if "%%i" equ "" >> "%file:~0,-2%" echo.
if "%%i" equ "%~2" (
>> "%file:~0,-2%" echo.%new:"=%
echo FOUND!!
) else (
>> "%file:~0,-2%" echo.%%i
)
)
move /y "%file:~0,-2%" %1

and use like:
call editall.bat "filename" "oldline" "newline"
i'll be making a search/replace version that will match partial lines and replace them with your full line soon..
Enjoy Big Grin
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#7
2011-08-03, 08:16 AM
because of the above batch file and empty line processing troubles, i learned a neat new batch variable processing trick today..
when substituting text in a variable, like %var:this=that%, you can use * to denote everything before delimiter...
like: %var:*this=that% meaning, turn the first match of 'this', and everything before it, into 'that' Smile

say you have a variable called 'var' and in it is: "take this home"
echo %var:*this=that% would display "that home"
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
Reddwarf
Offline

Posting Freak

Posts: 6,628
Threads: 229
Joined: Mar 2007
#8
2011-08-03, 09:51 PM
What that guy knows!! Big Grin

"I'd rather have a bottle in front of me than a frontal lobotomy"
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#9
2011-10-03, 03:56 PM (This post was last modified: 2012-06-16, 07:32 AM by pBS.)
Here's a little batch i whipped up to automatically rip your dvd's to your hard drive.
It detects the dvd drive, looks for a video dvd in it, and determines correct main-movie title with mplayer, then rips it to mpeg4[divx] .avi, around 700-1100megs with extremely little loss...Big Grin [constant quality]
Filename generated from volume label of drive[usually same as the title of movie]

It doesn't need any other decryption software, as mencoder can do that itself, and drive detection and title detection are accomplished using diskpart and mplayer.exe respectively..

Just place mencoder.exe and mplayer.exe in same dir as batch, and edit top of batch to specify output dir, and run batchfile to start ripping..
If you'd like to rip a dir, just specify it as first command line option..

Code:
@echo off
@cls
rem         !!!!!!!!!!!Set below to specify output dir for all files. [include trailing '\']  example: \\pvr\s\dvd\ or s:\dvd\ !!!!!!!!!
set outpath=\\pvr\s\mpg\dvd\

rem Defaults: [usually never need changing]
set out=dvd
set dvdvol=dvd.avi

echo.
echo.
echo                           DVD to AVI Ripper
echo.
echo.

rem  Diskpart legend:  %%B=Volume # %%C=letter %%D=vol-label %%E=filesystem %%F=Type %%G=SIZE %%H=SIZE MULTIPLIER[mb/gb/etc] %%I=status %%J=Info

if "%~1"=="" (
FOR /F "tokens=1,2,3,4,5,6,7,8,9,10  delims= " %%A in ('ECHO list volume ^| DISKPART.EXE ^| FIND.EXE "-ROM "') DO (
if exist %%C:\VIDEO_TS\. (
  set disk=%%C:
  set out=%%C:
echo Detected Disk = %%C:
) else ( echo No DVD-Video disk found in any drive!!
    pause
       exit)
)
)
echo.
echo.
echo.

if not "%~1"=="" set disk=%~1
if not "%~1"=="" set out=%~1

if "%disk:~-1%"=="\" set disk=%disk:~0,-1%

call :getname "%disk%"
@set lastsize=0
@set bigtitle=0
@rem mplayer -identify dvd:// -nosound -novideo -dvd-device "%disk%" >dvdtmp.txt 2>NUL
@FOR /F "usebackq tokens=1,2,3,4,5,6,7,8,9 delims==_." %%i IN (`@mplayer -identify dvd:// -nosound -novideo -dvd-device "%disk%"  2^>NUL`) do @if "%%m"=="LENGTH" call :getlongest %%l %%n
echo.
echo.

set /a lastsize=%lastsize%/60
echo     Detected title %title% in "%disk%" is %lastsize% minutes long.
echo.
@echo  Now Ripping DVD in "%disk%" Title-%title% to "%outpath%%out%.avi"
@title Ripping DVD in "%disk%",Title-%title% to "%outpath%%out%.avi"
echo.
echo.
echo.

rem The Heavy Lifting....
echo %disk% - %title% - "%outpath%%out%.avi"
mencoder -cache 10240 -dvd-device "%disk%" dvd://%title% -alang en -vf filmdint,softskip,hqdn3d=3:2:3:3,harddup -o "%outpath%%out%.avi"  -fps 30000/1001 -ofps 24000/1001 -oac mp3lame -lameopts cbr:br=128 -ovc lavc -ffourcc XVID -idx  -lavcopts vcodec=mpeg4:abitrate=160:acodec=mp3:autoaspect:keyint=30:vqscale=2.4:vqmin=2 -af volume=18
goto :eof

:: The End
:: Subs Below

:getlongest
@if %2 GTR %lastsize% (
set lastsize=%2
set title=%1
)
@goto :eof

:getname
rem   Get name from either volume label if whole disc, or dir name if path....
if not "%out:~-1,1%" == ":" (set out=%~n1
echo Dir name used for filename: %~n1
    ) else (
        FOR /F "tokens=6 usebackq delims= " %%i IN (`vol %1`) DO set out=%%i
)
@goto :eof

Adjust the mencoder line to your quality preferences, usually just adjust the qscale= param to alter size/quality tradoff..
You can substitute VLC for mencoder, but mplayer would still be needed.
it's setup for NTSC but could easily be adjusted for PAL.. Smile please share if you do..
i'll do some cleaning and beautification of it later..lol

Put it in a Custom command menu item for quick and easy npvr rips Big Grin
Enjoy!
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#10
2011-10-04, 11:49 AM (This post was last modified: 2012-02-26, 03:35 AM by pBS.)
Here's a little trick to enable multi-line comments and echo-ing lines with a single echo command:
Code:
rem.^

these are some comments^

comments line2^

comments line3^

comments line4
would show [with 'echo on']:
Code:
rem.
these are some comments
comments line2
comments line3
comments line4
NOTE the extra blank lines, they are needed to give carriage return, without them everything's on one line.
The "rem.^" is necessary at the beginning, and all lines must end with "^" except the last one
Benefit is you don't have to type 'rem ' at beginning of each line..Big Grin


The same works for echoing lines:
Code:
@echo line1^

line2^

line3^

line4
would output:
Code:
line1
line2
line3
line4

whereas without the extra lines,
Code:
@echo text1^
text2^
text3^
text4
would output:
Code:
text1text2text3text4
notice no extra blank lines between lines..

This can also be used to make multi-line variables!
Code:
set test=line1^

line1^

line3
but it's a bit tricky to use those variables..eg: echo doesn't work right..

"set test"
Produces:
Code:
test=line1
line2
line3
echo %test%
produces:
Code:
line1

basically what's happening is, the ^ escapes the next character, which is carriage return, but keeps linefeed...
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  VidImport not working tesla1886 36 4,750 2023-01-24, 06:29 PM
Last Post: mvallevand
  Comskip config file spudjg1 0 1,645 2019-08-26, 02:49 PM
Last Post: spudjg1
  TS and PART file? Download/recording tv streams joeijm 5 2,544 2018-03-25, 01:53 AM
Last Post: joeijm
  download button not working momofterrors 0 1,259 2016-06-20, 11:16 PM
Last Post: momofterrors
  Not saving in s01e01 file format jeflatt 4 2,326 2015-09-30, 08:26 PM
Last Post: mvallevand
  Replace video file without windows telling apps the original was deleted? ATHiker 0 1,246 2013-11-25, 09:23 PM
Last Post: ATHiker
  Working on Server 2012 darrenmunday 3 3,040 2013-10-31, 09:47 PM
Last Post: jyan_osu
  <Enter> to drop a line in forum posting screen no loger works? jksmurf 3 1,822 2013-09-28, 09:44 AM
Last Post: whurlston
  H/W Quick sync transcoding from the command line. mvallevand 2 2,983 2013-03-23, 08:25 AM
Last Post: pBS
  Need Help With Video File Types bdgbill 8 3,148 2012-12-30, 11:43 PM
Last Post: Reddwarf

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode