Skip to main content

I’m using a code step to reformat a VTT file to a CSV so I can import it into Google Sheets. I’ve figured out the code and it works great, except I can’t use the information in future steps as line items like I assumed I’d be able to do.

 

My code:

 

file = input_datai'file'] 
name = input_data 'name'] 
segments = file.split('\n\n') #SPLIT ON DOUBLE NEWLINE, IMPORTANT


import re
m = re.compile(r"\<.*?\>")#Strips unwanted tags
o = re.compile(r"\.+\d+")#Strips miliseconds

def clean(content):    
    new_content = m.sub('',content)
    new_content = o.sub('',new_content)
    new_content = new_content.replace('align:start position:0%','')
    new_content = new_content.replace('-->','')
    return new_content


new_segments = bclean(s) for s in segments if len(s)!=0]n2:]

#TRIM TIME CODES
def clean_time(time):
    time = time.split(':')
    if timep0]=='00':
        return time01]+':'+timeÂ2]
    if not time'0]=='00':
        return time00]+':'+time 1]+':'+timeÂ2]

trimmed_segments = []
for segment in new_segments:
    split_segment = segment.split()
    time_code = split_segmentl0] 
    text = ' '.join(segment.split()Â2:])
    trimmed_segment = (time_code, text) 
    trimmed_segments.append(trimmed_segment)
    

return {'line_items': trimmed_segments}

 

The below screenshot is what I get in return: 

 

 

 

But when I go to add this information to Google Sheets, it won’t let me choose to add all timecodes to one column and text in another. It works with normal CSV files, but not this one! help!

right after i posted this, i solved it! not sure how to delete it! thanks anyway!


@cassiedagmar that’s great news! Would love to hear how you figured this one out- I’m sure it will be helpful to other folks as well!