• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

tests/H23-May-2021-3,5732,647

tvnamer/H23-May-2021-2,4171,676

tvnamer.egg-info/H03-May-2022-3229

MANIFEST.inH A D28-Jun-202055 43

PKG-INFOH A D23-May-20211.2 KiB3229

README.mdH A D30-Apr-202114.4 KiB281174

UNLICENSEH A D16-Sep-20171.2 KiB2721

setup.cfgH A D23-May-202138 53

setup.pyH A D30-Apr-20211.5 KiB6146

README.md

1# `tvnamer`
2
3[![PyPI][pypi-img]][pypi-link] [![Build Status][build-img]][build-link] [![codecov][coverage-img]][coverage-link]
4
5`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`](http://github.com/dbr/tvdb_api))
6
7It supports Python 2.7 and 3.5 onwards
8
9TV information is provided by TheTVDB.com, but we are not endorsed or certified by TheTVDB.com or its affiliates.
10
11[build-link]: https://travis-ci.org/dbr/tvnamer
12[build-img]: https://travis-ci.org/dbr/tvnamer.svg?branch=master
13[pypi-link]: https://pypi.org/project/tvnamer/
14[pypi-img]: https://img.shields.io/pypi/v/tvnamer
15[coverage-link]: https://codecov.io/gh/dbr/tvnamer
16[coverage-img]: https://codecov.io/gh/dbr/tvnamer/branch/master/graph/badge.svg
17
18## Installing
19
20The "official" way to install `tvnamer` is via `pip`:
21
22    pip install tvnamer
23
24This installs the `tvnamer` command-line tool and the requirements from [the `tvnamer` package on PyPI](https://pypi.python.org/pypi/tvnamer/)
25
26Alternatively, the community have packaged tvnamer in various platform/distro specific package managers, including:
27
281. [Homebrew for OS X](https://formulae.brew.sh/formula/tvnamer) - `brew install tvnamer`
292. [Debian](https://tracker.debian.org/pkg/tvnamer) - `apt-get install tvnamer`
303. [FreeBSD/DragonFlyBSD/MacPorts](https://www.freshports.org/multimedia/py-tvnamer) - `pkg install py36-tvnamer` etc
31
32Although not recommended for general use, see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for details on installing the unstable development version.
33
34## Features
35
36- Interactive command line based interface, with a non-interactive "batch" mode for automation.
37- Comprehensive set of file-name matching patterns
38- Handles non-ASCII names
39- Support for anime filenames, such as `[Shinsen-Subs] Beet - 19 [24DAB497].mkv`
40- Support for multi-episode files, such as `scrubs.s01e23e24.avi`
41- Extensive configuration options (via a JSON config file) and command-line arguments, including output name customising, series name replacements
42- Support for moving files to specific location after renaming (`/media/tv/{series name}/season {seasonnumber}/` for example)
43
44## Bugs?
45
46Please file issues on tvnamer's [Github Issues page](http://github.com/dbr/tvnamer/issues)
47
48Please 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)
49
50## Basic usage
51
52From the command line, simply run:
53
54    tvnamer the.file.s01e01.avi
55
56For example:
57
58    $ tvnamer brass.eye.s01e01.avi
59    ####################
60    # Starting tvnamer
61    # Found 1 episodes
62    # Processing brass.eye.s01e01.avi
63    TVDB Search Results:
64    1 -> Brass Eye [en] # http://thetvdb.com/?tab=series&id=70679&lid=7
65    Automatically selecting only result
66    ####################
67    # Old filename: brass.eye.s01e01.avi
68    # New filename: Brass Eye - [01x01] - Animals.avi
69    Rename?
70    ([y]/n/a/q)
71
72Enter `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 `[]`
73
74If 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:
75
76    $ tvnamer lost.s01e01.avi
77    ####################
78    # Starting tvnamer
79    # Found 1 episodes
80    # Processing lost.s01e01.avi
81    TVDB Search Results:
82    1 -> Lost [en] # http://thetvdb.com/?tab=series&id=73739&lid=7
83    2 -> Lost [sv] # http://thetvdb.com/?tab=series&id=73739&lid=8
84    3 -> Lost [no] # http://thetvdb.com/?tab=series&id=73739&lid=9
85    4 -> Lost [fi] # http://thetvdb.com/?tab=series&id=73739&lid=11
86    5 -> Lost [nl] # http://thetvdb.com/?tab=series&id=73739&lid=13
87    6 -> Lost [de] # http://thetvdb.com/?tab=series&id=73739&lid=14
88    Enter choice (first number, ? for help):
89
90To 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.
91
92You can rename multiple files, or an entire directory by using the files or directories as arguments:
93
94    $ tvnamer file1.avi file2.avi etc
95    $ tvnamer .
96    $ tvnamer /path/to/my/folder/
97    $ tvnamer ./folder/1/ ./folder/2/
98
99You 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.
100
101Note, 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:
102
103    dir1/
104        file1.avi
105        dir2/
106            file2.avi
107            file3.avi
108
109..then running `tvnamer dir1/` will only rename `file1.avi`, ignoring `dir2/` and its contents.
110
111If you wish to rename all files (file1, file2 and file3), you would run:
112
113    tvnamer --recursive dir1/
114
115## Command line arguments
116
117There are various flags you can use with `tvnamer`, run..
118
119    tvnamer --help
120
121..to see them, and a short description of each.
122
123The most useful are most likely `--batch`, `--selectfirst` and `--always`:
124
125`--selectfirst` will select the first series the search found, but will not automatically rename any episodes.
126
127`--always` will ask you select the correct series, then automatically rename all files.
128
129`--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!
130
131`--series-id` will allow you to use a specific ID from theTVdb. This can help with name detection issues.
132
133## Configs
134
135One 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).
136
137To write the default JSON configuration file, which is a good starting point for your modifications, simply run:
138
139    tvnamer --save=./mytvnamerconfig.json
140
141To 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`
142
143**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`)
144
145If 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:
146
147    {
148        "language": "fr"
149    }
150
151If `search_all_languages` is true, tvnamer will return multilingual search results. If false, it will return results only in the preferred language.
152
153For an always up-to-date description of all config options, see the comments in [`config_defaults.py`](http://github.com/dbr/tvnamer/blob/master/tvnamer/config_defaults.py)
154
155# Custom output filenames
156
157If you wish to change the output filename format, there are a bunch of options you can change.
158
159The 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:
160
161- One for a file with an episode name (`filename_with_episode`). Example input: `Scrubs.s01e01.my.ep.name.avi`
162- One for a file *without* an episode name (`filename_without_episode`). Example input: `AnUnknownShow.s01e01.avi`
163
164Next, for episodes without a season number:
165
166- 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`
167- One for a filename with no season number, and no episode name (`filename_without_episode_no_season`). Example input: `AnUnknownShow.E24.avi`
168
169Date-based episodes (which used aired-date instead of episode numbers):
170
171- One for date-based episodes (`filename_with_date_and_episode`). Example input: `AnUnknownShow.2000-01-23`
172- Date-based episode without epiosde nam (`filename_with_date_without_episode`)
173
174Finally, anime episodes have the usual with/without episode names, and again with/without the CRC value:
175
176- `filename_anime_with_episode` - for example, `[SubGrp] SeriesName - 02 - Episode Name [CRC1234].ext`
177- `filename_anime_without_episode` - for example, `[SubGrp] SeriesName - 02 [CRC1234].ext`
178- `filename_anime_with_episode_without_crc` - for example, `[SubGrp] SeriesName - 02 - Episode Name.ext`
179- `filename_anime_without_episode_without_crc` - for example, `[SubGrp] SeriesName - 02.ext`
180
181This 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)
182
183Say you want the format `Show Name 01x24 Episode Name.avi`, your `filename_with_episode` option would be:
184
185    %(seriesname)s %(seasonno)02dx%(episode)s %(episodename)s%(ext)s
186
187The formatting language used is Python's string formatting feature, which you can read about in the Python documentation, [6.6.2. String Formatting Operations](http://docs.python.org/library/stdtypes.html#string-formatting). Basically it's just `%()s` and the name element you wish to use between `( )`
188
189Note `ext` contains the extension separator symbol, usually `.` - for example `.avi`
190
191Then you need to make a few variants, one without the `episodename` section, and two without the `seasonno` option:
192
193`filename_with_episode_no_season`:
194
195    %(seriesname)s %(seasonno)02dx%(episode)s %(episodename)s%(ext)s
196
197`filename_without_episode`:
198
199    %(seriesname)s %(seasonno)02dx%(episode)s%(ext)s
200
201`filename_without_episode_no_season`:
202
203    %(seriesname)s %(episode)s%(ext)s
204
205There are yet two more options you may want to change, `episode_single` and `episode_separator`
206
207`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`
208
209If 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)
210
211The `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`
212
213You could change this to `e`, and by altering the `filename_*` options you could create filenames such as..
214
215    Show - [s01e01e02] - Episode Name.avi
216
217By 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
218
219The 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:
220
221    {
222        "output_filename_replacements": [
223            {"is_regex": true,
224            "match": "[ ]",
225            "replacement": "."}
226        ]
227    }
228
229
230You 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 `.`
231
232`normalize_unicode_filenames` attempts to replace Unicode characters with their unaccented ASCII equivalent (`å` becomes `a` etc). Any untranslatable characters are removed.
233
234`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
235
236`lowercase_filename` converts the entire filename to lower case.
237
238
239This document does not describe all config options - for a complete list, see the comments in [`config_defaults.py`](http://github.com/dbr/tvnamer/blob/master/tvnamer/config_defaults.py)
240
241
242# Custom filename parsing pattern
243
244`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.
245
246The patterns are regular expressions, compiled with the [`re.VERBOSE` flag](http://docs.python.org/library/re.html#re.VERBOSE). Each pattern must contain several named groups.
247
248Named groups are like regular groups, but the group starts with `?P<thegroupname>`. For example:
249
250    (?P<seriesname>.+?)
251
252All patterns must contain a named group `seriesname` - this is of course the name of the show the filename contains.
253
254Optionally 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)
255
256You must also match an episode number group. For simple, single episode files use the group `episodenumber`
257
258If you wish to match multiple episodes in one file, there two options:
259
260- `episodenumber1` `episodenumber2` etc - match any number of episode numbers (can be non-consecutive), or..
261- 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].
262
263# Regex flags in config files
264
265Regular expressions are used in several places in the config. It can
266be useful to specify flags the "ignore case" flag. This can be done
267with the `(?...)` syntax, e.g to replace `and`, `And`, `AND` etc with
268`&`:
269
270    {
271        "input_filename_replacements": [
272            {"is_regex": true,
273            "match": "(?i)and",
274            "replacement": "&"}
275        ]
276    }
277
278See the other flags
279[in the Python `re` docs](http://docs.python.org/2/library/re.html#regular-expression-syntax)
280(search for `(?iLmsux)` on the page)
281