dbr / tvnamer

Automatic TV episode file renamer, uses data from thetvdb.com via tvdb_api
https://pypi.python.org/pypi/tvnamer/
The Unlicense
912 stars 115 forks source link

Allow more flexibility in configuration filepath destination? #152

Open ardumont opened 5 years ago

ardumont commented 5 years ago

Hello,

First, thanks for tvnamer, quite a time saver!

Regarding moving file configuration, this would be great to allow more flexibility in the path setup (move_files_destination option).

For example, today we can define:

...
"move_files_destination": ".../tvshow/%(seriesname)s/%(seasonnumber)d/",
...

I'd like to be able to set a more specific path still based on those options, for example, splitting on the first letter of the tvshow:

...
"move_files_destination": ".../tvshow/%(seriesname[0])/s%(seriesname)s/%(seasonnumber)d/",
...

As far as i could see in the code, that part is static so we cannot yet (checked doc, code and issues). The formatting uses a dict with special keywords [1].

[1] https://github.com/dbr/tvnamer/blob/d4f52624353a9050708ae2b7c3cbd3cb16bb570d/tvnamer/main.py#L63-L74

To test the idea, i patched locally my installation to adapt that dict accordingly (for all conditionals), for example:

 isinstance(episode, NoSeasonEpisodeInfo):
        seriesname = wrap_validfname(episode.seriesname)
        destdir = Config['move_files_destination'] % {
            'seriesname[0]': seriesname[0],
            'seriesname': seriesname,
        ...

I found this rather limited but it works.

I don't really know how to apply this generically though (maybe some users would want that on other keys and with more than 1 first letter).


config:


Relatedly, other tools like flexget [2] uses jinja [3]. That allows configuration to look like:

{{ tvdb_series_name | lower | first }}

(this is verbose but it's declarative enough ;)

Then again that adds a new dependency and possibly new issues for you later down the line.

[2] https://github.com/Flexget/Flexget

[3] http://jinja.pocoo.org/

Cheers,

ardumont commented 4 years ago

I found this rather limited but it works.

I don't really know how to apply this generically though (maybe some users would want that on other keys and with more than 1 first letter).

In the mean time, here is my actual proposal [1]

I have been using this successfully for a while now [2]

[1] https://github.com/ardumont/tvnamer/commit/d3012571b97aef2ae583eec9ce14e7ecb6b82acb

[2] https://gitlab.com/ardumont/nixos/-/blob/master/rpi4/pytools/default.nix#L31

Cheers,