Last active
October 5, 2021 12:57
-
-
Save Forceflow/8d5b5c50ff8e5dfe2e84092deebe5c4b to your computer and use it in GitHub Desktop.
CSV to timestamped Souncloud URLs for Nerdland Podcast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a script that takes Audobe Audition CSV file output from a project and combines them with a Souncloud URL to generate a list of clickable topic - timestamp entries | |
# Jeroen Baert - jeroen [at] nerdland [dot] | |
from datetime import datetime, timedelta | |
import csv | |
import sys | |
# Import CSV file as a list-of-lists | |
def import_csv(filename): | |
with open(filename) as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter='\t') | |
csv_list = list(csv_reader) | |
return csv_list | |
# Convert Adobe Audition time strings to list of hour, minute second | |
def to_timestamp(time): | |
# find out if the input contains hours or not by counting the ":" | |
if time.count(":") == 2: | |
t = datetime.strptime(time, "%H:%M:%S.%f") | |
else: | |
t = datetime.strptime(time, "%M:%S.%f") | |
timestamp = [t.hour, t.minute, t.second] | |
return timestamp | |
# Create soundcloud timestamped url from base url and list with H, M, S | |
def to_soundcloud_href(url, timestamp): | |
timestamp_parameter = "#t=" + f'{timestamp[0]:02d}' + ":" + f'{timestamp[1]:02d}' + ":" + f'{timestamp[2]:02d}' | |
link = url + timestamp_parameter | |
href = "<a target=\"_blank\" href=\"" + link + "\">" + f'{timestamp[0]:02d}' + ":" + f'{timestamp[1]:02d}' + ":" + f'{timestamp[2]:02d}' + "</a>" | |
return href | |
# Convert list of processed CSV markers to HTML <ul> | |
def to_html(sc_url, marker_list): | |
html_output = ["<ul>"] | |
for i in marker_list: | |
topic = i[0].strip() | |
href = to_soundcloud_href(sc_url,i[1]) | |
html_output.append("<li>" + topic + " - " + href + "</li>") | |
html_output.append("</ul>") | |
return html_output | |
def main(): | |
if (len(sys.argv) != 3): | |
print("ERROR: I need two arguments: <path to csv file> and <base soundcloud URL>") | |
return | |
file = sys.argv[1] | |
url = sys.argv[2] | |
# import CSV output from Adobe Audition | |
marker_list = import_csv(file) | |
# get rid of first line (columns) | |
marker_list = marker_list[1:] | |
# only retain first two items per line (item name and timestamp) | |
processed_marker_list = [] | |
for i in marker_list: | |
i[1] = to_timestamp(i[1]) | |
processed_marker_list.append(i[0:2]) | |
html_list = to_html(url, processed_marker_list) | |
for i in html_list: | |
print(i) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment