Kodi Community Forum
SortTV: Sort TV episodes, movies, and music into directories for xbmc (Linux/Win/Mac) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Supplementary Tools for Kodi (https://forum.kodi.tv/forumdisplay.php?fid=116)
+--- Thread: SortTV: Sort TV episodes, movies, and music into directories for xbmc (Linux/Win/Mac) (/showthread.php?tid=75949)



- mwkurt - 2010-10-22

Cliffe,

Your script looks like something I would like to try, however, I have 5 2TB drives that I save my TV shows to. From looking through this thread I think that I am seeing that this will only work with sorting to 1 directory. Is there any way to get this to work with more than one directory that TV Shows are stored in?

Thanks,
Mark


- lompelurt - 2010-10-22

Thanks for the noob guide Cliffe, but I get an error when i type in the perl sorttv.pl command.

DBM: Deep : Cannot sysopen file '/.tvdb' : Permission denied

Any Idea what i am doing wrong?


New version available - cliffe - 2010-10-22

Version 1.7 is here.
  • As there seems to be demand for it, there is a new feature to optionally only sort episodes that have a matching show directory in the destination directory. This makes it easy to sort from one incoming directory, out to multiple directories.

    --require-show-directories-already-exist:[TRUE|FALSE]
    Only sort into show directories that already exist
    This may be helpful if you have multiple destination directories. Just set up all the other details in the conf file,
    and specify the destination directory when invoking the script. Only episodes that match existing directories in the destination will be moved.
    If this is false, then new directories are created for shows that dont have a directory.
    TRUE/FALSE
    If not specified, FALSE
  • When recursively sorting contents of directories with a non-episode directory specified, non-episode files are now named after where they were sorted from. For example
    "My Show s1e2/read this.txt"
    would be moved to
    Non-episode-directory/"My Show s1e2-read this.txt"

  • Also included are some output clean ups, and some bug fixes.

You can get the new version from:
https://sourceforge.net/projects/sorttv/files/

If you find this script helpful then please consider making a $5 paypal donation Smile
http://sourceforge.net/donate/index.php?group_id=330009

mwkurt Wrote:Is there any way to get this to work with more than one directory that TV Shows are stored in?

There is now Smile


- cliffe - 2010-10-22

lompelurt Wrote:Thanks for the noob guide Cliffe, but I get an error when i type in the perl sorttv.pl command.

DBM: Deep : Cannot sysopen file '/.tvdb' : Permission denied

Any Idea what i am doing wrong?

That is coming from within the TVDB API module. Is there any more info? Are any other Windows users seeing this error message?


- CoinTos - 2010-10-22

Hey cliffe,

Just tested your latest script and it keeps getting better and better, even sent a $10'er as a thank you.

Still have a small problem with the ep look up and I was wondering since I use the Sort To folder as a samba share if there was a way to add force windows illegal character filtering. I tried it myself with CSI: Crime Scene Investigators but it failed to look up the ep title cause I removed the : (I believe). It also failed with Shit My Father Says. So I wonder if there is a way to add tvdb id support to show name subsitution. So it can still find the ep details even if the directory you want is slightly different.

Keep up the great scripting.

Thanks again.


New version available - cliffe - 2010-10-23

Introducing v 1.8:

New feature:
--force-windows-compatible-filenames:[TRUE|FALSE]
Forces MSWindows compatible file names, even when run on other platforms such as Linux
This may be helpful if you are writing to a Windows share from a Linux system
If not specified, FALSE

You can get the new version from:
https://sourceforge.net/projects/sorttv/files/

CoinTos Wrote:Hey cliffe,

Just tested your latest script and it keeps getting better and better, even sent a $10'er as a thank you.

Still have a small problem with the ep look up and I was wondering since I use the Sort To folder as a samba share if there was a way to add force windows illegal character filtering. I tried it myself with CSI: Crime Scene Investigators but it failed to look up the ep title cause I removed the : (I believe). It also failed with Shit My Father Says. So I wonder if there is a way to add tvdb id support to show name subsitution. So it can still find the ep details even if the directory you want is slightly different.

Keep up the great scripting.

Thanks again.

Thanks Smile
Try out this new version. The substitute name is used for thetvdb.com lookups, so this should do the trick.

For example
Code:
CSI s1e4.avi
would be looked up as
Code:
CSI: Crime Scene Investigation
and saved as:
Code:
TV/CSI- Crime Scene Investigation/Season 1/CSI- Crime Scene Investigation - S01E04 - Pledging Mr. Johnson.avi
or on Linux with --force-windows-compatible-filenames:FALSE
Code:
TV/CSI: Crime Scene Investigation/Season 1/CSI: Crime Scene Investigation - S01E04 - Pledging Mr. Johnson.avi



- Targettio - 2010-10-23

cliffe Wrote:That is coming from within the TVDB API module. Is there any more info? Are any other Windows users seeing this error message?

I am getting the same error (SortTV 1.8, Windows 7 64bit, Strawberry Perl 5.12.1.0 64bit)

I used cpan to install the required modules (which all went fine), no log file was created (despite it being set in the conf).

I checked the permissions and ensured all users have full control over the Strawberry file

I am not sure what more info I can provide.


- newphreak - 2010-10-24

Cleaning old symlinks doesnt work. it doesnt remove symlinks of things that doesnt excist in source folder. Also it would be cool if it removed the entire show/season folders if stuff were completly gone from source folder.
thx in advance.


- cliffe - 2010-10-24

newphreak Wrote:Cleaning old symlinks doesnt work. it doesnt remove symlinks of things that doesnt excist in source folder. Also it would be cool if it removed the entire show/season folders if stuff were completly gone from source folder.
thx in advance.

I am not sure what you mean.

The remove symlink feature only removes symlinks left behind by the "sort-by:MOVE-AND-LEAVE-SYMLINK-BEHIND" feature. So the idea is if you want to keep seeding, it moves the file to an organised place, and leaves behind a link so that the torrent software sees the file as being still there.

After you have finished seeding you can use the remove symlink option to remove the links so the torrent software no longer has access to the files, and to keep that directory tidy.

On the other hand, if you used PLACE-SYMLINK the files are left in the origin directory, and organised links are placed. Remove symlinks will not do anything in this situation. This is probably not what you want, unless you want a second organised copy for xbmc. If you want to delete this copy, then just delete the directory.

Does this clear up the confusion, or is there a bug I am not aware of?


New version available - cliffe - 2010-10-24

Version 1.9 is now available.

This version should hopefully fix the bug reported below. If not please let me know Smile

Also added is a feature for downloading images from thetvdb.

--fetch-images:[NEW_SHOWS|FALSE]
Download images for shows, seasons, and episodes from thetvdb
Downloaded images are copied into the sort-to (destination) directory.
NEW_SHOWS - When new shows, seasons, or episodes are created the associated images are downloaded
FALSE - No images are downloaded
if not specified, NEW_SHOWS

--images-formatTongueOSTER
Sets the image format to use, poster or banner.
POSTER/BANNER
if not specified, POSTER

So far it only downloads images for new shows, seasons, and episodes. Maybe a future release will add the ability to download images for shows you already have.

Keep in mind this slows down the sort considerably, and at the moment is enabled by default. Also currently this all happens in the one thread. You may want to disable this feature in the config file.

You can get the new version from:
https://sourceforge.net/projects/sorttv/files/

Targettio Wrote:I am getting the same error (SortTV 1.8, Windows 7 64bit, Strawberry Perl 5.12.1.0 64bit)

Hopefully this update fixes the problem by storing the tv cache db with the script. I am relying on you guys to test this for me, thanks Smile


- CoinTos - 2010-10-24

Hey cliffe,

I am still having a problem with ep retrieval for Shit My Dad Says, I tried a sub for it S#*! My Dad says but it fails before it even gets the ep lookup.

Forced Windows (my mod):
Sorting /home/deluge/unsorted/tv_shows/ into /raid/Media/TV_Shows/
INFO: making show directory: /raid/Media/TV_Shows/$##! My Dad Says
INFO: making show directory: /raid/Media/TV_Shows/$##! My Dad Says
WARN: Could not create show dir: /raid/Media/TV_Shows/$##! My Dad Says:File exists

Linux Detect:
10:20:1, 24-9-2010
Sorting /home/deluge/unsorted/tv_shows/ into /raid/Media/TV_Shows/
INFO: making show directory: /raid/Media/TV_Shows/$#*! My Dad Says
INFO: making show directory: /raid/Media/TV_Shows/$#*! My Dad Says
WARN: Could not create show dir: /raid/Media/TV_Shows/$#*! My Dad Says:File exists

It does create the directory both times then dies.

Note: My mod for forced windows is, change all other illegal characters to # except : which will become - and finally, strip those pesky question marks.

Edit: Just a feature thought, rss downloaders like the one I use (Flexget) will automatically download proper/repacks of the same eps when one is detect. Can you please add support to overwrite the same eps (if detected) when detecting a proper/repack in the sort folder? Thanks again.


- Targettio - 2010-10-24

cliffe Wrote:Version 1.9 is now available.

Hopefully this update fixes the problem by storing the tv cache db with the script. I am relying on you guys to test this for me, thanks Smile

I am afraid I am still getting:
Quote:DBM:Big Grineep: Cannot sysopen file '/.tvdb' : Permission denied

:confused2:


- mwkurt - 2010-10-24

Cliffe,

Hello again, I noticed that you made an option to sort into multiple directories. Unless I am mistaken though, I would have to change the "directory to sort to" every time I run the script? What if I have downloaded multiple shows that are to be put into different directories and the script is run? What happens? Are new directories made in the directory that the script says to sort to, even though those directories may be on another hard drive? I just don't see how this script, as it is, is a hands-off way of running a server with multiple hard drives for storage. If there was an option to enter every storage location that is on one's sever, and have the script then decide where the proper directory to store whatever show is being moved, then it would be perfect. As it is now though, I still can't use it as I need a completely hands off solution for renaming and moving TV Shows.

Thanks,
Mark


- cliffe - 2010-10-24

mwkurt Wrote:Cliffe,

Hello again, I noticed that you made an option to sort into multiple directories. Unless I am mistaken though, I would have to change the "directory to sort to" every time I run the script? What if I have downloaded multiple shows that are to be put into different directories and the script is run? What happens? Are new directories made in the directory that the script says to sort to, even though those directories may be on another hard drive? I just don't see how this script, as it is, is a hands-off way of running a server with multiple hard drives for storage. If there was an option to enter every storage location that is on one's sever, and have the script then decide where the proper directory to store whatever show is being moved, then it would be perfect. As it is now though, I still can't use it as I need a completely hands off solution for renaming and moving TV Shows.

Thanks,
Mark

Just schedule it to happen automatically then...

Type: crontab -e
Then:

5 * * * * perl /path/to/sorttv.pl --directory-to-sort-into:/your/first/hdd --require-show-directories-already-exist:TRUE

20 * * * * perl /path/to/sorttv.pl --directory-to-sort-into:/your/second/hdd --require-show-directories-already-exist:TRUE

35 * * * * perl /path/to/sorttv.pl --directory-to-sort-into:/your/third/hdd --require-show-directories-already-exist:FALSE

This would sort according to the config (where you set things like the source directory)

5 mins past the hour would sort all the episodes of shows that already exist in the first hdd onto that drive
Then 20 mins past every hour it would sort all the episodes of shows that already exist in the second hdd onto that drive
Finally at 35 mins past every hour every other show is sorted onto your third hdd, and any tv shows that don't already have a directory are given one.


- cliffe - 2010-10-24

v1.10:

Fixes regexp characters appearing in titles.

Fixes symlink stopping script on Windows systems when copying images (for some reason symlinks are not implemented in Strawberry Perl yet, even though Windows does have symlinks now)

Added feature to overwrite episodes if a repack / proper release is made.


I did a quick test on Windows and it seems to work on my system (Win7 32bit Strawberry Perl v5.10.1). However, it was very slow at downloading the images and they did not display properly. So for now I recommend Windows users disable the download images feature by editing the sorttv.conf file to include:

fetch-images:FALSE
(rather than "fetch-images:NEW_SHOWS")

Since I cannot replicate the problem reported earlier (DBM: Deep : Cannot sysopen file '/.tvdb' : Permission denied) I haven't sorted that out yet. Maybe you could try to figure out which line it is crashing on by simply adding some
Code:
print "hasn't crashed yet 1";
lines. And see how far it gets before you get the error message.

CoinTos Wrote:Hey cliffe,

I am still having a problem with ep retrieval for Shit My Dad Says, I tried a sub for it S#*! My Dad says but it fails before it even gets the ep lookup.

Forced Windows (my mod):
Sorting /home/deluge/unsorted/tv_shows/ into /raid/Media/TV_Shows/
INFO: making show directory: /raid/Media/TV_Shows/$##! My Dad Says
INFO: making show directory: /raid/Media/TV_Shows/$##! My Dad Says
WARN: Could not create show dir: /raid/Media/TV_Shows/$##! My Dad Says:File exists

Linux Detect:
10:20:1, 24-9-2010
Sorting /home/deluge/unsorted/tv_shows/ into /raid/Media/TV_Shows/
INFO: making show directory: /raid/Media/TV_Shows/$#*! My Dad Says
INFO: making show directory: /raid/Media/TV_Shows/$#*! My Dad Says
WARN: Could not create show dir: /raid/Media/TV_Shows/$#*! My Dad Says:File exists

It does create the directory both times then dies.

Note: My mod for forced windows is, change all other illegal characters to # except : which will become - and finally, strip those pesky question marks.

That is fixed now in v1.10, and seems to sort fine. Can't seem to get details from thetvdb for that particular show, but for now that doesn't seem to be a big deal.

CoinTos Wrote:Edit: Just a feature thought, rss downloaders like the one I use (Flexget) will automatically download proper/repacks of the same eps when one is detect. Can you please add support to overwrite the same eps (if detected) when detecting a proper/repack in the sort folder? Thanks again.

Ok added.

Could you explain how the naming for these works (is it just that it contains those words? proper/repack), as I have come across these but never given it much thought. As implemented, if it contains "proper" or "repack" it overwrites existing files with the same resulting sorted name.