Skip to content

Commit a07f262

Browse files
committed
v0.1717 - timestamp fixes
1 parent 79ee2dc commit a07f262

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ If you just need to see the options and help, type:
220220
```
221221

222222
## Changes
223-
- v0.1717 - Timestamped output fixed in multi-hour videos
223+
- v0.1717 - **Timestamp formatting fixes & dynamic hour display**
224+
- Fixed a bug where `_timestamped.txt` files would incorrectly drop the hour from timestamps (e.g., a timestamp of `1:23:45` would appear as `[23:45]`).
225+
- Introduced dynamic timestamp formatting, which is on by default. Timestamps for moments under the one-hour mark are now shown in a shortened `[mm:ss]` format. Once a transcription passes the one-hour mark, timestamps automatically switch to the full `[hh:mm:ss]` format within the same file.
226+
- This behavior is controlled by the new `shorten_timestamps_under_one_hour` flag in `config.ini` and is set to `true` by default. Set it to `false` to force the full `[hh:mm:ss]` format for all timestamps.
227+
- Added a log message to confirm which formatting mode is active when generating the timestamped file.
224228
- v0.1716 - **NEW: Configurable per-domain yt-dlp arguments**
225229
- Added new `[YTDLPSettings]` config options:
226230
- `use_special_commands_for_domains = true` (set to `true` to enable)

config/config.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ keepaudiofiles = False
2828
sendasfiles = True
2929
# Send as timestamped .txt files separately if `sendasfiles` is set to true
3030
send_timestamped_txt = true
31+
# If true, timestamps for moments under one hour will be shortened (e.g., [59:59] instead of [00:59:59]).
32+
shorten_timestamps_under_one_hour = true
3133
# Send the transcriptions as message(s) in Telegram
3234
sendasmessages = True
3335

src/config_loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def get_transcription_settings(cls):
4848
'keep_audio_files': config.getboolean('TranscriptionSettings', 'keepaudiofiles', fallback=False),
4949
'send_as_files': config.getboolean('TranscriptionSettings', 'sendasfiles', fallback=True),
5050
'send_timestamped_txt': config.getboolean('TranscriptionSettings', 'send_timestamped_txt', fallback=False), # ADDED, default to False
51+
'shorten_timestamps_under_one_hour': config.getboolean('TranscriptionSettings', 'shorten_timestamps_under_one_hour', fallback=True), # ADDED THIS LINE in v0.1717
5152
'send_as_messages': config.getboolean('TranscriptionSettings', 'sendasmessages', fallback=False),
5253
}
5354
logger.info(f"Loaded transcription settings: {transcription_settings}")

src/transcription_handler.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,14 +1118,26 @@ def format_srt_time_to_timestamp_prefix(time_str: str) -> str:
11181118
except Exception as e:
11191119
logger.error(f"Error formatting SRT time '{time_str}': {e}")
11201120
return f"[{time_str.split(',')[0]}]" # Return a basic timestamp as fallback
1121-
1122-
# Helper function to create timestamped TXT from SRT (as provided before)
1121+
1122+
# Helper function to create timestamped TXT from SRT
11231123
def create_timestamped_txt_from_srt(srt_path: str, output_txt_path: str, header_content: str = "") -> bool:
11241124
try:
1125+
# Load the relevant config setting
1126+
settings = ConfigLoader.get_transcription_settings()
1127+
should_shorten = settings.get('shorten_timestamps_under_one_hour', True)
1128+
1129+
# --- NEW LOGGING BLOCK ---
1130+
if should_shorten:
1131+
logger.info("Timestamp formatting: Shortening timestamps for entries under one hour (e.g., [mm:ss]).")
1132+
else:
1133+
logger.info("Timestamp formatting: Using full hh:mm:ss format for all entries as per configuration.")
1134+
# --- END OF NEW LOGGING BLOCK ---
1135+
11251136
with open(srt_path, 'r', encoding='utf-8') as srt_file, \
11261137
open(output_txt_path, 'w', encoding='utf-8') as txt_file:
1138+
11271139
if header_content:
1128-
txt_file.write(header_content) # header_content should already have \n\n
1140+
txt_file.write(header_content)
11291141

11301142
lines = srt_file.read().splitlines()
11311143
i = 0
@@ -1134,24 +1146,37 @@ def create_timestamped_txt_from_srt(srt_path: str, output_txt_path: str, header_
11341146
if not line:
11351147
i += 1
11361148
continue
1149+
11371150
try:
1151+
# Check if the line is a sequence number
11381152
int(line)
11391153
if i + 1 < len(lines) and "-->" in lines[i+1]:
11401154
time_line = lines[i+1].strip()
11411155
start_time_str = time_line.split(" --> ")[0]
1142-
timestamp_prefix = format_srt_time_to_timestamp_prefix(start_time_str)
1156+
1157+
# Get the full timestamp, which will be [hh:mm:ss] if hours are present
1158+
full_timestamp = format_srt_time_to_timestamp_prefix(start_time_str)
1159+
final_timestamp = full_timestamp
1160+
1161+
# If the setting is on, shorten any timestamp that is under the 1-hour mark
1162+
if should_shorten and full_timestamp.startswith('[00:'):
1163+
final_timestamp = '[' + full_timestamp[4:] # Strips '[00:' to leave '[mm:ss]'
1164+
11431165
i += 2
11441166
text_block = []
11451167
while i < len(lines) and lines[i].strip():
11461168
text_block.append(lines[i].strip())
11471169
i += 1
1170+
11481171
if text_block:
11491172
full_text = " ".join(text_block)
1150-
txt_file.write(f"{timestamp_prefix} {full_text}\n")
1173+
txt_file.write(f"{final_timestamp} {full_text}\n")
11511174
continue
11521175
except ValueError:
1176+
# Not a sequence number, so we move on
11531177
pass
11541178
i += 1
1179+
11551180
logger.info(f"Successfully created timestamped TXT: {output_txt_path}")
11561181
return True
11571182
except FileNotFoundError:

0 commit comments

Comments
 (0)