Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need to write a script - no idea where to start - PHP HELP NEEDED
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need to write a script - no idea where to start - PHP HELP NEEDED

VPNshVPNsh Member, Host Rep
edited September 2012 in Help

Ok guys, so I am in need of a script to write. It'll need to do the following:

  1. Access a folder that I have selected
  2. Rename the file within that folder
  3. Move the file into a separate folder
  4. Run an FFMPEG conversion command
  5. Remove original file

Any ideas on where I could/should start with this?

Liam

Comments

  • NexusNexus Member
    edited September 2012

    I could help, but unfortunately stuck at #4, lol. I know all the commands 1 -3 and 5. But 4 I have no idea how to run a FFMPEG conversion command...

    I am sure someone here will help you! :) Be Patient :O

  • I like Java. Do everything in Java!

  • VPNshVPNsh Member, Host Rep

    Only thing is, the script needs to be dynamic. Needs to be able to rename a file within that folder regardless of what the original file name is.

    Basically it's for going through my collection of TV series.

    Needs to access the folder where the video files are kept, rename the files individually to make them more recognisable, move them elsewhere, convert from avi to flv (stream through browser on home network for family), then remove original file.

    Just lost atm D:.

  • telephonetelephone Member
    edited September 2012

    @liamwithers said: Needs to access the folder where the video files are kept, rename the files individually to make them more recognisable, move them elsewhere, convert from avi to flv (stream through browser on home network for family), then remove original file.

    CouchPotato, Sickbeard, and Plex. Done and done.

    CouchPotato (movies) and Sickbeard (tv) for renaming and keeping track of your collection. Plex for a media center that can stream to any device.
    It won't remove the original file, but it will on the fly perform an ffmpeg stream so you can watch the video on mobile and more if the original file format is not capable of playing on said device.

  • @liamwithers Windows?

    Do it in Java, multithread that shit.

  • @liamwithers said: Ok guys, so I am in need of a script to write. It'll need to do the following:

    Access a folder that I have selected

    Rename the file within that folder
    Move the file into a separate folder
    Run an FFMPEG conversion command
    Remove original file

    Any ideas on where I could/should start with this?

    Maybe by defining the parameters....

    What's the basis for the new file name for renaming files?
    What's the new folder going to be named?

    And providing a sample of what you have, e.g. a sample directory listing.

  • @AsadHaider said: I like Java. Do everything in Java!

    Maybe he needs to run it in a 128mb VPS.

  • @Soylent With Java? Not a chance, 4GB should be enough right?

    Thanked by 1Soylent
  • Seriously, bash

    Thanked by 1klikli
  • What you are writing on command line can be used exactly same in bash
    You can do all the stuffs you listed on command line, can't you?
    Now with a bit of tweak with bash codes such as loop, output and error handling, you can make robust script for whatever you want on Linux.

  • VPNshVPNsh Member, Host Rep

    Ok, so I could use Bash.. but basically it's my torrented collection from online. So some of the names of files are a little confusing, or when I've downloaded individual episodes, the layout for the name has been different. I want to change them all to be me more consistent.

    The script doesn't need to access a SPECIFIC folder.. it needs to access a folder which I haven't defined a name for. It then needs to be able to make the conversion on any .avi files, whilst renaming them, without me defining the original name. Obviously it would be a lot easier if I was giving it direct instructions: Go to this folder, fetch this file, rename it to this, convert it, move it.

    Obviously it's slightly different to that though, seeing as I'm dealing with multiple files, and would rather have the script do it for me than do it manually through all of them.

    I understand you guys say I can do this in bash, but I've never used bash before.. anybody able to give me a pointer or two as to how to do this? Would rather have some first-hand knowledge than being pointed towards a tutorial site, because that's not what I need in this case.

    Cheers

  • @liamwithers - do it one file by hand, post the commands here - we can take generalising the commands into a bash script from there...

  • @liamwithers Use sickbeard to organise all the files, then maybe run the converter script to do whatever you want. Or maybe sickbeard lets you run scripts on files? I don't use it myself.

  • hm.. in VIsual Basic it would be nice

  • Could PHP script that :L, seems pretty simple to do; just need to figure out your conversion script; there will be something, and just make it wait until finished, using arguments from the script found online.

    Seems pretty easy :D!

  • Why would you bring PHP into something that can be done entirely in a shell script?

  • @Gary - Gives expandability to make a interface for you to view the converted file; have a gallery of files converted etc. Depends what you're fluent in. I'd prefer PHP to Bash.

    Thanked by 1tridinebandim
  • VPNshVPNsh Member, Host Rep

    Ok, think I'm gonna be doing this in PHP.

    For doing the FFMPEG command, is it simply:

    shell_exec("FFMPEG COMMAND"); ?

    Also, can you use PHP variables within shell_exec?

    Basically I'll be wanting to do the following:

    ffmpeg -i $FILENAME $FILENAME.flv

    $FILENAME being a PHP variable :)

  • VPNshVPNsh Member, Host Rep

    Ok, so I'm stuck for ideas.

    Currently I've got a script that takes all of the video filenames from within a folder, and places them line-by-line in a text file like so:

    file1.mp4
    file2.mp4
    file3.mp4
    file4.mp4
    etc...
    etc...

    I'm able to select each individual line as so (example to select fourth line):

    $content = file('test.txt');
    echo $content[3];

    Now what I need to be able to do is perform an FFMPEG command on each one of these until I have reached the final line of the text file.

    Any ideas on:

    1. how to perform an FFMPEG command from within PHP?
    2. how to loop this for each line until the final line has been reached?

    Thanks guys, appreciate your patience :)

  • Expand: For doing the FFMPEG command, is it simply:

    It would be ffmpeg... *nix are case-sensitive.

  • VPNshVPNsh Member, Host Rep
    edited September 2012

    @Damian yeah that's fine.. I know the command I'd need to use, just need to know how to do this for each video file which is defined in the text file. ffmpeg command I'd be using is:

    ffmpeg -i $filename -f flv -qscale 5 -r 25 -ar 44100 -ab 96 -s 500x374 $filename.flv

    Just need to know how this is all gonna work from each line of the text file :/

  • @liamwithers said: how to loop this for each line until the final line has been reached?

    http://us.php.net/manual/en/control-structures.foreach.php is what you're looking for.

  • Use something like...

    Do until EOF(1) {
    for each $line as $filename {
    ~~~~
    }
    }

Sign In or Register to comment.