# Program to create .txt files for show series?



## superflysocal (Nov 26, 2009)

Is there a script or program that will create a txt file for a bunch of tv show files so that it will be sent over in one folder.

I believe there is a tutorial to do it manually, but wanted a way to automate it.

For example, I have a bunch of work out videos in mp4 format. I would like to transfer them over to tivo premiere under one folder, let's call it "P90X". Is there a way to automate this?


----------



## orangeboy (Apr 19, 2004)

I'm about to go function with the family, but think I have time to post this bit of Windows command line that I use in a script that pushes videos:


```
:MetaData
::-----------------------------------------::
:: Create metadata if there isn't any      ::
::-----------------------------------------::
IF NOT EXIST "&#37;~dpnx1.txt" (
	"\\DL380-Server\lan path\pyTivoMetaThis.py" -d -p "!ThisPath!"
)
IF NOT EXIST "%~dpnx1.txt" (
	>"%~dpnx1.txt" ECHO episodeTitle : "%~n1"
)
```
%1 indicates a full path+filename variable passed to the script. Using the tilde (~) and lowercase letters (dpnx) will cull file attributes from the variable, specifically:

d = drive letter
p = path
n = file name
x = file extension

So the above looks for full path+filename+.txt (the metadata file). If one is not found, try to create one using pyTivoMetaThis (preferred). If pyTivoMetaThis cannot find a match in the database (which would be your situation with P90X), it would fall through to creating a simple metadata file with only the filename as the episode title. More "ECHO"s would be required to add in seriedId, isEpisodic, isEpisode, title, or whatever other keywords that are required for consistent grouping.

I could help with a script after the family function, if Windows is the OS flavor you use, and if you wanted to provide a bit of detail as far as your directories are structured (could help determine if hardcoded directory names would be wanted/needed in the script, or "drag & drop" of a folder onto the script would be wanted/needed). PM's may be more appropriate for the nitty-gritty details.


----------



## superflysocal (Nov 26, 2009)

Dude that would be so awesome if you can help me with this. The more drag and drop, the easier to use, the better. i am surprised no one has desired this before.

this is what I think is needed minimally:

title : P90X
SeriesTitle: P90X
episodeTitle : P90X - 02 - Pylometrics
episodeNumber : 2
isEpisode :true
seriesId : SH999905

right now file name is in this format, though not sure if it is necessary.
P90X_S01E02_Pylometrics.avi


----------



## orangeboy (Apr 19, 2004)

superflysocal said:


> Dude that would be so awesome if you can help me with this. The more drag and drop, the easier to use, the better. i am surprised no one has desired this before.
> 
> this is what I think is needed minimally:
> 
> ...


Quick question: Are your titles grouped in folders, or are they all like the example shown above, where the title is part of the filename? Or a combination of both?


----------



## superflysocal (Nov 26, 2009)

both, i think.

all the files are currently in one folder called P90X

Each file name is like above P90X_S01Exx_nameofworkout.avi


----------



## orangeboy (Apr 19, 2004)

superflysocal said:


> both, i think.
> 
> all the files are currently in one folder called P90X
> 
> Each file name is like above P90X_S01Exx_nameofworkout.avi


Ok. I'll probably end up making two versions: One to use the folder's name to create the title & seriesTitle keyword values, with episodeTitle being the filename as more of a general purpose script, and a second that parses the filename to get that information.

And something else came up during a discussion of seriesIds in another thread: Do you intend to push or pull the videos to TiVo? Push is when the pyTivo web interface is used to send a file to a selected TiVo; Pull is when the file is selected from the pyTivo share found in the NPL, on the TiVo itself...


----------



## superflysocal (Nov 26, 2009)

I usually would push but I forgot which one is better or faster so I can go either way.

thanks.


----------



## orangeboy (Apr 19, 2004)

I haven't given up on this. Just got wrapped up in other projects. I also was going to try to incorporate pyTivoMetaThis into the script, but I'm going to abandon that effort*. However, I will incorporate the "Tidy" feature as an option, where the metadata files are stored in a ".meta" subdirectory.

*The pyTivoMetaThis that I use has been customized by me to also accept filenames instead of just a folder name as input to that program. I'd rather not have to have a requirement of using that customized program to make this Windows script work.


----------



## orangeboy (Apr 19, 2004)

This version uses the directory name as the title, seriesTitle, and _seriesId_, while the file name is used for the episodeTitle and description. 
When it is run for the first time, it will ask: "Use pyTivo .meta directory to store metadata? (Y/N)". This gives the ability to store the metadata files in a ".meta" subdirectory, essentially keeping the video directory clear of text files.

Drag a single file, a group of files, a single directory or a group of directories onto the batch file to process the video files. Tested on WinXP, and offered "as-is".


```
::-----------------------------------------::
:: Set batch file parameters and options.  ::
::-----------------------------------------::
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
2>NUL CALL :Set_Options || IF !ERRORLEVEL! GTR 0 CALL :Get_Options

:Loop
::-----------------------------------------::
:: Process until arguments are empty       ::
::-----------------------------------------::
IF "&#37;~1"=="" GOTO Done

::-----------------------------------------::
:: Test for file, directory, or UNC path   ::
::-----------------------------------------::
2>NUL PUSHD "%~1"
IF /I %errorlevel% EQU 1 (
    PUSHD "%~dp1"
    CALL :Is_File "%~nx1"
    POPD
) ELSE (
    CALL :Is_Directory "%~1"
    POPD
)

:End
::-----------------------------------------::
:: Argument is processed, go get next one  ::
::-----------------------------------------::
SHIFT
GOTO Loop

:Done
::-----------------------------------------::
:: Go back from wence you came             ::
::-----------------------------------------::
EXIT /B

::-----------------------------------------::
:: A file/set of files has been passed to  ::
:: the script. Use the file name as        ::
:: episode title.                          ::
::-----------------------------------------::
:Is_File
SET ThisPath=%~dp1
SET ThisPath=!ThisPath:~0,-1!
SET episodeTitle=%~n1
CALL :Get_title "!ThisPath!"
IF NOT EXIST "%~dpnx1.txt" (
    IF /I "!UseMetaDir!" EQU "Y" (
        IF NOT EXIST "!ThisPath!\.meta" (
            MKDIR "!ThisPath!\.meta"
            SET where="!ThisPath!\.meta\%~nx1.txt"
            CALL :Create_Meta_File "!where!"
        ) ELSE (
            SET where="!ThisPath!\.meta\%~nx1.txt"
            CALL :Create_Meta_File "!where!"
        )
    ) ELSE (
        SET where="!ThisPath!\%~nx1.txt"
        CALL :Create_Meta_File "!where!"
    )
)
GOTO :EOF

::-----------------------------------------::
:: A directory was passed to the script.   ::
:: Look for known video extenstions, and   ::
:: create metadata for all files found.    ::
::-----------------------------------------::
:Is_Directory
CALL :Get_title "%~1"
FOR %%A IN (%extensions%) DO (
    FOR /F "delims=" %%B IN ('DIR /B /S "%~1\%%A"') DO (
        IF /I "%%~xB" NEQ ".txt" (
            SET episodeTitle=%%~nB
            IF /I "!UseMetaDir!" EQU "Y" (
                IF NOT EXIST "%~1\.meta" (
                    MKDIR "%~1\.meta"
                    SET where="%~1\.meta\%%~nxB.txt"
                    CALL :Create_Meta_File "!where!"
                ) ELSE (
                    SET where="%~1\.meta\%%~nxB.txt"
                    CALL :Create_Meta_File "!where!"
                )
            ) ELSE (
                SET where="%~1\%%~nxB.txt"
                CALL :Create_Meta_File "!where!"
            )
        )
    )
)
GOTO :EOF

::-----------------------------------------::
:: Display the metadata that has been      ::
:: constructed, then write the data to the ::
:: appropriate location.                   ::
::-----------------------------------------::
:Create_Meta_File
ECHO title : !title!
ECHO seriesTitle : !title!
ECHO seriesId : !title!
ECHO episodeTitle : !episodeTitle!
ECHO description : !episodeTitle!
ECHO isEpisode : true
ECHO isEpisodic : true
ECHO.
    
> !where! ECHO title : !title!
>>!where! ECHO seriesTitle : !title!
>>!where! ECHO seriesId : !title!
>>!where! ECHO episodeTitle : !episodeTitle!
>>!where! ECHO description : !episodeTitle!
>>!where! ECHO isEpisode : true
>>!where! ECHO isEpisodic : true
GOTO :EOF

::-----------------------------------------::
:: Set the directory name to be the title. ::
::-----------------------------------------::
:Get_title
SET title=%~nx1
GOTO :EOF

::-----------------------------------------::
:: Set the filename to be the episode      ::
:: title.                                  ::
::-----------------------------------------::
:Get_episodeTitle
SET episodeTitle=%~n1
GOTO :EOF

::-----------------------------------------::
:: Update the script with user options.    ::
::-----------------------------------------::
:Get_Options
SET extensions=*.3g* *.amv *.asf *.av* *.bi* *.box *.bsf *.dat *.di* *.dmb
SET extensions=%extensions% *.dpg *.dv* *.evo *.eye *.fl* *.gvi *.ivf *.m1v
SET extensions=%extensions% *.m2* *.m4* *.mjp* *.mkv *.mod *.moov *.mov* *.mp* 
SET extensions=%extensions% *.mqv *.mts *.mvb *.nsv *.nu* *.ogm *.qt *.rm* *.rts
SET extensions=%extensions% *.scm *.smv *.ssm *.svi *.tivo *.tp *.trp *.ts *.vdo
SET extensions=%extensions% *.vfw *.vi* *.vob *.vp* *.vro *.wm* *.yuv

SET /P UseMetaDir=Use pyTivo .meta directory to store metadata? ^(Y/N^) 
SET UseMetaDir=!UseMetaDir:~0,1!
IF /I "!UseMetaDir!" EQU "Y" (
    SET UseMetaDir=Y
) ELSE (
    SET UseMetaDir=N
)

>>"%~dpnx0" ECHO :Set_Options
>>"%~dpnx0" ECHO SET extensions=*.3g* *.amv *.asf *.av* *.bi* *.box *.bsf *.dat *.di* *.dmb
>>"%~dpnx0" ECHO SET extensions=%%extensions%% *.dpg *.dv* *.evo *.eye *.fl* *.gvi *.ivf *.m1v
>>"%~dpnx0" ECHO SET extensions=%%extensions%% *.m2* *.m4* *.mjp* *.mkv *.mod *.moov *.mov* *.mp*
>>"%~dpnx0" ECHO SET extensions=%%extensions%% *.mqv *.mts *.mvb *.nsv *.nu* *.ogm *.qt *.rm* *.rts
>>"%~dpnx0" ECHO SET extensions=%%extensions%% *.scm *.smv *.ssm *.svi *.tivo *.tp *.trp *.ts *.vdo
>>"%~dpnx0" ECHO SET extensions=%%extensions%% *.vfw *.vi* *.vob *.vp* *.vro *.wm* *.yuv
>>"%~dpnx0" ECHO SET UseMetaDir=!UseMetaDir!
GOTO :EOF
```
Edit: This is for _*Push*_ metadata only. With the "unusual" seriesId, attempting to Pull the videos will likely fail to group.


----------



## superflysocal (Nov 26, 2009)

Thank you so much!!! I think it works! Can i use pytivo to push the avi files now to Tivo an have it all show up under one folder, or do i still have to do the trick where you send one dummy file first?

If so, anybody has a link to instructions on how to send it over and appear in one folder? I can't find it anymore. Also, orangeboy, how would I incorporate seriesID into this? maybe have it ask at the beginning if there is a seriesid? I think you need it to be able to put it in one folder, right?

Would episodeNumber be required also??

Again, a big thanks


----------



## orangeboy (Apr 19, 2004)

superflysocal said:


> Thank you so much!!! I think it works! Can i use pytivo to push the avi files now to Tivo an have it all show up under one folder, or do i still have to do the trick where you send one dummy file first?
> 
> If so, anybody has a link to instructions on how to send it over and appear in one folder? I can't find it anymore. Also, orangeboy, how would I incorporate seriesID into this? maybe have it ask at the beginning if there is a seriesid? I think you need it to be able to put it in one folder, right?
> 
> ...


Well, I was going to try to incorporate a pyTivoMetaThis as an initial step to get much more valid/accurate data, and resort to using the (computer) folder name as the title, and filename as the episodeTitle. I learned in this post that the seriesId doesn't need to be numeric at all, so I didn't bother with trying to generate an integer as a value for that field. As long as all the files are in the same (computer) folder, they will group correctly when you pyTivo PUSH them. episodeNumber shouldn't be required for the files to group correctly.


----------



## superflysocal (Nov 26, 2009)

This appears to work for the p90x files.

However, I now tried this with a more conventional show and it doesnt appear to go through pytivometathis (which is located in the same folder as this bat script)

here are the files:

Nikita_S01E11.avi
Nikita_S01E12_Free.avi
Nikita_S01E13_Coup_De_Grace.avi

edit: just reread your previous post, guess you decided not to incorporate pytivometathis?


----------



## orangeboy (Apr 19, 2004)

superflysocal said:


> This appears to work for the p90x files.
> 
> However, I now tried this with a more conventional show and it doesnt appear to go through pytivometathis (which is located in the same folder as this bat script)
> 
> ...


Correct. If you already have pytivometathis "capable" files, I'd say just use that. It will produce much better metadata.


----------



## superflysocal (Nov 26, 2009)

is there a way to do that with drag drop method of this batch file without using command line?


----------



## orangeboy (Apr 19, 2004)

You might be able to drag the folder onto the .py file? I don't have anything that needs metadata at the moment to try...


----------



## superflysocal (Nov 26, 2009)

Thanks. folder drop works for pytivometathis!


----------



## orangeboy (Apr 19, 2004)

superflysocal said:


> Thanks. folder drop works!


:up:


----------



## oregonman (Jul 1, 2002)

Thank you for doing this script. I was searching for how to push my videos to a folder and found this thread. The script works like a charm.


----------



## orangeboy (Apr 19, 2004)

oregonman said:


> Thank you for doing this script. I was searching for how to push my videos to a folder and found this thread. The script works like a charm.


Glad to hear it!


----------



## johnfarmer55 (Mar 24, 2009)

orangeboy you are AWESOME! This does indeed work like a charm! Except of course for files i've tried pushing with previous metafiles. I think the tivo somehow remembers these files being associated with a different group. It seems renaming them and moving them to a different folder seems to work. Thanks for this awesome little gem!


----------

