Skip to content

Commit

Permalink
Fix/dated show name (nzbget#54)
Browse files Browse the repository at this point in the history
nzbget#52, nzbget#53, nzbget#54: fix DatedFormat and original letter case specifiers
  • Loading branch information
fleXible authored and hugbug committed Aug 28, 2019
1 parent e3e9900 commit 314f9f4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 34 deletions.
72 changes: 45 additions & 27 deletions VideoSort.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@
# for duplicate files such as "My Movie (2).mkv"
dupe_separator = ' '


class deprecation_support:
"""Class implementing iterator for deprecation message support"""

def __init__(self, mapping):
self.iter = iter(mapping)

def __iter__(self):
return self

def __next__(self):
map_entry = next(self.iter)
return map_entry if len(map_entry) >= 3 else list(map_entry) + [None]

def next(self):
return self.__next__()


def guess_dupe_separator(format):
""" Find out a char most suitable as dupe_separator
"""
Expand Down Expand Up @@ -573,10 +591,12 @@ def path_subst(path, mapping):
while n < plen:
result = path[n]
if result == '%':
for key, value in mapping:
for key, value, msg in deprecation_support(mapping):
if path.startswith(key, n):
n += len(key)-1
result = value
if msg:
print('[WARNING] specifier %s is deprecated, %s' % (key, msg))
break
newpath.append(result)
n += 1
Expand Down Expand Up @@ -848,19 +868,19 @@ def add_movies_mapping(guess, mapping):
# title
name = guess.get('title', '')
ttitle, ttitle_two, ttitle_three = get_titles(name, True)
title, title_two, title_three = get_titles(name, True)
mapping.append(('%title', title))
mapping.append(('%.title', title_two))
mapping.append(('%_title', title_three))
title, title_two, title_three = get_titles(name, False)
mapping.append(('%title', ttitle))
mapping.append(('%.title', ttitle_two))
mapping.append(('%_title', ttitle_three))

# title (short forms)
mapping.append(('%t', title))
mapping.append(('%.t', title_two))
mapping.append(('%_t', title_three))
mapping.append(('%t', ttitle))
mapping.append(('%.t', ttitle_two))
mapping.append(('%_t', ttitle_three))

mapping.append(('%tT', ttitle))
mapping.append(('%t.T', ttitle_two))
mapping.append(('%t_T', ttitle_three))
mapping.append(('%tT', title))
mapping.append(('%t.T', title_two))
mapping.append(('%t_T', title_three))

# year
year = str(guess.get('year', ''))
Expand All @@ -886,22 +906,20 @@ def add_dated_mapping(guess, mapping):
mapping.append(('%_title', title_three))

# title (short forms)
mapping.append(('%t', title))
mapping.append(('%.t', title_two))
mapping.append(('%_t', title_three))

mapping.append(('%sn', title))
mapping.append(('%s.n', title_two))
mapping.append(('%s_n', title_three))

mapping.append(('%sN', ttitle))
mapping.append(('%s.N', ttitle_two))
mapping.append(('%s_N', ttitle_three))

# Guessit doesn't provide episode names for dated tv shows
mapping.append(('%desc', ''))
mapping.append(('%.desc', ''))
mapping.append(('%_desc', ''))
mapping.append(('%t', title, 'consider using %sn'))
mapping.append(('%.t', title_two, 'consider using %s.n'))
mapping.append(('%_t', title_three, 'consider using %s_n'))

# Show name
series = guess.get('title', '')
show_tname, show_tname_two, show_tname_three = get_titles(series, True)
show_name, show_name_two, show_name_three = get_titles(series, False)
mapping.append(('%sn', show_tname))
mapping.append(('%s.n', show_tname_two))
mapping.append(('%s_n', show_tname_three))
mapping.append(('%sN', show_name))
mapping.append(('%s.N', show_name_two))
mapping.append(('%s_N', show_name_three))

# date
date = guess.get('date')
Expand Down
44 changes: 37 additions & 7 deletions testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@
"NZBPP_CATEGORY": "Kids cartoons"
},
{
"id": "movies-1",
"INPUTFILE": " The.Silence.Of.The.Lambs.1991.1080p.BluRay.CUSTOM.Plus.Criterion.Comm.DTS.x264-MaG.mkv",
"id": "movies-title-case-correct",
"INPUTFILE": "the.silence.of.the.lambs.1991.1080p.bluray.custom.plus.criterion.comm.dts.x264-mag.mkv",
"OUTPUTFILE": "/movies/The Silence of the Lambs 1991.mkv",
"NZBPO_MOVIESFORMAT": "%t %y.%ext"
},
{
"id": "movies-title-case-correct-_",
"INPUTFILE": "the.silence.of.the.lambs.1991.1080p.bluray.custom.plus.criterion.comm.dts.x264-mag.mkv",
"OUTPUTFILE": "/movies/The_Silence_of_the_Lambs 1991.mkv",
"NZBPO_MOVIESFORMAT": "%t_T %y.%ext"
"NZBPO_MOVIESFORMAT": "%_t %y.%ext"
},
{
"id": "movies-title-case-preserve",
"INPUTFILE": "the.silence.of.the.lambs.1991.1080p.bluray.custom.plus.criterion.comm.dts.x264-mag.mkv",
"OUTPUTFILE": "/movies/the silence of the lambs 1991.mkv",
"NZBPO_MOVIESFORMAT": "%tT %y.%ext"
},
{
"id": "mini-1",
Expand Down Expand Up @@ -119,16 +131,34 @@
"NZBPR__DNZB_EPISODENAME": "Let the Children the Childbearers Toil"
},
{
"id": "dated-1",
"id": "dated-deprecated-t-1",
"INPUTFILE": "The.Daily.Show.2013.06.27.Tom.Goldstein.HDTV.x264-FQM.mkv",
"OUTPUTFILE": "/dated/2013-06/The Daily Show - 2013-6-27.mkv",
"NZBPO_DATEDFORMAT": "%y-%0m/%t - %y-%m-%0d - %desc.%ext"
"NZBPO_DATEDFORMAT": "%y-%0m/%t - %y-%m-%0d.%ext"
},
{
"id": "dated-2",
"id": "dated-deprecated-t-2",
"INPUTFILE": "Real.Time.with.Bill.Maher.2014.10.31.720p.HDTV.x264-BATV.mkv",
"OUTPUTFILE": "/dated/2014-10/Real Time With Bill Maher - 2014-10-31.mkv",
"NZBPO_DATEDFORMAT": "%y-%0m/%t - %y-%m-%0d - %desc.%ext"
"NZBPO_DATEDFORMAT": "%y-%0m/%t - %y-%m-%0d.%ext"
},
{
"id": "dated-case-correct",
"INPUTFILE": "the.daily.show.2013.06.27.Tom.Goldstein.HDTV.x264-FQM.mkv",
"OUTPUTFILE": "/dated/2013-06/The Daily Show - 2013-6-27.mkv",
"NZBPO_DATEDFORMAT": "%y-%0m/%sn - %y-%m-%0d.%ext"
},
{
"id": "dated-case-correct-_",
"INPUTFILE": "Real.Time.With.Bill.Maher.2014.10.31.720p.HDTV.x264-BATV.mkv",
"OUTPUTFILE": "/dated/2014-10/Real_Time_With_Bill_Maher - 2014-10-31.mkv",
"NZBPO_DATEDFORMAT": "%y-%0m/%s_n - %y-%m-%0d.%ext"
},
{
"id": "dated-case-preserve",
"INPUTFILE": "the.daily.show.2013.06.27.Tom.Goldstein.HDTV.x264-FQM.mkv",
"OUTPUTFILE": "/dated/the daily show - 2013-6-27.mkv",
"NZBPO_DATEDFORMAT": "%sN - %y-%m-%0d.%ext"
},
{
"id": "multi-1",
Expand Down

0 comments on commit 314f9f4

Please sign in to comment.