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

International character #22

Closed tngranados closed 13 years ago

tngranados commented 13 years ago

I have noticed that when you try to use tvnamer with a file which has an international character on it (like ñ, á or ç) it give you an error like this:

Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 8, in 
    load_entry_point('tvnamer==2.1', 'console_scripts', 'tvnamer')()
  File "build/bdist.macosx-10.6-universal/egg/tvnamer/main.py", line 351, in main
  File "build/bdist.macosx-10.6-universal/egg/tvnamer/main.py", line 268, in tvnamer
  File "build/bdist.macosx-10.6-universal/egg/tvnamer/main.py", line 112, in processFile
  File "build/bdist.macosx-10.6-universal/egg/tvnamer/utils.py", line 518, in fullfilename
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 13: ordinal not in range(128)

(This one is for a file with ñ).

In my configuration file, normalize_unicode_filenames is true, so I don't know why is this happening. I'm using tvnamer on OS X.

PS: Are you planning to do something similar for movies? It would be great. PS 2: Thank you for your awesome work.

EDIT: It's seems like this error only happen when using a custom configuration. I tried to process a file with ñ with default config an it doesn't fail. EDIT 2: If I created a new config file and I use it with a file with ñ, it doesn't work (even when I don't touch anything from the config file created by tvnamer).

dbr commented 13 years ago

Same problem as #17

This is an utterly strange bug - even an empty config ({ }) causes the error.

Well spotted! Shall look into this soon.

PS: Are you planning to do something similar for movies? It would be great.

I never found the need for such a thing - it's pretty easy to rename such files manually, and they are one-off files. TV episodes are much more tedious!

I did write a Python wrapper for themoviedb, it should make it pretty simple to write such a tool - i.e something like:

import sys
import optparse

import tmdb

opter = optparse.OptionParser()
opts, args = opter.parse_args()
for fname in args:
    fpath, fname = os.path.split(fname)
    fname, fext = os.path.splitext(fname)
    film = tmdb.searchByHashingFile(fname)
    if raw_input().strip() in ['y', 'yes']:
        new_name = film['name'] + fext
        new_path = os.path.join(fpath, new_name)
        os.rename(fname, new_path)

..but, when I played about with it, I didn't find the find-film-by-hashing method to work for many files

Not really sure what such a tool would achieve? I guess a UI when you could run it on a file, start typing a name and it would autocomplete the name might be useful

tngranados commented 13 years ago

I have found a provisional fix. It's quite obvious, but in case you don't think on it, if we change the default configuration of tvnamer as we want, we can avoid the error (which only occurs when using an external config). It's not the best fix, but It can work provisionally.