import re, sys, csv # From [itertools recipes](https://docs.python.org/3/library/itertools.html#itertools-recipes) def grouper (iterable, n): args = [iter(iterable)] * n return zip(*args) w = csv.writer(sys.stdout) w.writerow(["url","start", "text"]) text = sys.stdin.read() items = list(re.split(f"((https?://\S+?)#t=(\S+))", text)) for url, baseurl, timecode, text in grouper(items[1:], 4): w.writerow((baseurl, timecode, text))