#56 open
kientran (at gmail)

Date Based Episodes fail to to assign season and episode number

Reported by kientran (at gmail) | June 24th, 2010 @ 05:40 PM | in v2.4

I was attempting to rename some episodes of some talk shows I have, and tvnamer is failing.

The first problem is that in the default config, there is not a filename_with_date_and_episode set. I just copied the filename_with_episode line and the result is as such.

"filename_with_date_and_episode": "%(seriesname)s %(seasonno)1dx%(episode)s - %(episodename)s%(ext)s",

Now when I attempt to parse a file, this is the result.

# Processing file: tonight.show.conan.2009.06.05.hdtv.xvid-chgrp.avi
# Detected series: tonight show conan (season: -1, episode: 2009-06-05)
TVDB Search Results:
1 -> The Tonight Show with Conan O'Brien [en] # http://thetvdb.com/?tab=series&id=85285&lid=7
Automatically selecting only result
Old filename: tonight.show.conan.2009.06.05.hdtv.xvid-chgrp.avi
New filename: The Tonight Show with Conan O'Brien -1x2009-06-05 - Ryan Seacrest, Patton Oswalt, Chickenfoot.avi

As you can see, it considers the season as "-1" and the episode number as "2009-06-05"

I looked though the code and have come up with this rough pseudo code logic (I'm not a Python programer)

tvnamer(paths)   paths = tonight.show.conan.2009.06.05.hdtv.xvid-chgrp.avi

  regex parses filename and generates key pairs for year, month, day
  if year,month, and day then
  episodenumbers = 2009-06-05

  if seasonnumber in namedgroup (false as there's no season key)
  elseif year month day
  seasonnumber = -1   #this is where things get wonky

  parse() returns the following object
  episode = 
    seriesname = seriesname
    seasonnumber = -1
    episodenumbers = 2009-06-06
    filename = tonight.show.conan.2009.06.05.hdtv.xvid-chgrp.avi

back to tvnamer()
Appends episode object to episode_found stack

processFile (tvdb, episode)
  correctedSeriesName, epName = getEpisodeName()

  inside getEpisodeName
    if episode.seasonnumber = -1
      sr = show.airedOn(cepno)  #cepno = 2009-06-05
      epName = sr[0]['episodename']  # "Ryan Seacrest, Patton Oswalt, Chickenfoot"
    getEpisodeName() returns the above episode name
  back to processFile()
  episode.seriesname = correctedSeriesName
  episode.episodename = epName
From here it generates the file name as usual but the problem is
  episode.seasonnumber = -1
  episode.episodenumbers = 2009-06-06

which results in 
  New filename: The Tonight Show with Conan O'Brien -1x2009-06-05 - Ryan Seacrest, Patton Oswalt, Chickenfoot.avi

From the logic processFile does not correct for the fact that date
based episodes do indeed have season and episode numbers.

One option would be to have processFile detect that the seasonnumber is -1
and instead of running getEpisodeName it runs getEpisodeByDate which looks
something like follows

getEpisodebyDate(tvdb_instance, episode)

  if episode.seasonnumber = -1
      sr = show.airedOn(cepno)  #cepno = 2009-06-05
      epName = sr[0]['episodename']    # "Ryan Seacrest, Patton Oswalt, Chickenfoot"
      seNum  = sr[0]['seasonnumber']   # 1
      epNum  = sr[0]['episodenumber']  # 5

  return correctedShowName, seNum, epNum, epName

This function would return the appropriate values which are corrected in the episode
object. From there, processFile will run episode.generateFilename() with the
correct season and episode numbers in place.

In retrospect, I prob could do this myself and have you pull it in if you agree with the logic.

Comments and changes to this ticket

  • dbr/Ben

    dbr/Ben June 25th, 2010 @ 09:52 PM

    • State changed from “new” to “open”


    The reason season is -1 is because the date-based episodes are currently hackish, and relies on season being set to a magic number (-1), the psuedo code is..

    if year,month, and day then
        episode = [datetime(2009-06-05)]
        seasonnumber = -1
        episodenumbers = [1, 2, 3]
        seasonnumber = 2
    function generateName:
        if season_number == -1:

    I'm planning to rewrite this soon, so it doesn't rely on on the magic -1 value, and I will make sure you can still access seasonnumber and episodenumber as one would expect.

  • dbr/Ben

    dbr/Ben June 25th, 2010 @ 10:19 PM

    Oh, also, there's no filename_with_date_and_episode, it's using the default filename_with_episode, thus the -1x2009-12-23 string. The following exist currently:


    I need to add a %(episode_date)s parameter to the string formatting options, or possibly add a filename_with_date (although the former is more flexible, as it means you can rename show.s02e01 to show - 2010-11-23 or whatever

    In case you're wondering why it's so incomplete, the date-based parsing was not added for tvnamer, but for http://sickbeard.com/ - I haven't fully implemented the date-based episode handling, yet!

  • Dave

    Dave August 4th, 2010 @ 01:24 AM

    • Milestone order changed from “0” to “0”

    I've got a 'fix' of sorts, for anyone that's interested in this. I understand this almost certainly isn't the best way of doing things. For background, I run tvnamer in batch mode which takes a file (in this case, episodes of The Daily Show) and moves them using move_files_enable to the right place on the file system.

    I've tried to avoid code modification as much as possible, since this is a hack after all :-) The diff file fixes a minor problem with makeValidFilename if the season number == -1 and adds the appropriate filename_with_date_and_episode string in the config. With this config the file will then be renamed as:

    the.daily.show.2004.10.05.avi -> "2004-10-05 - Billy Bob Thornton.avi"

    Then I use the following custom configuration options in the JSON config:

    "move_files_destination": "/var/media/TV Series/%(seriesname)s/Season %(seasonnumber)s/",
    "move_files_enable": true,
    "move_files_fullpath_replacements": [ { "is_regex": true, "match": "/Season -1/(\\d\\d\\d\\d)", "replacement": "/\\1/\\1" } ],

    The fullpath replacement will modify the Season -1 folder to something more sensible; in this we get

    the.daily.show.2004.10.05.avi -> /var/media/The Daily Show/2004/2004-10-05 - Billy Bob Thornton.avi

    Hope this proves useful for someone! And my thanks for such a useful little utility, it's made my life infinitely easier to manage my excessively large TV collection!

  • Ramon Felciano

    Ramon Felciano September 22nd, 2010 @ 03:14 PM

    It looks like the current design uses date formats as the episode number for date-based episodes. Is it possible to have both? It looks like some shows have both. For example, the Daily Show (http://www.thetvdb.com/?tab=season&seriesid=71256&seasonid=...) is clearly date-based, but has both season and episode numbers as well.

  • dbr/Ben

    dbr/Ben September 22nd, 2010 @ 07:59 PM

    The date-based filenames are still incomplete, next thing I plan is to expose an episodedate parameter, so you can do something like %(seriesname)s - %(episodedate)s%(ext)s

    it possible to have both?

    Yep, that's the plan

    The diff file fixes a minor problem with makeValidFilename if the season number == -1

    The recent changes should make this a non-issue - the seasonnumber = -1 was a temporary hackish way to support date-based episodes, but it is much tidier now (uses a separate DateBasedEpisodeInfo class, instead of the old single EpisodeInfo with lots of special cases)

  • Dave

    Dave October 17th, 2010 @ 10:16 PM

    For anyone using the most recent git version, naming works great but it looks like move_files was broken since getDestinationFolder couldn't cope with DatedEpisodeInfo objects. I've patched it up (attached); this adds a new config option, move_files_destination_date, which is the same as move_files_destination but instead your available variables are seriesname, year, month and day. For example setting this to:

    /var/media/TV Series/%(seriesname)s/%(year)s/

    gives the same behaviour I described as above without the regexp madness :-)

    Not sure if this is how the move functionality should be left... it seems like it should really be incorporated into the EpisodeInfo class structures instead. But this works for now and fixes the problem for anyone that needs the functionality.

  • dbr/Ben

    dbr/Ben January 4th, 2011 @ 11:02 AM

    • Milestone set to v2.3
    • Milestone order changed from “186709” to “0”
  • Fred Damstra

    Fred Damstra March 6th, 2011 @ 05:42 AM

    Thanks for this. Exactly what I was looking for.

  • Ramon Felciano

    Ramon Felciano November 14th, 2011 @ 03:47 PM

    It looks like v2.2 was released but Dave's patch wasn't included. As a result move_files is still broken when dealing with DateEpisodeInfo objects:

    Old filename: The Colbert Report - 2011-09-28 Ken Burns.avi
    New filename: The Colbert Report - [2011-09-28] - Ken Burns.avi
    Traceback (most recent call last):
      File "C:\Python26\Scripts\tvnamer-script.py", line 8, in <module>
        load_entry_point('tvnamer==2.2', 'console_scripts', 'tvnamer')()
      File "build\bdist.win32\egg\tvnamer\main.py", line 368, in main
      File "build\bdist.win32\egg\tvnamer\main.py", line 283, in tvnamer
      File "build\bdist.win32\egg\tvnamer\main.py", line 169, in processFile
      File "build\bdist.win32\egg\tvnamer\main.py", line 62, in getDestinationFolder
    AttributeError: 'DatedEpisodeInfo' object has no attribute 'seasonnumber'

    Is there another way to pass date-based episodes into the move files functionality?

  • dbr/Ben
  • dbr/Ben

    dbr/Ben November 15th, 2011 @ 12:22 AM

    Oh, I somehow completely missed Dave's patch - made this change, moving date-based episodes should be working now - thanks!

    Still need to expose the season/episode numbers to them, however..

  • Ramon Felciano

    Ramon Felciano November 15th, 2011 @ 02:43 PM

    Thanks for the quick turnaround!

    While we're at it, is there a difference between the pattern variables seasonnumber and seasonno? If not it might be worth unifying them.

  • dbr/Ben

    dbr/Ben November 15th, 2011 @ 11:50 PM

    Good point. I've added seasonnumber as an attribute for the filename pattern. Will deprecate seasonno at some point (but it'll continue working for now)

  • dbr/Ben

    dbr/Ben November 23rd, 2011 @ 08:53 PM

    (from [5ed428222df3fd2ae5761ad4c59d35410b48d5a4]) Add "seasonnumber" to filename patterns [#56]

    Will deprecate the inconsistent seasonno at some point

  • dbr/Ben

    dbr/Ben March 8th, 2012 @ 04:03 PM

    • Milestone changed from v2.3 to v2.4
    • Milestone order changed from “7” to “0”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket