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

modify output of 'seriesname' #81

Closed jkwill87 closed 11 years ago

jkwill87 commented 11 years ago

XBMC can parse series names with underscores or periods just fine and i prefer to leave spaces out of my files and directories if at all possible.

I'm looking for a solution, either through the configuration file or by redefining the output of 'seriesname', something outside my very basic understanding of python, and was wondering if this would be something simple to accomplish or more trouble than its worth.

Otherwise I love tvnamer, and use it on a daily basis, thanks!

lahwaacz commented 11 years ago

Of course you can configure it, look at https://github.com/dbr/tvnamer#custom-output-filenames I think this is what you're after - will replace all spaces in output filename with underscores:

{
    "output_filename_replacements": [
        {"is_regex": true,
        "match": "[ ]",
        "replacement": "_"}
    ]
}
jkwill87 commented 11 years ago

Great, thank you.

Sorry i missed that part of the readme, but by adding these two lines to my .tvnamer.json config file, tvnamer parsed out spaces and replaced them with underscores just like I was hoping to do:

"custom_filename_character_blacklist": " " "replace_invalid_characterswith": ""

dbr commented 11 years ago

Glad you got it working \o/ Thanks for the suggestion @lahwaacz - I guess output_filename_replacements is the more "official" way to do it, but using the character blacklist is perfectly reasonable too

Bear in mind the readme isn't always kept up-to-date - the most reliable documentation of the config options is the config_defaults.py file

jkwill87 commented 11 years ago

@lahwaacz method actually works better after all but I also need to duplicate that regex syntax into move_files_fullpath_replacements otherwise any replacement to tv shows that are released by date are ignored for some reason.

I'm getting a little OCD here, but the last thing that I'm trying to achieve is simply stripping all non-alphanumeric characters whatsoever, since it makes going through directories a lot easier without having to type escape characters into the command line for paranthesis and since xbmc doesn't really care about them when I believe it just querries tvdb with the year as part as the title field, not needing to parse it out or anything.

I've started with inputting the following into move_files_fullpath_replacements and output_series_replacements without success:

{"is_regex": true,
"match": "(",
"replacement": ""}

Any idea about how I could go about doing that?

lahwaacz commented 11 years ago

1) Sorry for the confusion, in fact output_filename_replacements are matched first, then if you have move_files_enable set to True move_files_fullpath_replacements are matched. Also note that output_filename_replacements are matched only against the filename (the part after the last /, extension included) and move_files_fullpath_replacements are matched against full path.

2) You can use something like this, which will just remove all non-alphanumeric characters from the matched string (the ^ negates the character set in []):

{"is_regex": true,
"match": "[^a-zA-Z0-9]",
"replacement": ""}

3) It doesn't work, because "(" is not valid regular expression - if you set "is_regex": false, it might work, but I recommend my previous suggestion.

edit: you might want to check filename_with_episode and similar formating strings, you might customize them to better fit your needs - the defaults contain a lot of non-alphanumeric characters.

jkwill87 commented 11 years ago

thanks for explaining that..

{"is_regex": true,
"match": "[^a-zA-Z0-9_]",
"replacement": ""}

worked perfectly, thanks