Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help on Flagging Timestamps
#1
Bug 
Hi, I was trying to flag timestamps that increment but 1,but cannot be more than 3 matches and not '0:00:00' or '0:00:01', lastly flag the highest out of 3 or 2 matches.

Any ideas on how solve this issue would be amazing Smile.

This is what I have so far:

This is the TS class:
from datetime import timedelta

class TS():
    '''This class + and - timestamps hr:min:sec'''

    def __init__(self, input_TS):
        self.input_TS = str(input_TS)

        if input_TS == None:
            input_TS = "0:00:00"
        hours, minute, seconds = input_TS.split(":")
        self.hours = int(hours)
        self.minute = int(minute)
        self.seconds = int(seconds)
        self.TS = timedelta(hours=self.hours,
                            minutes=self.minute,
                            seconds=self.seconds)

    def __add__(self, other):
        return str(self.TS + other.TS)

    def __sub__(self, other):
        return str(self.TS - other.TS)

    def __str__(self):
        return self.input_TS

    def __repr__(self):
        return repr(self.TS)

if __name__ == '__main__':
    print("TS.py File")
Main Script:
from TS import TS

raw_TS_list = ['0:00:00', '0:00:01', '0:02:25', '0:02:26', '0:02:27',
 '0:02:28', '0:02:29', '0:02:30', '0:02:31', '0:11:39',
 '0:11:40', '0:22:10', '0:22:11', '0:35:06', '0:35:07',
 '0:35:08', '0:43:12', '0:43:18', '0:43:20', '0:43:22',
 '0:43:23', '0:43:26', '0:45:28', '0:45:29', '0:45:57',
 '0:45:58']

def remove_duplicates(input_list):
    print('Removing Duplicates...')
    cleaned_list = list(set(input_list))
    return sorted(cleaned_list)

def ts_parsing(input_list):
    not_a_TS_list = {'0:00:00', '0:00:01'}
    ts_old  = None

    for ts in remove_duplicates(input_list):
        if ts not in not_a_TS_list:
            if TS(ts) - TS(ts_old) == "0:00:01":
                    print(f"most likely: {repr(ts)}")
            else:
                print(f"{repr(ts_old)}")
        ts_old = ts

        print(repr(ts))
This is the output:
Output:
'0:00:00' '0:00:01' '0:00:01' '0:02:25' most likely: '0:02:26' '0:02:26' most likely: '0:02:27' '0:02:27' most likely: '0:02:28' '0:02:28' most likely: '0:02:29' '0:02:29' most likely: '0:02:30' '0:02:30' most likely: '0:02:31' '0:02:31' '0:02:31' '0:11:39' most likely: '0:11:40' '0:11:40' '0:11:40' '0:22:10' most likely: '0:22:11' '0:22:11' '0:22:11' '0:35:06' most likely: '0:35:07' '0:35:07' most likely: '0:35:08' '0:35:08' '0:35:08' '0:43:12' '0:43:12' '0:43:18' '0:43:18' '0:43:20' '0:43:20' '0:43:22' most likely: '0:43:23' '0:43:23' '0:43:23' '0:43:26' '0:43:26' '0:45:28' most likely: '0:45:29' '0:45:29' '0:45:29' '0:45:57' most likely: '0:45:58' '0:45:58'
This what it should look like,,
Output:
Removing Duplicates... '0:02:25' '0:02:26' '0:02:27' '0:02:28' '0:02:29' '0:02:30' '0:02:31' '0:11:39' '0:11:40' '0:22:10' most likely: '0:22:11' '0:35:06' '0:35:07' most likely: '0:35:08' '0:43:12' '0:43:18' '0:43:20' '0:43:22' most likely: '0:43:23' '0:43:26' '0:45:28' most likely: '0:45:29' '0:45:57' most likely: '0:45:58'
Reply
#2
I don't think your intent is clearly stated.

Why should 0:02:26 not appear as a "most likely"?
Reply
#3
(Oct-26-2020, 10:19 PM)bowlofred Wrote: I don't think your intent is clearly stated.

Why should 0:02:26 not appear as a "most likely"?

It shouldn't appear because the number of matches should be >= 3.
Why 3?, because this function is going to be used in finding chapter timestamps
and 3 or less seconds is usually chapter timestamps.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find tags using specific text (timestamps) in a url? q988988 1 1,369 Mar-08-2022, 08:09 AM
Last Post: buran
  Speech Recognition with timestamps DeanAseraf1 3 6,565 Jun-27-2021, 06:58 PM
Last Post: gh_ad
  Removing timestamps from transcriptions jehoshua 5 4,738 Dec-09-2018, 09:27 AM
Last Post: jehoshua
  How to compare timestamps in python asad 2 9,099 Oct-24-2018, 03:56 AM
Last Post: asad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020