Skip to content

Instantly share code, notes, and snippets.

@Jawschamp
Last active October 28, 2022 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jawschamp/76b2c1906e057383f771d4a139946233 to your computer and use it in GitHub Desktop.
Save Jawschamp/76b2c1906e057383f771d4a139946233 to your computer and use it in GitHub Desktop.
Simple YouTube timestamp converter for Python (simple thing I needed for a project) | Right now it only supports 4 digit numbers: (mm:ss)
class TimestampConverter:
def __init__(self, time_):
self.time_ = time_
self.len_dig = len(self.time_)
self.time_array = []
if self.len_dig == 4:
self.time_array.append(self.time_[:2])
self.time_array.append(self.time_[2:])
first = int(self.time_array[0]) * 60
second = int(self.time_array[1])
first_math = first + second
print(f"Number of digits: [{self.len_dig}] "
f"Seconds in minutes: [{int(self.time_array[0]) * 60}] "
f"and in seconds [{int(self.time_array[1])}] "
f"With the final results being [{first_math}]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment