This will make it easier to integrate with statically typed systems like
databases. It already simplifies the duration-caching machinery.
def _duration(me, title, start_chapter, end_chapter):
return -1
def _duration(me, title, start_chapter, end_chapter):
return -1
- def url_and_duration(me, title = None,
- start_chapter = None, end_chapter = None):
- if title == "-":
+
+ def url_and_duration(me, title = -1, start_chapter = -1, end_chapter = -1):
+ if title == -1:
if me.TITLEP: raise ExpectedError("missing title number")
if me.TITLEP: raise ExpectedError("missing title number")
- if start_chapter is not None or end_chapter is not None:
+ if start_chapter != -1 or end_chapter != -1:
raise ExpectedError("can't specify chapter without title")
suffix = ""
elif not me.TITLEP:
raise ExpectedError("can't specify title with `%s'" % me.fn)
raise ExpectedError("can't specify chapter without title")
suffix = ""
elif not me.TITLEP:
raise ExpectedError("can't specify title with `%s'" % me.fn)
- elif start_chapter is None:
- if end_chapter is not None:
+ elif start_chapter == -1:
+ if end_chapter != -1:
raise ExpectedError("can't specify end chapter without start chapter")
suffix = "#%d" % title
elif not me.CHAPTERP:
raise ExpectedError("can't specify chapter with `%s'" % me.fn)
raise ExpectedError("can't specify end chapter without start chapter")
suffix = "#%d" % title
elif not me.CHAPTERP:
raise ExpectedError("can't specify chapter with `%s'" % me.fn)
- elif end_chapter is None:
+ elif end_chapter == -1:
suffix = "#%d:%d" % (title, start_chapter)
else:
suffix = "#%d:%d-%d:%d" % (title, start_chapter, title, end_chapter - 1)
suffix = "#%d:%d" % (title, start_chapter)
else:
suffix = "#%d:%d-%d:%d" % (title, start_chapter, title, end_chapter - 1)
SELECT device, inode, size, mtime, duration FROM duration
WHERE path = ? AND title = ? AND
start_chapter = ? AND end_chapter = ?
SELECT device, inode, size, mtime, duration FROM duration
WHERE path = ? AND title = ? AND
start_chapter = ? AND end_chapter = ?
- """, [me.fn, title, start_chapter is None and -1 or start_chapter,
- end_chapter is None and -1 or end_chapter])
+ """, [me.fn, title, start_chapter, end_chapter])
row = c.fetchone()
foundp = False
if row is None:
row = c.fetchone()
foundp = False
if row is None:
(path, title, start_chapter, end_chapter,
device, inode, size, mtime, duration)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
(path, title, start_chapter, end_chapter,
device, inode, size, mtime, duration)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
- """, [me.fn, title, start_chapter is None and -1 or start_chapter,
- end_chapter is None and -1 or end_chapter,
+ """, [me.fn, title, start_chapter, end_chapter,
st.st_dev, st.st_ino, st.st_size, st.st_mtime,
duration])
else:
st.st_dev, st.st_ino, st.st_size, st.st_mtime,
duration])
else:
SET device = ?, inode = ?, size = ?, mtime = ?, duration = ?
WHERE path = ? AND title = ? AND
start_chapter = ? AND end_chapter = ?
SET device = ?, inode = ?, size = ?, mtime = ?, duration = ?
WHERE path = ? AND title = ? AND
start_chapter = ? AND end_chapter = ?
- """, [st.st_dev, st.st_dev, st.st_size, st.st_mtime, duration,
- me.fn, title, start_chapter is None and -1 or start_chapter,
- end_chapter is None and -1 or end_chapter])
+ """, [st.st_dev, st.st_dev, st.st_size, st.st_mtime, duration,
+ me.fn, title, start_chapter, end_chapter])
- if end_chapter is not None:
keys = [(title, ch) for ch in range(start_chapter, end_chapter)]
set = me.used_chapters
else:
keys, set = [title], me.used_titles
for k in keys:
if k in set:
keys = [(title, ch) for ch in range(start_chapter, end_chapter)]
set = me.used_chapters
else:
keys, set = [title], me.used_titles
for k in keys:
if k in set:
raise ExpectedError("`%s' already used" % me.fn)
raise ExpectedError("`%s' already used" % me.fn)
- elif end_chapter is None:
+ elif end_chapter == -1:
raise ExpectedError("`%s' title %d already used" % (me.fn, title))
else:
raise ExpectedError("`%s' title %d chapter %d already used" %
(me.fn, title, k[1]))
raise ExpectedError("`%s' title %d already used" % (me.fn, title))
else:
raise ExpectedError("`%s' title %d chapter %d already used" %
(me.fn, title, k[1]))
- if end_chapter is not None:
for ch in range(start_chapter, end_chapter):
me.used_chapters.add((title, ch))
return me.PREFIX + ROOT + urlencode(me.fn) + suffix, duration
for ch in range(start_chapter, end_chapter):
me.used_chapters.add((title, ch))
return me.PREFIX + ROOT + urlencode(me.fn) + suffix, duration
if not 1 <= title <= ntitle:
raise ExpectedError("bad title %d for `%s': must be in 1 .. %d" %
(title, me.fn, ntitle))
if not 1 <= title <= ntitle:
raise ExpectedError("bad title %d for `%s': must be in 1 .. %d" %
(title, me.fn, ntitle))
- if start_chapter is None:
+ if start_chapter == -1:
durq = "duration:%d" % title
else:
nch = int(program_output(["dvd-info", path, "chapters:%d" % title]))
durq = "duration:%d" % title
else:
nch = int(program_output(["dvd-info", path, "chapters:%d" % title]))
- if end_chapter is None: end_chapter = nch
+ if end_chapter == -1: end_chapter = nch
else: end_chapter -= 1
if not 1 <= start_chapter <= end_chapter <= nch:
raise ExpectedError("bad chapter range %d .. %d for `%s' title %d: "
else: end_chapter -= 1
if not 1 <= start_chapter <= end_chapter <= nch:
raise ExpectedError("bad chapter range %d .. %d for `%s' title %d: "
class Episode (object):
def __init__(me, season, i, neps, title, src, series_title_p = True,
class Episode (object):
def __init__(me, season, i, neps, title, src, series_title_p = True,
- tno = None, startch = None, endch = None):
+ tno = -1, startch = -1, endch = -1):
me.season = season
me.i, me.neps, me.title = i, neps, title
me.chapters = []
me.season = season
me.i, me.neps, me.title = i, neps, title
me.chapters = []
def _process_episode(me, ww):
opts = ww.nextword(); check(opts is not None, "missing title/options")
def _process_episode(me, ww):
opts = ww.nextword(); check(opts is not None, "missing title/options")
- ti = None; sname = None; neps = 1; epi = None; loch = hich = None
+ ti = -1; sname = None; neps = 1; epi = None; loch = hich = -1
explen, expvar, explicitlen = me._explen, me._expvar, False
series_title_p = True
for k, v in me._keyvals(opts):
if k is None:
if v.isdigit(): ti = int(v)
explen, expvar, explicitlen = me._explen, me._expvar, False
series_title_p = True
for k, v in me._keyvals(opts):
if k is None:
if v.isdigit(): ti = int(v)
- elif v == "-": ti = "-"
else: sname = v
elif k == "s": sname = v
elif k == "n": neps = getint(v)
else: sname = v
elif k == "s": sname = v
elif k == "n": neps = getint(v)
explicitlen = True
elif k == "ch":
try: sep = v.index("-")
explicitlen = True
elif k == "ch":
try: sep = v.index("-")
- except ValueError: loch, hich = getint(v), None
+ except ValueError: loch, hich = getint(v), -1
else: loch, hich = getint(v[:sep]), getint(v[sep + 1:]) + 1
else: raise ExpectedError("unknown episode option `%s'" % k)
check(ti is not None, "missing title number")
else: loch, hich = getint(v[:sep]), getint(v[sep + 1:]) + 1
else: raise ExpectedError("unknown episode option `%s'" % k)
check(ti is not None, "missing title number")
season = series.ensure_season()
if epi is None: epi = season.ep_i
season = series.ensure_season()
if epi is None: epi = season.ep_i
check(season.implicitp or season.i is None,
"audio source, but explicit non-movie season")
dir = lookup(me._audirs, series.name,
check(season.implicitp or season.i is None,
"audio source, but explicit non-movie season")
dir = lookup(me._audirs, series.name,