Last active
October 28, 2022 07:03
-
-
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)
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
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