cleanup keys/has_key usage

This commit is contained in:
j 2007-09-04 14:44:14 +00:00
parent b483c3b262
commit 52301794f7
4 changed files with 13 additions and 10 deletions

View file

@ -181,7 +181,7 @@ class Archive(SQLObject):
for f in files:
meta = oxdb_import.oxdb_file_stats(f)
f = f.replace(self.basePath, '')
if oxdb_files.has_key(f) and oxdb_files[f]['size'] == meta['size']:
if f in oxdb_files and oxdb_files[f]['size'] == meta['size']:
stats['skipped'] += 1
md5sum_on_disk.append(oxdb_files[f]['md5sum'])
else:

View file

@ -15,7 +15,7 @@ img_extension = 'jpg'
def srt2txt(srt, encoding = "utf-8"):
subtitles = srt2dict(srt, encoding)
txt = ''
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
txt += "%s\n\n" % subtitles["%s" % k]['text']
return txt.strip()
@ -49,7 +49,7 @@ def dict2srt(subtitles, encoding = "utf-8"):
into an srt file
'''
srt = ''
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
k = "%s" % k
srt += "%s\r\n%s --> %s\r\n%s\r\n\r\n" % (
k,
@ -91,7 +91,7 @@ def shift_subtitles(offset, offset_num, subtitles):
shifts a subtitle by offset, where offsest is a tuple (time, position)
'''
sdict = {}
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
ko = "%s" % (k + offset_num)
sdict[ko] = subtitles["%s" % k]
sdict[ko]['start'] = shift_time(offset, sdict[ko]['start'])
@ -105,7 +105,7 @@ def merge_subtitles(subtitles):
'''
subs = {}
offset = 0
for k in sorted(subtitles.keys()):
for k in sorted(subtitles):
sdict = srt2dict(subtitles[k]['txt'])
if offset:
sdict = shift_subtitles(offset, len(subs), sdict)
@ -121,7 +121,7 @@ def split_subtitle(subtitles, offset):
offset_time = time.strftime("%H:%M:%S", offset)
one = {}
two = {}
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
if subtitles['stop'] < offset_time:
one[k] = subtitle[k]
else:
@ -238,7 +238,7 @@ def extract_poster_still(movie_file, png_file, inpoint):
def extract_subtitles(movie_file, srt, img_folder, width=128, offset = 0, redo = False):
subtitles = srt2dict(srt)
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
timestamp = subtitles["%s" % k]['start']
extract_frame(movie_file, timestamp, img_folder, width, offset, redo)

View file

@ -91,7 +91,7 @@ def loadTimelineImageMap(movie):
length = int(movie.length / 1000)
imageMap ='<map name="timelineImageMap">'
for key in sorted([int(k) for k in s.keys()]):
for key in sorted([int(k) for k in s]):
sub = s["%s" % key]
start = int(round(time_str2msec(sub['start']) / 1000))
stop = int(round(time_str2msec(sub['stop']) / 1000))

View file

@ -32,7 +32,7 @@ def dict2srt(subtitles, encoding = "latin-1"):
into an srt file
'''
srt = ''
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
k = "%s" % k
srt += "%s\r\n%s --> %s\r\n%s\r\n\r\n" % (
k,
@ -72,7 +72,7 @@ def shift_subtitles(offset, offset_num, subtitles):
shifts a subtitle by offset
'''
sdict = {}
for k in sorted([int(k) for k in subtitles.keys()]):
for k in sorted([int(k) for k in subtitles]):
ko = "%s" % (k + offset_num)
sdict[ko] = subtitles["%s" % k]
sdict[ko]['start'] = shift_time(offset, sdict[ko]['start'])
@ -80,6 +80,9 @@ def shift_subtitles(offset, offset_num, subtitles):
return sdict
if __name__ == '__main__':
if len(sys.argv) != 3:
print """\nusage: %s movie.srt offset(in milliseconds)\n""" % sys.argv[0]
sys.exit(1)
srt = open(sys.argv[1]).read()
srtd = srt2dict(srt)
offset = int(sys.argv[2])