Filename based scraper for TV shows?
#16
You're welcome Smile

Quote: I thought nobody would respond ever again, but now you appear!!
Have some faith, man Wink I mean it was only a day (in my time zone). As you asked so kindly, I had another look at your problems.

Quote:I dislike relying on an online connection and availability of content in databases
As you are editing your nfo files anyway you might have a look at some of the proper library managers like Ember or Elch that - afaik - allow to edit and safe nfos as well. The script is rather meant for getting really unscrapable videos that are not in tvdb, imdb, etc. like vodcast or home made videos to show up in Kodi.

But here are my answers to your problem:
Quote:1. Problem: incompatibility with characters. "Mr. Robot" has its <title> set as "Mr",
That was a bug in my script... sorry. Just had to change the two "%%~nt" into "%%t". Should work now properly.

Quote:folders with Asian characters like "スクールランブル" are skipped
Being a lousy coder I struggle with special characters, code pages and character encoding things myself. Can't really help you there. Could even be caused by the way you save the .bat file. I always get rid of special chars before I put the files into the folder.

Quote:2. Problem: some shows cannot have their name modified
NOT renaming anything and using the orginal file name for the .nfo is actually easier than renaming it Wink. I changed that in the code below. So no more S01E01 etc. naming. I put the episode number in the nfo file instead. I hope Kodi can work with that.

Quote:3. Suggestion: Similar to above, it'd be good to have a mechanism that detects if an .nfo already exists
It should already do that. Works here. Probably you missed something when you stripped the renaming from my code.

Quote:4. Suggestion: I'd like to use "Extra" instead of "Season 00"
Oh boy... now the script really becomes custom made for you... Wink ok, included that, too. You can also use that part for more exceptions like that, e.g. "Extras", "DVD extras", etc. Just copy the line and change the keyword.

So here comes the customized script:
Code:
@echo off & setlocal enabledelayedexpansion
chcp 1252 >NUL
REM Please change the next line. It should point to the folder that contains all of your unscrapable videos (without "\" at the end!)
REM I highly recommend to put those files in an extra folder that does not contain other "scrapable" videos as this script can't tell the difference and will create .nfo files for all folders
set "Basefolder=C:\Videos\Unscrapable Videos"

echo -------------------------------------------------------------------------------
REM Scans all main folders (series) without the subfolders (seasons).
echo Creating a tvshow.nfo for each new folder.
pushd "%Basefolder%"
for /f "delims=" %%t in ('dir /b /AD') do (
    if not exist "!Basefolder!\%%t\tvshow.nfo" (
        set "month=!date:~3,2!"
        set "year=!date:~6,4!"
        set "day=!date:~0,2!"
        echo New folder "%%t" found! tvshow.nfo generated
        REM Writing a basic XML structure to the tvshow.nfo just using the folder name as a title.
        echo ^<^?xml version=^"1.0^" encoding=^"UTF-8^" standalone=^"yes^" ^?^> > "!Basefolder!\%%t\tvshow.nfo"
        echo ^<tvshow^>^<title^>%%t^</title^>^<premiered^>!year!-!month!-!day!^</premiered^>^</tvshow^> >> "!Basefolder!\%%t\tvshow.nfo"
        )
    )


echo -------------------------------------------------------------------------------
REM Scans all main folders (series) without the subfolders (seasons).
echo Creating a .nfo for each new video.
for /f "delims=" %%t in ('dir /b /AD') do (
    REM Go to show level
    pushd "%%t"
    echo %%t
    for /f "tokens=1-2 delims= " %%a in ('dir /b /AD') do (
        REM Setting the season number from the folder name by taking the part after the blank (e.g. "01" from "Season 01")
        set "Seasonnumber=%%b"
        REM On special request of user firewater ;)
        if "%%a%%b"=="Extra" set "Seasonnumber=0"
        REM Go to season level
        pushd "%%a %%b"
        for /f "delims=" %%f in ('dir /b /OD *.mkv *.avi *.flv *.mp4 *.wmv *.mov') do (
            if not exist "%%~dpf_episodecounter.txt" echo 0 > "%%t\_episodecounter.txt"
            if not exist "%%~dpnf.nfo" (
                set /p "EpisodeCounter="<"%%~dpf\_episodecounter.txt"
                set /A EpisodeCounter +=1
                set "timestamp=%%~tf"
                set "month=!timestamp:~3,2!"
                set "year=!timestamp:~6,4!"
                set "day=!timestamp:~0,2!"
                if !EpisodeCounter! LSS 10 (
                    set "Episode=0!EpisodeCounter!"
                    ) ELSE (
                    set "Episode=!EpisodeCounter!"
                    )
                    REM Echo !Episode!
                if exist "%%~dpnf.jpg" (
                set "thumb=%%~dpnf.jpg"
                ) else (
                set thumb=
                )
                echo ^<^?xml version=^"1.0^" encoding=^"UTF-8^" standalone=^"yes^" ^?^> > "%%~dpnf.nfo"
                echo ^<episodedetails^>^<title^>%%~nf^</title^>^<aired^>!year!-!month!-!day!^</aired^>^<season^>!Seasonnumber!^</season^>^<episode^>!Episode!^</episode^>^<thumb^>!thumb!^</thumb^>^</episodedetails^> >> "%%~dpnf.nfo"
                echo !EpisodeCounter!>"%%~dpf\_episodecounter.txt"
                )
            )
        cd..
        )
    pushd "%Basefolder%"
    )

Enjoy... And I hope you can solve your special character issue.
Reply
#17
Aaaaah, alright!!! Thankssssssssssssss!!!!!!

Very sorry to bother you again, but there's just one last thing that happens now that you did the no-rename change: episode numbers are numbered overall. So for example I'm seeing <episode>98</episode> on a folder with 6 files.

edit: whoops, something else I hadn't noticed now that you did the change above - I actually like the renaming part, so I hope you can keep the renaming for the .nfo (ie. <title>S01E01</title> over <title>[Coalgirls]_FLCL_Come_Down_(960x720_Blu-ray_FLAC)_[17A57433]-s01e001-s00e001.s0e04</title>)

On the up side, I figured the fix for the foreign characters (which I like to keep because they're the 'actual', original name): "chcp 1252 >NUL" has to be changed to "chcp 65001 >NUL".

edit: second up side for a second bad side - if anyone doesn't want to be bothered constantly opening the script, you can make it run at startup of Kodi if you make a file called "autoexec.py" inside your userdata folder, and paste the following inside (of course, with the corresponding modifications):

Code:
import xbmc
xbmc.executebuiltin('XBMC.System.Exec(""C:\\example\\directory\\nfo.bat"")')

Too bad it takes away the focus of Kodi for a second...

edit: this one's a neutral side. i forgot to mention, before finding this, i found an an addon that adds videos as 'movies' by using their title. i could not get it to work for series, but maybe someone can look into it.
Reply
#18
Quote:Very sorry to bother you again, but there's just one last thing that happens now that you did the no-rename change: episode numbers are numbered overall. So for example I'm seeing <episode>98</episode> on a folder with 6 files.
Found the bug. I forgot to delete some backslashes that were necessary in my non-season version of the script. New code below. Included your codepage 65001 as well (seems not work for me for the title tag in the nfo. äöü became a some strange characters.)

Quote: I actually like the renaming part, so I hope you can keep the renaming for the .nfo
I'm not sure what you need here. I guess you want the nfo file named like the video file name (otherwise Kodi will not recognize it anyways) but have something inside the nfo / in the xml like <title>Coalgirls blah blah blah S01E02</title>. Right? I put it in the code as well but you might configure that yourself. Just use variables like "%%~nf" (filename without extension), "%%~nxf" (filename with extension), "!Seasonnumber!", "!Episode!", etc.

So I guess my work is done here Smile

Code:
@echo off & setlocal enabledelayedexpansion
chcp 65001 >NUL
REM I highly recommend to put those files in an extra folder that does not contain other "scrapable" videos as this script can't tell the difference and will create .nfo files for all files and folders
REM Please change the next line. It should point to the folder that contains all of your unscrapable videos (without "\" at the end!)
set "Basefolder=C:\Videos\Unscrapable Videos"

echo -------------------------------------------------------------------------------
REM Scans all main folders (series) without the subfolders (seasons).
echo Creating a tvshow.nfo for each new folder.
pushd "%Basefolder%"
for /f "delims=" %%t in ('dir /b /AD') do (
    if not exist "!Basefolder!\%%t\tvshow.nfo" (
        set "month=!date:~3,2!"
        set "year=!date:~6,4!"
        set "day=!date:~0,2!"
        echo New folder "%%t" found! tvshow.nfo generated
        REM Writing a basic XML structure to the tvshow.nfo just using the folder name as a title.
        echo ^<^?xml version=^"1.0^" encoding=^"UTF-8^" standalone=^"yes^" ^?^> > "!Basefolder!\%%t\tvshow.nfo"
        echo ^<tvshow^>^<title^>%%t^</title^>^<premiered^>!year!-!month!-!day!^</premiered^>^</tvshow^> >> "!Basefolder!\%%t\tvshow.nfo"
        )
    )


echo -------------------------------------------------------------------------------
REM Scans all main folders (series) without the subfolders (seasons).
echo Creating a .nfo for each new video.
for /f "delims=" %%t in ('dir /b /AD') do (
    REM Go to show level
    pushd "%%t"
    echo %%t
    for /f "tokens=1-2 delims= " %%a in ('dir /b /AD') do (
        REM Setting the season number from the folder name by taking the part after the blank (e.g. "01" from "Season 01")
        set "Seasonnumber=%%b"
        REM On special request of user firewater ;)
        if "%%a%%b"=="Extra" set "Seasonnumber=0"
        REM Go to season level
        pushd "%%a %%b"
        for /f "delims=" %%f in ('dir /b /OD *.mkv *.avi *.flv *.mp4 *.wmv *.mov') do (
            if not exist "%%~dpf_episodecounter.txt" echo 0 > "%%~dpf_episodecounter.txt"
            if not exist "%%~dpnf.nfo" (
                set /p "EpisodeCounter="<"%%~dpf_episodecounter.txt"
                set /A EpisodeCounter +=1
                Echo !EpisodeCounter!
                set "timestamp=%%~tf"
                set "month=!timestamp:~3,2!"
                set "year=!timestamp:~6,4!"
                set "day=!timestamp:~0,2!"
                if !EpisodeCounter! LSS 10 (
                    set "Episode=0!EpisodeCounter!"
                    ) ELSE (
                    set "Episode=!EpisodeCounter!"
                    )
                    REM Echo !Episode!
                if exist "%%~dpnf.jpg" (
                set "thumb=%%~dpnf.jpg"
                ) else (
                set thumb=
                )
                echo ^<^?xml version=^"1.0^" encoding=^"UTF-8^" standalone=^"yes^" ^?^> > "%%~dpnf.nfo"
                echo ^<episodedetails^>^<title^>%%~nf S!Seasonnumber!E!Episode!^</title^>^<aired^>!year!-!month!-!day!^</aired^>^<season^>!Seasonnumber!^</season^>^<episode^>!Episode!^</episode^>^<thumb^>!thumb!^</thumb^>^</episodedetails^> >> "%%~dpnf.nfo"
                echo !EpisodeCounter!>"%%~dpf_episodecounter.txt"
                )
            )
        cd..
        )
    pushd "%Basefolder%"
    )
Thanks for the hint with the autoexec.py ! Did not know that yet. don't need it for this script, because I want it to run right after the vodcast download and before I start Kodi. But might come handy some day for another script.

Quote:Too bad it takes away the focus of Kodi for a second...
Just do it the other way round: Start Kodi at the end nfo script instead of starting the nfo script via Kodi. It will also generate all the nfos before Kodi starts...
Reply
#19
Yessssssssssssssssssssssssssss. It's done. Thanks again so much for your efforts, just great.
Reply
#20
Hi Firewater. As I can not reply to PMs (not enough posts yet), I will write into the thread again (sorry, guys)...
Quote:I checked again and the episode number thing is still off - now they're numbered randomly
I think I found your problem.If I am right, you get episode numbers that are not really random but based on the age of the video file. Try to replace the "DIR /B /OD" part with "DIR /B /ON". There is only one occurrence in the script.

DIR /B /OD sorts the files in the directory by date, oldest first. DIR /B /ON should sort the files alphabetically (afaik this is the default method for dir, so you could even delete the /OD part).

Starting with the oldest file instead the first one in the alphabet made sense for me as I just use the script to "scrape" vodcasts that do not have file names that indicate the order of the airing date.
Reply
#21
It works!!! A million thanks again, man. Fantastic stuff. Crossing my fingers that this is the last fix for it, but I think it's done.

Really hope other people can benefit from it, too. Emby does this automatically, maybe Plex does too, so it's crazy to me that Kodi still isn't able to add unknown series by default. At last!!!
Reply
#22
(2016-11-09, 05:27)firewater Wrote: WOAH!!!! Thunder response!! This is both an awful and lucky day haha, I spent hours working on this organization stuff today, failing again and again trying to modify the code (I'm not a coder) because I thought nobody would respond ever again, but now you appear!!

If you are trying to sort out shows that are listed in TVDB (almost all regular TV shows), then try TVRename. (http://tvrename.com/) It is a great program to sort and rename/relocate your TV shows. My Kodi Setup wouldn't be without it. You setup shows in the program, point to a source folder with TV episodes and let it do the rest. It looks for most common filename formats in the source folder and then rename them properly. You can add your own RegX as well if needed.

HTH
Reply
#23
I am setting up a TV show in Kodi for all my home videos. I have one TV Show with multiple episodes. All files are renamed appropriately (SxxExx). I will use these batch files to create the NFO files. I will post mine once I have worked it out. Thanks again for the pointers. Smile
Reply
#24
Hi,

I am trying to modify the batch file examples given here however having a heck of a time. All my files have proper file names (S01E02) etc. I don't plan to run the batch file for the whole show folder but instead once for each season.The only thing I need this batch file to do is to create an NFO file for each episode in the folder.

NFO Example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<episodedetails>
  <title>S02E02</title>
  <aired>2016</aired>
  <rating>0</rating>
  <season>2</season>
  <episode>2</episode>
  <plot>S02E02</plot>
  <dateadded>2016-11-05 09:10:53</dateadded>
</episodedetails>

Trying to parse the file name

Code:
@echo off
setlocal

Z:\
cd "Z:\Home\MyShow\SEASON 09\"

for %%f in ("*.mp4") do (
    REM Following echo is for testing only
    echo %%f

    REM Original file name format: S09E05.mp4
    REM Extract file name, season #, and episode # to variables

    set myfilename=%nf
    set SeasonNum=myfilename:~2,2
    set EpisodeNum=myfilename:~5,2

    echo/Season [%SeasonNum%]
    echo/Episode [%EpisodeNum%]

    REM Check and create Episode NFO
    REM If NOT Exist "%myfilename%.nfo" ...
    )

For some reason Season and Episode numbers are not being extracted. Any help is appreciated.

Thanks.
Reply
#25
(2016-11-22, 00:11)DJDJDJDJ Wrote: Hi,

I am trying to modify the batch file examples given here however having a heck of a time. All my files have proper file names (S01E02) etc. I don't plan to run the batch file for the whole show folder but instead once for each season.The only thing I need this batch file to do is to create an NFO file for each episode in the folder.

NFO Example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<episodedetails>
  <title>S02E02</title>
  <aired>2016</aired>
  <rating>0</rating>
  <season>2</season>
  <episode>2</episode>
  <plot>S02E02</plot>
  <dateadded>2016-11-05 09:10:53</dateadded>
</episodedetails>

Trying to parse the file name

Code:
@echo off
setlocal

Z:\
cd "Z:\Home\MyShow\SEASON 09\"

for %%f in ("*.mp4") do (
    REM Following echo is for testing only
    echo %%f

    REM Original file name format: S09E05.mp4
    REM Extract file name, season #, and episode # to variables

    set myfilename=%nf
    set SeasonNum=myfilename:~2,2
    set EpisodeNum=myfilename:~5,2

    echo/Season [%SeasonNum%]
    echo/Episode [%EpisodeNum%]

    REM Check and create Episode NFO
    REM If NOT Exist "%myfilename%.nfo" ...
    )

For some reason Season and Episode numbers are not being extracted. Any help is appreciated.

Thanks.

Did you try the last version posted? I don't see how it wouldn't fit you, unless the run-from-show-folder thing doesn't work at season level, in which case try a version before that.

The spacing for the .nfo file I actually wanted to have too so I added

Code:
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

before the first

Code:
echo -------------------------------------------------------------------------------

And then the line that makes the .nfo looks like this:

Code:
echo ^<episodedetails^>%NL%^<title^>S!Seasonnumber!E!Episode!^</title^>%NL%^<season^>!Seasonnumber!^</season^>%NL%^<episode^>!Episode!^</episode^>%NL%^<premiered^>^</premiered^>%NL%^</episodedetails^> >> "%%~dpnf.nfo"
Reply
#26
Guys, I am having a heck of a time trying to modify the batch file. Mostly due to my limited knowledge of course.

My videos files (in each Season) are in a sequence so I have named them appropriately. For this reason, they are already in the correct format. I do not want them to be renamed. Standard file name I have is like S02E05.mp4 etc. My thumbnail images are named as S02E05-thumb.jpg. I have tried adding REM in front of the rename commands but renamed name is used for the JPGs.

Any help is appreciated.

Thanks.
Reply
#27
Very sorry, but I can't help you further. I tried your setup with many scripts listed here, and for some reason none of them work for me. I kept getting different errors, which doesn't make any sense because your setup is almost exactly like mine... maybe it's something with the .jpg being included, or maybe the folder I tried had weird permissions... but most probably I'm too tried and overlook something every time I tried.

I wish I could help because I know how awfully frustrating this can be, but I'm even less of a coder than you are, and what I tried didn't help, so I suggest either trying each and every version of the scripts already posted if you haven't (they do almost the same, and then it's just a few lines that you can remove until you get it right via trial and error), or PMing Jotha (that's how I got him to respond so much).
Reply
#28
Thanks firewater for try. I have no taken a different route. I have some old school Visual Basic experience so I have not installed Visual Studio and started coding a small app to do this task. Yep, it does sound like killing a fly with a sledgehammer but I don't mind coding as long as it is as a hobby.:-)

Time to watch some videos on how to do things in VB.NET :-)

I will come back if I get a half-decent utility in case someone else wants one.

Thanks again.
Reply

Logout Mark Read Team Forum Stats Members Help
Filename based scraper for TV shows?0