Skip to content

michaelgrossklos/sortier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo Sortier

What it does

Sortier is capable to sort any kind of tv-shows that one has ripped or downloaded. During the process, all video files will be renamed, sorted into folders named after the season they’re belonging to and saved wherever you desire. By that, it is possible to upload the files to your media server like Plex, Emby or others. These media centers need the correct naming convention in order to find all the metadata like posters, background images and other informations.

The seasons need to be in a folder called after the season. For example:

Season 01

Also, the videos itself need to follow these kind of conventions. Files need to be named like this:

My New Show (2011) s01e01.mkv.

This very tool does all that for you.



Tested Operation Systems

Sortier is actual only tested with Mac OSX Catalina. But should be running on any OS.
Tester wanted!

Installation

To install Sortier just copy the following line to your Terminal or command line:

pip3 install git+https://github.com/michaelgrossklos/sortier.git

I assume you have Python >= 3.7 already installed on your machine. If not, go to https://www.python.org/ and follow the instructions there.

Usage

Help

First of all, it is important to know, that you always can use the --help option.
This will print something like this:

Usage: sortier [OPTIONS] COMMAND [ARGS]...

  Sorting your ripped or downloaded tv-shows into folders named after the
  seasons they're belonging to (f.e.: Season 01). Renames all files like
  "Name Of Show s01e01.ext" for direct use in your media center like Plex or
  Emby. So it can find all meta data needed.

Options:
  -l, --language TEXT       Sets the language for season names
  --debug / --no-debug      Turn debug mode on
  --delete-folders BOOLEAN  Delete the source folder after copying the file
  --help                    Show this message and exit.

Commands:
  addextensions  Extends the list of file extensions.
  destpath       Changes the destination path permanently
  oripath        Changes the origin path permanently
  settings       Shows the actual settings
  titles         The titles of the shows to be sorted.

As you can see in the first line, you first (and always) need to call the program itself by using sortier. After that you can specify options which usually begins with -- (two dashes). Or (in some cases) also with just one -. This is just the short hand version of it. The effect will be exactly the same.

For example -l is the same as --language.

All options are, well… optional ;)

Some of them requiring arguments to be passed in, some do not. --delete-folders for example is one that does not need any arguments. Therefor it is called a flag. Whereas --origin-path in fact needs the path where all the video files are located.

On the other hand there are commands. Those need to be typed after the options (if you’ve specified one). Some of them are requiring arguments. Some do not. For Example settings does not need any argument. If you set one, you would get an error.

A complete line for using Sortier could look something like this:

sortier -l=en --delete-folders titles "my first show" "my second show"
sortier titles "my fisrt show" "my second show"

if you wouldn’t use any options.

Important to know is, that you can’t use two commands at the same time, whereas you are able to use more than one option at ones. The order in which you specify the options does not matter.

Commands

Show all settings

As you are able to change most of the settings, you need to know the actual state they’re in. Just type

sortier settings

without any arguments, and something like the following will get printed on the screen:

ACTUAL SETTINGS FOR SORTIER:
Regex for seasons: (s([0-9]{2})e[0-9]{2})
Origin/Source path: Downloads/extracted
Destination path: Downloads/extracted/SORTED
File extensions available: ['.mkv', '.avi', '.mp4', '.mov']
Languages available: ['de', 'en', 'es', 'fr', 'it', 'ru']
Language set: en
Season is called: Season

You can find more information on:
https://github.com/michaelgrossklos/sortier

Renaming files

The files to be renamed are only the video files that get stored into the destination folder.

File name a.k.a tv-show titles (runs Sortier)

In order to rename - and more importantly - find the right files, you need to provide the titles of the show. This command also starts the whole process. Any other command won’t.

You use it by typing:

sortier titles "My tv show 1" "My tv show 2"

Don’t use any placeholders for spaces. Write the title like you want the files get named. Capitalization will be ignored for finding the video files. But, it is important for the file and folder naming. The way you specify the titles here, the files and folder will get named.

Notice, that you are able to specify just one, or an unlimited amount of titles. You just need to wrap each title into quotation marks followed by a space. The order in which you define the titles is irrelevant.

This also means, that you can have multiple tv-shows including multiple seasons in your source folder. As long as each episode is contained in its own folder and this folder is somehow named after the show.

For example:

/The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
/345-my.tv.show_2/
/dim-mytvshow.3-IFRIM/

The characters in between the words of the title itself, and surrounding it are not relevant at all. Sortier will find the title anyways.

How the video file itself is named, does not matter, as long as it holds the season and episode count.

For example

The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv

In which S02E01 means season 2, episode 1. Without that, Sortier is incapable of sorting the episodes and will stop running with printing out an error message. Capitalization will be ignored.


File extensions

Not always, but most of the time, are the provided default file extensions sufficient. If that is not the case you can extend the list of file extensions by using the commmand

sortier addextensions ".mpeg" ".webm"

Like the command title, you can specify just one or an unlimited amount of extensions. You just need to put a dot in front of the extension itself and wrap each extension into quotation marks followed by a space. The order in which you define those, is irrelevant.

The extension you’re adding, will get saved permanently. So, you don’t need to set them the next time you use Sortier.


Setting the paths

There are two paths to be set. The origin path and the destination path.

Origin/Source path

This is the path where the ripped or downloaded files are to find at. In the settings you’ll see the whole path.

Which by default is set to

Downloads/extracted

That is the relative path (from the users home directory) to your source folder, where all the files are in. You can set this path to any location under your users home directory, as long as one won’t need administrator rights to read from it. Most of the time, it will be your downloads folder or any subfolders beneath it. You just need to provide the parent folder that contains the folders of the video files.

Your folder structure could look something like this (assuming you’re on Mac OSX):

└── Users/
    └── <user name>/
        └── Downloads/
            └── extracted/
                ├── The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── The.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── The.Show.S02E03.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E03.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── Another.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── Another.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── Another.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── Another.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── ...└── Another.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv

In which extracted is the parent folder of all the video files.

Destination path

All the video files will be copied to this path.

This path by default is set to

<your home directory>/Downloads/extracted/SORTED

It’s the same principal as of the origin path.

As mentioned above, the files will be sorted into folders named after the show and subfolders named after the seasons. This could look something like this:

└── Users/
    └── <user name>/
        └── Downloads/
            └── extracted/
                ├── The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── The.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── The.Show.S02E03.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── The.Show.S02E03.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── Another.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── Another.Show.S02E01.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── Another.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA/
                │   └── Another.Show.S02E02.COMPLETE.English.DL.720p.BluRay.x264-UTOPiA.mkv
                ├── ...
                └── SORTED/
                    ├── The Show/
                    │   ├── Season 01/
                    │   │   ├── The Show - s01e01.mkv
                    │   │   ├── The Show - s01e02.mkv
                    │   │   ├── The Show - s01e03.mkv
                    │   │   └── ...
                    │   └── Season 02/
                    │       ├── The Show - s02e01.mkv
                    │       ├── The Show - s02e02.mkv
                    │       ├── The Show - s02e03.mkv
                    │       └── ...
                    └── Another Show/
                        └── Season 02/
                            ├── Another Show - s02e01.mkv
                            ├── Another Show - s02e02.mkv
                            └── ...

Changing the paths

To change the paths, you have two commands.

sortier oripath <path>
sortier destpath <path>

It’s obvious which one changes which path.

Example
sortier oripath Movies/Dowloads/Extracted

Please note, that you mustn’t use a prefixing slash nor quotation marks.

Options

Language

If you set the language, it really is not much what changes. The only thing that changes is how the folder for the seasons gets named. In English, it will be Season. In German Staffel and in french Saison and so on. You can set the language by either use the long or the short version of this option.

--language en or -l en

The default is German.

Table 1. Languages available in Sortier
Abbreviation Language Season

en

English

Season

de

German

Staffel

fr

French

Saison

it

Italian

Stagione

ru

Russian

Sezon

es

Spanish

Temporada

💡
Actually, there is no functionality to permanently set the language. So you have to use it every time you use Sortier.

Show titles based on dates

According to this part of the Plex support site, one can use dates in tv-show titles if needed. This is the case for remakes for example. Or maybe for shows like Star Trek.

Those dates could be written with:

  • Dashes (2011-11-15)

  • Periods (2011.11.15)

  • Spaces (2011 11 15)

To actually use these the right way in the titles, you need to use:

--date "<date>"

In which <date> gets substituted with the actual date.

The outcome looks like this:

SORTED/
    └── Show Title - 2011-09-01/
        └── Season 01/
            ├── Show Title - s01e01 - 2011-09-01.mkv
            ├── Show Title - s01e02 - 2011-09-01.mkv
            ├── Show Title - s01e03 - 2011-09-01.mkv
            └── ...
You only can use this for the whole tv-show. Not for single seasons or episodes.

Flags

Flags are a kind of options. Unlike options, they don’t reseive any arguments. You just use the flag like so

--flag

Delete folders

If you use the flag

--delete-folders

all source folders will get deleted after the video file was copied.

⚠️
Use this functionality with caution.

Debug mode

Users usually do not need this mode.

You can use

--debug

every time you want the debug mode to be switched on.

What it does is very simple. During the execution of Sortier, you will see some messages on the command line. These are giving some hints what the program actually does.

Configuration file

During the installation, Sortier saves a small configuration file. The file format is JSON.

This is what it looks like initally:

{
  "default_paths": {
    "ORIGIN_PATH": "Downloads/extracted",
    "DESTINATION_PATH": "Downloads/extracted/SORTED"
  },
  "FILE_EXTENSIONS": [
    ".mkv",
    ".avi",
    ".mp4",
    ".mov"
  ],
  "LANGUAGES": {
    "de": "Staffel",
    "en": "Season",
    "es": "Temporada",
    "fr": "Saison",
    "it": "Stagione",
    "ru": "Sezon"
  },
  "REGEX": "(s([0-9]{2})e[0-9]{2})"
}

The default installation path is:

<users home directory>/.config/sortier/sortier.json

Where <users home directory> gets substituted with the path to your users home directory. The path depends on the operating system you are using. On Windows for example, the path could look like this

C:\Users\<current user name>\.confing\sortier\sortier.json>

Changing the config

To change anything, you just need to open the file in a text editor. It doesn’t matter which one. But beforehand, you should know a little bit about JSON itself. You can find planty of informations here: https://www.json.org/json-en.html

The regex part

If you don’t know what regex is, you’re probably not able to change that part. Because, if you do something wrong, Sortier won’t work anymore. This regex is the "code" that finds the seasons.

Normaly, one does not need to change that part.

Any other parts

Other than the regex, you pretty much can change anyting. Adding languages for example. As you already know, the file extentions can be changed via a command. But if you want, you can do it in this file. Afterwards it still is possible to use the commmand to change it.

⚠️
Please do not change the location of the file. Because Sortier won’t work anymore.

The future

Well, after the launch is before the launch, isn’t it? So there are some additional features planed for future versions.

Getting titles from TheTVDB

The TV Database (TheTVDB) is a free Service which provides lots of informations about tv-shows. Media centers like Plex getting there data (like posters, background images, descriptions, actors a.s.f.) from that website.

Luckily for us, it also has an API. So we are capable to get this data too. But the only thing we really need, is the correct title. Since the media server needs the right one according to TheTVDB, the tool could search for a title, given by the user and find the right one to be used for the folder and file names.

Setting language permanently

Probably the next feature to implement will be this one. Just to be able to set the language permanently without editing the config file. The option will still be at hand. But most of the users don’t need to change that option that much.

Contributing to Sortie

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it’s:

  • Reporting a bug

  • Discussing the current state of the code

  • Submitting a fix

  • Proposing new features

  • Becoming a maintainer

We Develop with Github

We use github to host code, to track issues and feature requests, as well as accept pull requests.

We Use Github Flow, So All Code Changes Happen Through Pull Requests

Pull requests are the best way to propose changes to the codebase (we use Github Flow). We actively welcome your pull requests:

  1. Fork the repo and create your branch from master.

  2. If you’ve added code that should be tested, add tests.

  3. If you’ve changed APIs, update the documentation.

  4. Ensure the test suite passes.

  5. Make sure your code lints.

  6. Issue that pull request!

First Contribution

To contribute to Sortier:

  1. Clone the repository to your local machine:

    git clone https://github.com/michaelgrossklos/sortier.git
  2. Check out the /master branch:

    git checkout main
  3. Create a new working branch for your changes:

    git checkout -b branchname
  4. Ensure the tests are passing.

  5. Add the updated files to your commit:

    git add .
  6. Commit your changes:

    git commit -m "Commit message here"
  7. Push your changes:

    git push

    If git prompts you to set an upstream in order to push, use this command:

    git push --set-upstream origin <branchname>
  8. Create a pull request (PR) by navigating to github.com/michaelgrossklos/sortier/pulls and clicking on New Pull Request. Write an informative commit message detailing your changes and save your PR. If you haven’t yet finished the work you want to do, make sure you create a Draft PR by selecting it from the drop down box in the github web UI. This lets the reviewer know that you haven’t finished work yet, while still being transparent about what you are working on, and making sure we all understand current progress.

Any contributions you make will be under the GNU-GPL-V3 Software License

In short, when you submit code changes, your submissions are understood to be under the same GNU-GPL-V3 that covers the project. Feel free to contact the maintainers if that’s a concern.

Report bugs using Github’s issues

We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it’s that easy!

Write bug reports with detail, background, and sample code

This is an example of a bug report briandk wrote, and I think it’s not a bad model. Here’s another example from Craig Hockenberry, an app developer.

Great Bug Reports tend to have:

  • A quick summary and/or background

  • Steps to reproduce

  • Be specific!

  • Give sample code if you can.

  • What you expected would happen

  • What actually happens

  • Notes (possibly including why you think this might be happening, or stuff you tried that didn’t work)

People love thorough bug reports. I’m not even kidding.

Use a Consistent Coding Style

I’m again borrowing these from Facebook’s Guidelines

  • We’re using the PEP8 Style Guide for Python, with the following exceptions:

    • 4 spaces for indentation rather than tabs

    • 120 character line length

License

By contributing, you agree that your contributions will be licensed under its GNU-GPL-V3 License.

References

This document was adapted from the open-source contribution guidelines for Facebook’s Draft

License

Sortier: Sorting ripped or downloaded tv-shows into folders
Copyright (C) 2021  Michael Grossklos ([email protected])

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see

About the name

Sometimes one asks: why this name?
In this case it is very simple and unspectacular.
"Sortieren" in German means "to sort". So Sortier is so to speak, the noun for that. Even thou, a noun for that verb does not exist in German.

One could see it a little different from that. Because "Tier" (SorTIER) in German means "animal". Which could be seen as "sorting animal", with a bit of phantasy.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages