Merge pull request #4 from HaltCatchFire/fix-starting-in-segment

Add logic for when video starts in a segment
This commit is contained in:
David
2022-02-22 00:07:28 +01:00
committed by GitHub

18
main.py
View File

@@ -91,14 +91,16 @@ async def get_segments(vid_id, web_session, categories = ["sponsor"]):
async def time_to_segment(segments, position, rc): async def time_to_segment(segments, position, rc):
future_segments = [] for segment in segments:
for i in segments: if position < 2 and (position >= segment[0] and position < segment[1]):
if i[0] > position: next_segment = [position, segment[1]]
future_segments.append(i) break
next_segement = future_segments[0] if segment[0] > position:
time_to_next = next_segement[0] - position next_segment = segment
await skip(time_to_next, next_segement[1], rc) break
time_to_next = next_segment[0] - position
await skip(time_to_next, next_segment[1], rc)
async def skip(time_to, position, rc): async def skip(time_to, position, rc):
await asyncio.sleep(time_to) await asyncio.sleep(time_to)
await rc.set_position(position) await rc.set_position(position)