Code Monkey home page Code Monkey logo

tvnamer's Introduction

tvnamer

PyPI Build Status codecov

tvnamer is a utility to rename files from some.show.s01e03.blah.abc.avi to Some Show - [01x03] - The Episode Name.avi (by retrieving the episode name using data from tvdb_api)

It supports Python 3.5 onwards. The last version of tvnamer to support Python 2.7 was tvnamer==3

TV information is provided by TheTVDB.com, but we are not endorsed or certified by TheTVDB.com or its affiliates.

Installing

The "official" way to install tvnamer is via pip:

pip install tvnamer

This installs the tvnamer command-line tool and the requirements from the tvnamer package on PyPI

Alternatively, the community have packaged tvnamer in various platform/distro specific package managers, including:

  1. Homebrew for OS X - brew install tvnamer
  2. Debian - apt-get install tvnamer
  3. FreeBSD/DragonFlyBSD/MacPorts - pkg install py36-tvnamer etc
  4. Nix package manager - nix-env -iA nixpkgs.python37Packages.tvnamer

Although not recommended for general use, see CONTRIBUTING.md for details on installing the unstable development version.

Features

  • Interactive command line based interface, with a non-interactive "batch" mode for automation.
  • Comprehensive set of file-name matching patterns
  • Handles non-ASCII names
  • Support for anime filenames, such as [Shinsen-Subs] Beet - 19 [24DAB497].mkv
  • Support for multi-episode files, such as scrubs.s01e23e24.avi
  • Extensive configuration options (via a JSON config file) and command-line arguments, including output name customising, series name replacements
  • Support for moving files to specific location after renaming (/media/tv/{series name}/season {seasonnumber}/ for example)

Bugs?

Please file issues on tvnamer's Github Issues page

Please make tickets for any possible bugs or feature requests, or if you discover a filename format that tvnamer cannot parse (as long as a reasonably common format, and has enough information to be parsed!), or if you are struggling with the a custom configuration (please state your desired filename output, and what problems you are encountering)

Basic usage

From the command line, simply run:

tvnamer the.file.s01e01.avi

For example:

$ tvnamer brass.eye.s01e01.avi
####################
# Starting tvnamer
# Found 1 episodes
# Processing brass.eye.s01e01.avi
TVDB Search Results:
1 -> Brass Eye [en] # http://thetvdb.com/?tab=series&id=70679&lid=7
Automatically selecting only result
####################
# Old filename: brass.eye.s01e01.avi
# New filename: Brass Eye - [01x01] - Animals.avi
Rename?
([y]/n/a/q)

Enter y then press return and the file will be renamed to "Brass Eye - [01x01] - Animals.avi". You can also simply press return to select the default option, denoted by the surrounding []

If there are multiple shows with the same (or similar) names or languages, you will be asked to select the correct one - "Lost" is a good example of this:

$ tvnamer lost.s01e01.avi
####################
# Starting tvnamer
# Found 1 episodes
# Processing lost.s01e01.avi
TVDB Search Results:
1 -> Lost [en] # http://thetvdb.com/?tab=series&id=73739&lid=7
2 -> Lost [sv] # http://thetvdb.com/?tab=series&id=73739&lid=8
3 -> Lost [no] # http://thetvdb.com/?tab=series&id=73739&lid=9
4 -> Lost [fi] # http://thetvdb.com/?tab=series&id=73739&lid=11
5 -> Lost [nl] # http://thetvdb.com/?tab=series&id=73739&lid=13
6 -> Lost [de] # http://thetvdb.com/?tab=series&id=73739&lid=14
Enter choice (first number, ? for help):    

To select the first result, enter 1 then return, to select the second enter 2 and so on. The link after # goes to the relevant [thetvdb.com][tvdb] page, which will contain information and images to help you select the correct series.

You can rename multiple files, or an entire directory by using the files or directories as arguments:

$ tvnamer file1.avi file2.avi etc
$ tvnamer .
$ tvnamer /path/to/my/folder/
$ tvnamer ./folder/1/ ./folder/2/

You can skip a specific file by entering n (no). If you enter a (always) tvnamer will rename the remaining files automatically. The suggested use of this is check the first few episodes are named correctly, then use a to rename the rest.

Note, tvnamer will only descend one level into directories unless the -r (or --recursive) flag is specified. For example, if you have the following directory structure:

dir1/
    file1.avi
    dir2/
        file2.avi
        file3.avi

..then running tvnamer dir1/ will only rename file1.avi, ignoring dir2/ and its contents.

If you wish to rename all files (file1, file2 and file3), you would run:

tvnamer --recursive dir1/

Command line arguments

There are various flags you can use with tvnamer, run..

tvnamer --help

..to see them, and a short description of each.

The most useful are most likely --batch, --selectfirst and --always:

--selectfirst will select the first series the search found, but will not automatically rename any episodes.

--always will ask you select the correct series, then automatically rename all files.

--batch will not prompt you for anything. It automatically selects the first series search result, and automatically rename all files (identical to using both --selectfirst and --always). Use carefully!

--series-id will allow you to use a specific ID from theTVdb. This can help with name detection issues.

Configs

One of the largest improvements in tvnamer v2 is the ability to have custom configuration. This allows you to customise behaviour without modifying the code (as was necessary with tvnamer v1).

To write the default JSON configuration file, which is a good starting point for your modifications, simply run:

tvnamer --save=./mytvnamerconfig.json

To use your custom configuration, you must either specify the location using tvnamer --config=/path/to/mytvnamerconfig.json or place the file at ~/.config/tvnamer/tvnamer.json

Important: If tvnamer's default settings change and your saved config contains the old settings, you may experience strange behaviour or bugs (the config may contain a buggy filename_patterns regex, for example). It is recommended you remove config options you are not altering (particularly filename_patterns). If you experience any strangeness, try disabling your custom configuration (moving it away from ~/.config/tvnamer/tvnamer.json)

If for example you wish to change the default language used to retrieve data, change the option language to another two-letter language code, such as fr for French. Your config file would look like:

{
    "language": "fr"
}

If search_all_languages is true, tvnamer will return multilingual search results. If false, it will return results only in the preferred language.

For an always up-to-date description of all config options, see the comments in config_defaults.py

Custom output filenames

If you wish to change the output filename format, there are a bunch of options you can change.

The most common is an episode with both a season and episode number. There are two patterns, one for when an episode name is found, and one without the episode name:

  • One for a file with an episode name (filename_with_episode). Example input: Scrubs.s01e01.my.ep.name.avi
  • One for a file without an episode name (filename_without_episode). Example input: AnUnknownShow.s01e01.avi

Next, for episodes without a season number:

  • One for a filename with no season number, and an episode name (filename_with_episode_no_season). Example input: Sid.The.Science.Kid.E11.avi
  • One for a filename with no season number, and no episode name (filename_without_episode_no_season). Example input: AnUnknownShow.E24.avi

Date-based episodes (which used aired-date instead of episode numbers):

  • One for date-based episodes (filename_with_date_and_episode). Example input: AnUnknownShow.2000-01-23
  • Date-based episode without epiosde nam (filename_with_date_without_episode)

Finally, anime episodes have the usual with/without episode names, and again with/without the CRC value:

  • filename_anime_with_episode - for example, [SubGrp] SeriesName - 02 - Episode Name [CRC1234].ext
  • filename_anime_without_episode - for example, [SubGrp] SeriesName - 02 [CRC1234].ext
  • filename_anime_with_episode_without_crc - for example, [SubGrp] SeriesName - 02 - Episode Name.ext
  • filename_anime_without_episode_without_crc - for example, [SubGrp] SeriesName - 02.ext

This may seem like a lot, but they are mostly the same thing. They all have sensible default values, so you can only change the values you use commonly (say, you could ignore the date-based and anime episodes if you rarely rename such files)

Say you want the format Show Name 01x24 Episode Name.avi, your filename_with_episode option would be:

%(seriesname)s %(seasonno)02dx%(episode)s %(episodename)s%(ext)s

The formatting language used is Python's string formatting feature, which you can read about in the Python documentation, 6.6.2. String Formatting Operations. Basically it's just %()s and the name element you wish to use between ( )

Note ext contains the extension separator symbol, usually . - for example .avi

Then you need to make a few variants, one without the episodename section, and two without the seasonno option:

filename_with_episode_no_season:

%(seriesname)s %(seasonno)02dx%(episode)s %(episodename)s%(ext)s

filename_without_episode:

%(seriesname)s %(seasonno)02dx%(episode)s%(ext)s

filename_without_episode_no_season:

%(seriesname)s %(episode)s%(ext)s

There are yet two more options you may want to change, episode_single and episode_separator

episode_single is the Python string formatting pattern used to format the episode number. By default it is %02d - this simply turns the number 1 to 01, and keeps 24 as 24

If you do not want any padding in your numbers, you could change this to %d - this would result in filenames such as Show - [1x3] - Episode Name.avi (or Show 1x3 Episode Name.avi using your custom name, as described above)

The episode_separator option is for multi-episode files. When multiple episodes are detected in one file (such as Scrubs.s01e01e02.avi), this string is used to join the episode numbers together. By default it is - which results in filenames such as Scrubs - [01x01-02] - ... .avi

You could change this to e, and by altering the filename_* options you could create filenames such as..

Show - [s01e01e02] - Episode Name.avi

By default, tvnamer will sanitise files for the current operating system - either POSIX-compatible (OS X, Linux, FreeBSD) or Windows. You can force Windows compatible filenames by setting the option windows_safe_filenames to True

The preferred way to replace spaces with another character is to use the custom replacements feature. For example, to replace spaces with . you would use the config:

{
    "output_filename_replacements": [
        {"is_regex": true,
        "match": "[ ]",
        "replacement": "."}
    ]
}

You can also remove spaces in characters by adding a space to the option custom_filename_character_blacklist and changing the option replace_blacklisted_characters_with to .

normalize_unicode_filenames attempts to replace Unicode characters with their unaccented ASCII equivalent (å becomes a etc). Any untranslatable characters are removed.

selectfirst and always_rename mirror the command line arguments --selectfirst and --always - one automatically selects the first series search result, the other always renames files. Setting both to True is equivalent to --batch. recursive also mirrors the command line argument

lowercase_filename converts the entire filename to lower case.

This document does not describe all config options - for a complete list, see the comments in config_defaults.py

Custom filename parsing pattern

tvnamer comes with a set of patterns to parse a majority of common (and many uncommon) TV episode file names. If these don't parse your files, you can write custom patterns.

The patterns are regular expressions, compiled with the re.VERBOSE flag. Each pattern must contain several named groups.

Named groups are like regular groups, but the group starts with ?P<thegroupname>. For example:

(?P<seriesname>.+?)

All patterns must contain a named group seriesname - this is of course the name of the show the filename contains.

Optionally you can parse a season number using the group seasonnumber. If this group is not specified, it will search for the episode(s) in season 1 (following the [thetvdb.com][tvdb] convention)

You must also match an episode number group. For simple, single episode files use the group episodenumber

If you wish to match multiple episodes in one file, there two options:

  • episodenumber1 episodenumber2 etc - match any number of episode numbers (can be non-consecutive), or..
  • Two groups, episodenumberstart and episodenumberend - you match the first and last numbers in the filename. If the start number is 2, and the end number is 5, the file contains episodes [2, 3, 4, 5].

Regex flags in config files

Regular expressions are used in several places in the config. It can be useful to specify flags the "ignore case" flag. This can be done with the (?...) syntax, e.g to replace and, And, AND etc with &:

{
    "input_filename_replacements": [
        {"is_regex": true,
        "match": "(?i)and",
        "replacement": "&"}
    ]
}

See the other flags in the Python re docs (search for (?iLmsux) on the page)

tvnamer's People

Contributors

adamrodger avatar beck avatar cmcclure avatar darkpixel avatar dbr avatar eregon avatar jaggaer-mhansy avatar jlejeune avatar lutzky avatar mcclurec avatar midgetspy avatar milkyjoe avatar minrk avatar miracle2k avatar monirzadeh avatar nikdoof avatar oliverclaude avatar oracal avatar pgilad avatar pogman-code avatar port3m5 avatar tremby avatar virusdave avatar whyman avatar wikey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tvnamer's Issues

Show names imported with colon in it

Hi,

I just wanted to start by saying thanks for the work you do on this, very much appreciated.
An issue I find from time to time is when the show name that is imported from tvdb contains a colon in the name e.g. Man vs. Wild - [07x10] - Norway: Edge of Survival.avi

This is an invalid filename for Windows and Linux and causes the filename to become gibberish.
Is there anyway you can add a case to the rename for this character so that if it is found it will use a comma or ignore it?

Thanks

Mark

Option to use symlinks

It would be nice to use symlink instead of moving/renaming the original file so that applications can still access the file from its previous location. I would suggest two options: link-to to generate a link to the original file with the new name at the new location and link-from to generate a link with the old name after the file has been moved/renamed.

Alias in tvshows names

I think this is more a feature request that an issue but here it goes anyway.

Say we have a tvshow name like "CSI.New.York.S07E10.HDTV.XviD-LOL.avi". The tvdb name for the show can be CSI: NY or CSI: New York. I would never use ":" in a filename and seems that any show I get has exactly the same issue.

Therefore when you try to rename it you get:

Processing file: CSI.New.York.S07E10.HDTV.XviD-LOL.avi

Detected series: CSI New York (season: 7, episode: 10)

ShowNotFound('Show CSI New York not found on www.thetvdb.com',)

Old filename: CSI.New.York.S07E10.HDTV.XviD-LOL.avi
New filename: CSI.New.York-S07E10.avi

My suggested solution is to have an alias file where we can specify alternative naming to TV shows. You can either get tvnamer to search for all the aliases or, even better, use the aliases in case the main search is not successful. For example:

Realname: alias 1, alias 2, alias3
"CSI: New York": "CSI NY", "CSI: NY", "Crime Scene Investigation: New York"

Request : support ssh

Can we imagine to have the possibility to move files through SSH ?
Of course to avoid password we must set a connexion with a certificate for example and we can imagine a synthax like this for the destination directory :

ssh://user@ip/path

Thanks a lot

Preserve original filename

It seems like considering the application, an option to protect the original filename would be valuable. At this point, I don't see a way to copy the file to another folder and rename it, but leave the original file alone.

Using %(original filename)s I was able to move the file to the new destination with the original filename, but it renamed the file in the original destination. Is there a way to reverse this in the JSON file?

Script fails when executing by filetype associations on Windows

Executing tvnamer on Microsoft Windows without explicitly executing a python interpretor causes the option parser to fail unexpectedly. Standard out result:

 dbr-tvdb_api-dad05f3>tvnamer.py "f:\some valid path"
 Usage: tvnamer.py [options] <file or directories>

 tvnamer.py: error: No filenames or directories supplied

This also happens for other options, such as --help or -h as a result. When explicitly executed in python tvnamer is successful.

 dbr-tvdb_api-dad05f3>python tvnamer.py --help
 Usage: tvnamer.py [options] <file or directories>

 Options:
   -h, --help         show this help message and exit
   -d, --debug        show debugging info
   -b, --batch        selects first search result, requires no human
                      intervention once launched
   -i, --interactive  interactivly select correct show from search results
                      [default]
   -s, --selectfirst  automatically select first series search result (instead
                      of showing the select-series interface)
   -r, --recursive    recursivly search supplied directories for files to
                      rename
   -a, --always       always renames files (but still lets user select correct
                      show). Can be changed during runtime with the 'a' prompt-
                      option
   -f, --force        forces file to be renamed, even if it will overwrite an
                      existing file

Just move option (without renaming)

Hello,

I try to find option for move files to Series name directory without renaming files. But there is no I guess. Only I can edit tvnamer.json to erase all renaming options and add move option.

Could you add like --just-move option or similar thing?

queeup.

Crash when searching without permissions

Traceback (most recent call last):
  File "/usr/bin/tvnamer", line 9, in <module>
    load_entry_point('tvnamer==2.0', 'console_scripts', 'tvnamer')()
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 351, in main
    tvnamer(paths = sorted(args))
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 245, in tvnamer
    for cfile in findFiles(paths):
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 216, in findFiles
    valid_files.extend(cur.findFiles())
  File "/usr/lib/python2.7/site-packages/tvnamer/utils.py", line 196, in findFiles
    return self._findFilesInPath(self.path)
  File "/usr/lib/python2.7/site-packages/tvnamer/utils.py", line 225, in _findFilesInPath
    allfiles.extend(self._findFilesInPath(newpath))
  File "/usr/lib/python2.7/site-packages/tvnamer/utils.py", line 216, in _findFilesInPath
    for subf in os.listdir(unicode(startpath)):
OSError: [Errno 13] Permission denied: '/boot/lost+found'

Move subtitles along with video files

Hi,
I've been using this program only for an hour, so maybe I missed something, so I'll ask first:
I've noticed that the program renames subtitles as well, but the problem is that I have subtitles in two different languages for most of the episodes, so my collection basically looks like this:
episode1.avi
episode1.eng.srt
episode1.cze.srt
and so on. Tvnamer renames the first subtitle to episode1.srt and then obviously fails on the second.
I tried to specify 'valid_extensions': ['eng.srt','cze.srt','avi'] in the config, but that doesn't work because os.path.splitext() splits only the last part ('srt').
Is there some way to configure this? If not, I'd like to file a feature request.

Req: "touch" file to "best guess" of original broadcast date/time.

Using tvdpapi, capture the firstaired (date) from the episode data, and the airs_time (time) from the series data to construct a date/time to "touch" the file after renaming/moving it.

Unfortunately, the airs_time seems to be in a multitude of formats. Just in the shows I have checked, I have seen all of the following:

10:00 PM EST
09:00 PM
10:00 pm
9:00 PM
10:00PM
9:30pm
22:00
8 PM
9 pm
9pm

Problem with 2 character years

I have a series which downloads as dd.mm.yy..avi
I added the following into the config to handle this

    '''
    ^((?P<seriesname>.+?)[ \._\-])?          # show name
    (?P<day>\d{2})                           # day
    [ \._\-]                                 # separator
    (?P<month>\d{2})                         # month
    [ \._\-]                                 # separator
    (?P<year>\d{2})                          # year
    [^\/]*$''',

However when this is parsed by the system it turns it into - 0011-07-26.avi
The problem is the 0011 should be 2011.

Is there any way for the system to put a 20 infront of a year instead of 00?

Thanks

tvnamer fails when used by multiple users

Since files are cached in /tmp/tvdb_api and that directory is owned by whatever user first used tvnamer, if another user comes along and tries to grab info on another show not already cached they get an error since tvnamer can't save the file into that directory.

Example error message:

DataRetrievalError("Error with www.thetvdb.com: Could not connect to server: [Errno 2] No such file or directory: '/tmp/tvdb_api/9dc4c83476074703f5bab38e7226c83b.body'",)

I guess you could just have the username as part of the temporary directory name, or have the files flat in /tmp rather than in a subdirectory (this way they'd still be shared) or maybe there's a better solution.

Problem with Umlauts

tvnamer is unable to scan my TV episodes containing umlauts in the filename.

Example output for:
Der gefährlichste Job Alaskas S01E02 - Schlaflose Nächte

ShowNotFound(u'Show Der gefa\u0308hrlichste Job Alaskas not found on www.thetvdb.com',)

KeyError: 'filename_with_date_and_episode'

####################
# Processing file: The.Daily.Show.2010.07.26.William.Rosen.720p.HDTV.x264-BAJSKORV.m4v
# Detected series: The Daily Show (season: -1, episode: 2010-07-26)
Traceback (most recent call last):
  File "/opt/local/bin/tvnamer-2.6", line 9, in <module>
    load_entry_point('tvnamer==2.0', 'console_scripts', 'tvnamer')()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/tvnamer/main.py", line 348, in main
    tvnamer(paths = sorted(args))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/tvnamer/main.py", line 267, in tvnamer
    processFile(tvdb_instance, episode)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/tvnamer/main.py", line 144, in processFile
    newName = episode.generateFilename()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/tvnamer/utils.py", line 550, in generateFilename
    fname = Config['filename_with_date_and_episode'] % epdata
KeyError: 'filename_with_date_and_episode'

Does not handle series remakes

It doesn't seem to handle series remakes very well, at least with Battlestar Galactica (original in 1978, remake in 2003) it only offers options for the 1978 version. There is no current way to correct this as adding the date to the filename causes it to fail to find the show at all.

thetvdb.com lists the following when doing a search for "Battlestar Galactica"
Battlestar Galactica - this is the same as the 1978 one and seems to be the one tvnamer picks up
Battlestar Galactica (1978) - same as above
Battlestar Galactica (2003) - tvnamer doesn't offer this one at all
(and some others)

I would expect that when the show has more then one version that tvnamer offers all the options so we can pick the correct version.

KeyError: u'seasonnumber'

Existing filename is correct: [Taka] Naruto Shippuuden - 262 - War Begins [4B93BD6A].mp4
####################
Traceback (most recent call last):
  File "/usr/bin/tvnamer-2.7", line 9, in <module>
    load_entry_point('tvnamer==2.2.1', 'console_scripts', 'tvnamer')()
  File "/usr/lib64/python2.7/site-packages/tvnamer/main.py", line 416, in main
    tvnamer(paths = sorted(args))
  File "/usr/lib64/python2.7/site-packages/tvnamer/main.py", line 323, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/lib64/python2.7/site-packages/tvnamer/main.py", line 243, in processFile
    newPath = getMoveDestination(episode)
  File "/usr/lib64/python2.7/site-packages/tvnamer/main.py", line 75, in getMoveDestination
    'originalfilename': episode.originalfilename,
KeyError: u'seasonnumber'

Add "always_copy" and "always_move" options

I'm trying to move files from one partition to another with -m.
Since tvnamer at the moment detects the different partitions and copies the files instead of moving them I'll have to try to find a solution which works outside of tvnamer.

It would be great if one could specify whether to force moving (or copying) of the files

Fails to parse names with special characters

Just tried sorting my Alias folder, but 1x05, 3x15 and 4x07 make the script fail due to the characters ä, ç and é in the source filenames, returning the error below:

Loading config: /home/peter/.tvnamer.json
/usr/local/lib/python2.6/dist-packages/tvnamer-2.0-py2.6.egg/tvnamer/main.py:233: UserWarning: The move_files feature is still under development. Be very careful with it.
It has not been heavily tested, and is not recommended for general use yet.
  warnings.warn("The move_files feature is still under development. "
####################
# Starting tvnamer
Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 9, in <module>
    load_entry_point('tvnamer==2.0', 'console_scripts', 'tvnamer')()
  File "/usr/local/lib/python2.6/dist-packages/tvnamer-2.0-py2.6.egg/tvnamer/main.py", line 348, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python2.6/dist-packages/tvnamer-2.0-py2.6.egg/tvnamer/main.py", line 244, in tvnamer
    cfile = cfile.decode("utf-8")
  File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 38: ordinal not in range(128)

The same happens with file moving disabled.
Replacing these characters makes everything work as expected.

Option for DVD order

The default list returned by tvdb list them in the order they where aired, which isn't always the order they where produced (the order they are on dvds).

For example firefly: aired and dvd order

It would be handy to have an option to pick which order to rename the series when they differ like this as it is generally more desirable to have the episodes listed in the order of the story rather then they order they where aired.

Filename with date move fail

When using a output directory structure like /volume1/Video/TV Shows/%(seriesname)s/Season %(seasonnumber)d/ dated file names don't move as they don't have a season number.

When looking up an episode by date, it should also poll for the season and episode number. This would allow you to translate between dated or episode number file names.

Use alias map for lookups

I ocasionally have the problem that lookups done solely by series name are not always correct, especcialy if there are more then one series with the same name. TVDB usually handles this problems by adding the year to the name, but file names do not always provide this information. Another example where this often fails are show with the US suffix because they are remakes of UK shows. It would be cool if one could just map series names to the complete series name or the series id in the config file so that tvnamer does not have to guess which series is the right one.

Support for DVD order

I haven't had a good look through tvdb yet but my very first thought on finding tvnamer was which order exactly will it put the episodes in -- original airing order or creator's intended order? I found a page about it on the tvdb wiki: http://www.thetvdb.com/wiki/index.php/DVD_Order

Is there any support for this? I'd always like to be my episodes to use the season numbers/episode numbers the creator intended, not what the network ended up using.

Crash because of lower key attribute

Traceback (most recent call last):
  File "/usr/bin/tvnamer", line 9, in <module>
    load_entry_point('tvnamer==2.0', 'console_scripts', 'tvnamer')()
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 351, in main
    tvnamer(paths = sorted(args))
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 268, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/lib/python2.7/site-packages/tvnamer/main.py", line 121, in processFile
    correctedSeriesName, epName = getEpisodeName(tvdb_instance, episode)
  File "/usr/lib/python2.7/site-packages/tvnamer/utils.py", line 52, in getEpisodeName
    show = tvdb_instance[episode.seriesname]
  File "/usr/lib/python2.7/site-packages/tvdb_api.py", line 772, in __getitem__
    key = key.lower() # make key lower case
AttributeError: 'NoneType' object has no attribute 'lower'

Episodes with puctuation marks cause OSError(22, 'Invalid argument')

I was cleaning up some episodes from It's Always Sunny in Philadelphia, and a handful wouldn't rename. What I look on TVDB, all the episode names have punctuation like colons or question marks. I believe TVNamer is trying to pass these through unescaped, and it's causing the failure. Here's a sample below.

####################
# Processing file: It's Always Sunny In Philadelphia - [S06E07].avi
# Detected series: It's Always Sunny In Philadelphia (season: 6, episode: 7)
####################
Old filename: It's Always Sunny In Philadelphia - [S06E07].avi
New filename: It's Always Sunny in Philadelphia - [S06E07] - Who Got Dee Pregnant?.avi
OSError(22, 'Invalid argument')
New path: /media/ARES/TV Shows/It's Always Sunny in Philadelphia/It's Always Sunny In Philadelphia - [S06E07].avi
Creating directory /media/ARES/TV Shows/It's Always Sunny in Philadelphia
OSError(u"File /media/ARES/TV Shows/It's Always Sunny in Philadelphia/It's Always Sunny In Philadelphia - [S06E07].avi already exists, not forcefully moving /media/ARES/TV Shows/It's Always Sunny in Philadelphia/It's Always Sunny In Philadelphia - [S06E07].avi",)

Episodes 5,7,9 & 10 of season six all have punctuation and all are failing the same way. Here's a link to the episode guide.
http://thetvdb.com/?tab=season&seriesid=75805&seasonid=268951&lid=7

On a side note: Thanks for this fantastic script. It's exactly what I needed.

Skip stuff not found

There might be an option for this and I missed it, do you have IRC or mailing list for general shit?

####################
# Processing file: Iron.Chef.America.Super.Chef.Battle.HDTV.XviD-01.01.2010.avi
# Detected series: Iron Chef America Super Chef Battle HDTV XviD-01.01 (season: 20, episode: 10)
ShowNotFound(u'Show Iron Chef America Super Chef Battle HDTV XviD-01.01 not found on www.thetvdb.com',)
####################
Old filename: Iron.Chef.America.Super.Chef.Battle.HDTV.XviD-01.01.2010.avi
New filename: Iron Chef America Super Chef Battle HDTV XviD-01.01 - [20x10].avi
Rename?

International character

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).

On FreeBSD, tvnamer marks ":" as a blacklisted character in a filename

Small issue. On FreeBSD, the colon (:) character is a valid char. It gets replaced with the "replace_invalid_characters_with" value (_ by default). Looking at utils.py, it looks like it checks for Darwin, Linux, and then thinks it's Windows. FreeBSD gets no love.

Patch:

--- tvnamer/utils.py.old        2010-05-06 16:16:42.000000000 +1000
+++ tvnamer/utils.py    2010-05-06 16:19:46.000000000 +1000
@@ -404,7 +404,7 @@
         # : is technically allowed, but Finder will treat it as / and will
         # generally cause weird behaviour, so treat it as invalid.
         blacklist = r"/:"
-    elif sysname == 'Linux':
+    elif sysname == 'Linux' or sysname == 'FreeBSD':
         blacklist = r"/"
     else:
         # platform.system docs say it could also return "Windows" or "Java".

This is a copy of issue #5.. I somehow closed it or something... sorry.

Replacing spaces with _ in filenames

I am trying to remove spaces in my filenames and replace them with _
According to the documentation it can be done with two variables in the json config file however I can't seem to get them to work.

My settings are

"custom_filename_character_blacklist": " ",
"replace_blacklisted_characters_with": "_",

Is there anything else that I need to add in order to get the replacement working? Any ideas?

Tosh.0

So.... the tvnamer strips the "."'s out of file names, cheers, but in the case of Tosh.0 it's required in order to turn up a result on theTVDB. Is there a way I can rename it (via Noodlesoft's Hazel) to exclude that period?

Something like:
if name contains "tosh" and ".0" rename to "Tosh/./0"+old file name.
Basically so that it goes from "aaf.tosh.0.s03.e02.avi" or some crap, to "Tosh/./0 - aff.tosh.0.s03e02.avi" which the script should be able to identify as "Tosh.0" and "S03E02".
Of course, I'm assuming that the "/" marks mean anything aside form designating spaces.

Thoughts?

Stop renaming hidden files

Hey just wondering if there is a way to ignore hidden files in a directory (files with a "." before the filename) or particular files with certain characters in the beginning (ie "._"). My media is stored on a Drobo FS and it seems to create hidden duplicates of some of the files and I want my TVNamer config files to ignore them. cheers

Issue with Python 2.7 / Mac OS Lion

Just running tvnamer with no parameters gives me this message which I don't quite understand:

Traceback (most recent call last):
File "/usr/local/bin/tvnamer", line 5, in
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in
working_set.require(requires)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more

Any ideas? Completely stopped working after upgrading to Lion.

Copy, then Rename?

I really want to use this tool on my Downloaded TV Torrents. Would it be possible to allow copying to the correct location (ie.: TV Show/Season #/) before renaming the file, leaving the original file unchanged so that seeding can still go on?

Similar to other requests, a "Always_Copy" option would be needed also.

Thanks.

Add prompt for series name if one cannot be found

Some downloaded files do not have the name of the series in the title (or have an abbreviation) but do have the season and episode tag. In such cases it would be helpful to get a dialog to manually search for the name of the series.

FreeBSD: tvnamer gets wrong name for episodes

When processing the episodes on freebsd, I get no or the wrong name for the episode:

####################
# Processing file: How I Met Your Mother - S07E13 - Tailgate.avi
# Detected series: How I Met Your Mother (season: 7, episode: 13)
2012-03-06 09:21:53,315 - tvdb_api - DEBUG - Correcting how i met your mother to 75760
2012-03-06 09:21:53,315 - tvdb_api - DEBUG - Got series id 75760
####################
Old filename: How I Met Your Mother - S07E13 - Tailgate.avi
New filename: How I Met Your Mother - S07E13 - Episode 13.avi
Rename?
([y]/n/a/q) n
Skipping

####################
# Processing file: How I Met Your Mother - S07E14 - 46 Minutes.avi
# Detected series: How I Met Your Mother (season: 7, episode: 14)
2012-03-06 09:22:08,254 - tvdb_api - DEBUG - Correcting how i met your mother to 75760
2012-03-06 09:22:08,254 - tvdb_api - DEBUG - Got series id 75760
####################
Old filename: How I Met Your Mother - S07E14 - 46 Minutes.avi
New filename: How I Met Your Mother - S07E14 - Zip, Zip, Zip.avi
Rename?

The 'old' name is the correct name. I installed tvnamer via pip (pip 1.0.2 from /usr/local/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg)

Has anyone the same problem?

main.py line 31 (episode.fullpath) AttributeError

I use tvnamer without install.

$ ls -h
cache.py     main.py    tools                tvdb_ui.py              utils.py
cache.pyc    Rakefile   tvdb_api.py          tvdb_ui.pyc             utils.pyc
config.py    readme.md  tvdb_api.pyc         tvnamer_exceptions.py
config.pyc   setup.py   tvdb_exceptions.py   tvnamer_exceptions.pyc
__init__.py  tests      tvdb_exceptions.pyc  tvnamer_ideas.txt
$ python -V
Python 2.5.2
$ uname -a
Linux xbmc 2.6.27-14-generic #1 SMP Mon Aug 31 13:01:41 UTC 2009 i686 GNU/Linux
$ ./main.py -v ../../.xbmc/downloads/Dizi/Tokyo\ Magnitude/
####################
# Starting tvnamer
Invalid filename /home/xbmc/.xbmc/downloads/Dizi/Tokyo Magnitude/tvshow.nfo
# Found 12 episodes
# Processing [BSS]_Tokyo_Magnitude_8.0_-_02_[0E5C4A40].mkv
2009-09-28 18:35:03,115) DEBUG Getting show tokyo magnitude 8 0
2009-09-28 18:35:03,117) DEBUG Searching for show tokyo%20magnitude%208%200
2009-09-28 18:35:03,117) DEBUG Retrieving URL http://www.thetvdb.com/api/GetSeries.php?seriesname=tokyo%20magnitude%208%200&language=en
2009-09-28 18:35:03,121) DEBUG URL http://www.thetvdb.com/api/GetSeries.php?seriesname=tokyo%20magnitude%208%200&language=en was cached in /tmp/tvdb_api/6e3eeae8fe5d82389d5d656100dde169.body
2009-09-28 18:35:03,122) DEBUG Series result returned zero
Show Tokyo Magnitude 8 0 not found on www.thetvdb.com
Traceback (most recent call last):
  File "./main.py", line 177, in 
    main()
  File "./main.py", line 170, in main
    tvnamer(paths = args)
  File "./main.py", line 111, in tvnamer
    processFile(tvdb_instance, episode)
  File "./main.py", line 31, in processFile
    cnamer = Renamer(episode.fullpath)
AttributeError: 'NoneType' object has no attribute 'fullpath'
$

Error if filename contains umlauts

I have always this problem if I try to run tvnamer on a file which contain german umlauts in it.

%% tvnamer testserieswithä_s01e01.avi
Loading config: /root/.tvnamer.json
####################
# Starting tvnamer
# Found 1 episode
####################
Traceback (most recent call last):
  File "/usr/bin/tvnamer-2.6", line 9, in 
    load_entry_point('tvnamer==2.1', 'console_scripts', 'tvnamer')()
  File "/usr/lib64/python2.6/site-packages/tvnamer/main.py", line 351, in main
    tvnamer(paths = sorted(args))
  File "/usr/lib64/python2.6/site-packages/tvnamer/main.py", line 268, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/lib64/python2.6/site-packages/tvnamer/main.py", line 112, in processFile
    p("# Processing file: %s" % episode.fullfilename)
  File "/usr/lib64/python2.6/site-packages/tvnamer/utils.py", line 518, in fullfilename
    return u"%s.%s" % (self.filename, self.extension)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 14: ordinal not in range(128)

Currently I am using tvnamer version 2.1 with python 2.6

List Missing Episodes

Just a small feature request, say you're sorting through a series would it be possible to list the files that can't be found or matched, hinting at episodes that might be missing?
There'd probably need to be a date check between date aired, but I think it would be a nice little feature.

On an unrelated note, can you supply an example on the homepage for input_filename_replacements ?
I tried adapting the output_filename_replacements section, but got an unusual output (also using old version).
May just be because I don't know regex very well, but a little guide would be awesome.

When using valid_extensions in a custom config file, recursive search doesn't work

When I change the following line from this:
"valid_extensions": ["avi","mp4","m4v","wmv","mkv","mov","srt"],
to this:
"valid_extensions": [],

recursive searching for files suddenly work, otherwise it says there are no files.

"recursive": true
and also tried the -r and --recursive command

Is it possible that dirs get ignored because they are not valid?

Manual interactive search

It would be nice to beable to manually search for a TV series name when tvnamer fails to find the correct show. The current workaround involves renaming all the files manually to the correct name when a show is miss labelled (or labelled in shorthand) which mostly defeated the purpose of this program. Adding a manual search option would help make it easier to correct badly named files.

Add language to srt files

Since I always download dutch srt-files I would like to know if it's possible to rename the srt-file from 'somename.srt to somename.nl.srt'? This should only affect the srt files, so not the movie-files!

I tried this with a folder action when the files are moved to the destination folder but the folder actions doen't seem to work with subfolders, which is the issue with series, especially when new folders are created.

EDIT:
The 'output_filename_replacements' only looks in the filename, not the extension (in contradiction to input_filename).

Hope someone can help me, I really love this piece of work!

Thank You.

Error using unicode data from TVDB

Trying to clear up some Seaquest episodes, and tvnamer fails on one episode called "Give Me Liberté"

####################
# Processing file: SeaQuest DSV - 1x06 - Treasures of the Tonga Trench.avi
# Detected series: SeaQuest DSV (season: 1, episode: 6)
####################
Old filename: SeaQuest DSV - 1x06 - Treasures of the Tonga Trench.avi
New filename: SeaQuest DSV - [S01E06] - Give Me Liberté.avi
Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 9, in <module>
    load_entry_point('tvnamer==2.2.1', 'console_scripts', 'tvnamer')()
  File "/usr/local/lib/python2.7/dist-packages/tvnamer/main.py", line 413, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python2.7/dist-packages/tvnamer/main.py", line 322, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/local/lib/python2.7/dist-packages/tvnamer/main.py", line 213, in processFile
    doRenameFile(cnamer, newName)
  File "/usr/local/lib/python2.7/dist-packages/tvnamer/main.py", line 91, in doRenameFile
    cnamer.newName(newName, force = Config['overwrite_destination_on_rename'])
  File "/usr/local/lib/python2.7/dist-packages/tvnamer/utils.py", line 966, in newName
    if os.path.isfile(newpath):
  File "/usr/lib/python2.7/genericpath.py", line 29, in isfile
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 98: ordinal not in range(128)

Moving to directory does not respect safe filenames

I am using version 2010-03-01 under Ubuntu 9.10.

I have configured my tvnamer.json such that files are moved to: /media/data/Series/%(seriesname)s/Season %(seasonnumber)s/

If a file is named, for instance, "Series: Series Subtitle", tvnamer will attempt to move it to:

"/media/data/Series/Series: Series Subtitle/Season 1/Series- Series Subtitle - S01E01.avi"

Note that the actual filename is presented with safe characters but the directory name is not.

Upon completion I am left with a corrupted directory.

Crashes on filenames containing unicode characters

tvnamer is able to rename files using unicode characters (ex. episode 5x13 of 30 Rock) but is unable to later read those files.

This is particularly painful when you add new files and run tvnamer multiple times over the same files.

Traceback (most recent call last): File "/usr/local/bin/tvnamer", line 8, in <module> load_entry_point('tvnamer==2.1', 'console_scripts', 'tvnamer')() File "build/bdist.macosx-10.7-intel/egg/tvnamer/main.py", line 351, in main File "build/bdist.macosx-10.7-intel/egg/tvnamer/main.py", line 268, in tvnamer File "build/bdist.macosx-10.7-intel/egg/tvnamer/main.py", line 161, in processFile File "build/bdist.macosx-10.7-intel/egg/tvnamer/main.py", line 62, in doRenameFile UnicodeEncodeError: 'ascii' codec can't encode character u'\xa1' in position 74: ordinal not in range(128)

<stdin> is a directory, cannot continue

Got this console error in combination with Hazel, a automation tool for osx.

this is how hazel run tvnamer:
/usr/local/bin/tvnamer --config=/Users/***/Documents/TVnamer/mytvnamerconfig.json "$1"

I'm on OSX Lion 10.7.3
What does that mean?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.