dbr / tvnamer

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

Python 3.0 Issue #134

Closed pcartwright81 closed 6 years ago

pcartwright81 commented 7 years ago

TypeError: can't concat bytes to str File "\appdata\local\programs\python\python35-32\lib\site-packages\tvnamer\utils.py", line 785, in generateFilename replace_with = Config['replace_invalid_characters_with']) File "\appdata\local\programs\python\python35-32\lib\site-packages\tvnamer\utils.py", line 554, in makeValidFilename return value + extension

value.decode("utf-8") Has to be put on line 543 and 554 in order for it to work.

ardumont commented 6 years ago

Hello,

Reproduced with tvnamer installed from pip (debian stable on rpi3).

Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tvnamer
>>> tvnamer.__version__
(2, 4)

Stacktrace:

####################
# Starting tvnamer
# Found 1 episode
####################
# Processing file: something.S0xE0y.something.mp4
# With custom replacements: something.S0xE0y.something.mp4
# Detected series: Something (season: x, episode: y)
Traceback (most recent call last):
File "/usr/local/bin/tvnamer", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/tvnamer/main.py", line 436, in main
tvnamer(paths = sorted(args))
File "/usr/local/lib/python3.5/dist-packages/tvnamer/main.py", line 342, in tvnamer
processFile(tvdb_instance, episode)
File "/usr/local/lib/python3.5/dist-packages/tvnamer/main.py", line 196, in processFile
newName = episode.generateFilename()
File "/usr/local/lib/python3.5/dist-packages/tvnamer/utils.py", line 786, in generateFilename
replace_with = Config['replace_invalid_characters_with'])
File "/usr/local/lib/python3.5/dist-packages/tvnamer/utils.py", line 544, in makeValidFilename
if len(value + extension) > max_len:
TypeError: can't concat bytes to str

value.decode("utf-8") Has to be put on line 543 and 554 in order for it to work.

Or we can flip to false the option in ~/.tvnamer.json... if that's a reasonable thing to do

   "normalize_unicode_filenames": false

Checking at the code mentioned, there is a if just before the line in error which encode the string in bytes. But the code after that goes on and try to concat stuff which are then no longer of the same types (with the previous option set to true).

Cheers,

dbr commented 6 years ago

Thanks! This is now fixed, will be in tvnamer 2.5

Should have been caught by the tests, but doesn't seem to be any for the normalize_unicode_filenames option, I should add one (and look closer at the test coverage)

ardumont commented 6 years ago

Awesome! Thanks!