0

I am trying to execute the codes from this link https://zulko.github.io/blog/2014/06/21/some-more-videogreping-with-python/

import re # module for regular expressions

def convert_time(timestring):
    """ Converts a string into seconds """
    nums = map(float, re.findall(r'\d+', timestring))
    return 3600*nums[0] + 60*nums[1] + nums[2] + nums[3]/1000

with open("Identity_2003.srt") as f:
    lines = f.readlines()

times_texts = []
current_times , current_text = None, ""
for line in lines:
    times = re.findall("[0-9]*:[0-9]*:[0-9]*,[0-9]*", line)
    if times != []:
        current_times = map(convert_time, times)
    elif line == '\n':
        times_texts.append((current_times, current_text))
        current_times, current_text = None, ""
    elif current_times is not None:
        current_text = current_text + line.replace("\n"," ")

print (times_texts)


from collections import Counter
whole_text = " ".join([text for (time, text) in times_texts])
all_words = re.findall("\w+", whole_text)
counter = Counter([w.lower() for w in all_words if len(w)>5])
print (counter.most_common(10))

cuts = [times for (times,text) in times_texts
        if (re.findall("please",text) != [])]



from moviepy.editor import VideoFileClip, concatenate

video = VideoFileClip("Identity_2003.mp4")

def assemble_cuts(cuts, outputfile):
    """ Concatenate cuts and generate a video file. """
    final = concatenate([video.subclip(start, end)
                         for (start,end) in cuts])
    final.to_videofile(outputfile)

assemble_cuts(cuts, "please.mp4")

But the assemble_cuts function is not working . I am using python3.x

it is giving me an error

Traceback (most recent call last):

  File "<ipython-input-64-939ee3d73a4a>", line 47, in <module>
    assemble_cuts(cuts, "please.mp4")

  File "<ipython-input-64-939ee3d73a4a>", line 44, in assemble_cuts
    for (start,end) in cuts])

  File "<ipython-input-64-939ee3d73a4a>", line 43, in <listcomp>
    final = concatenate([video.subclip(start, end)

  File "<ipython-input-64-939ee3d73a4a>", line 6, in convert_time
    return 3600*nums[0] + 60*nums[1] + nums[2] + nums[3]/1000

TypeError: 'map' object is not subscriptable

Could you help me to solve this problem?

VGB
  • 447
  • 6
  • 21

1 Answers1

0

Fixed it.

def convert_time(timestring):
    """ Converts a string into seconds """
    nums = list(map(float, re.findall(r'\d+', timestring)))
    return 3600*nums[0] + 60*nums[1] + nums[2] + nums[3]/1000
Dionys
  • 3,083
  • 1
  • 19
  • 28
VGB
  • 447
  • 6
  • 21