Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WheheoHu/issue9 #12

Merged
merged 12 commits into from
Oct 19, 2024
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
dftt_timecode.egg-info
.pytest_cache
.DS_Store
playground.ipynb
20 changes: 20 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,23 @@ First Public Release.
This bug will cause error when using strings like `'00:00:27:183'` to initilize a dlp timecode object.


V0.0.13 changelog
## V0.0.13
重构 Refactor:
- 使用`f-string`处理字符串格式输出

Handling string format output using `f-string`

- 重构时间码输出函数,减少代码重复

Refactor the time code output function to reduce code duplication

添加 Add:
- 添加`get_audio_sample_count` 方法用于正确输出TC时间戳下的音频采样数, 解决issue [#9](https://github.com/OwenYou/dftt_timecode/issues/9)

Add `get_audio_sample_count` method for correctly outputting the count of audio samples at TC timestamps,solve issue [#9](https://github.com/OwenYou/dftt_timecode/issues/9)

弃用 Deprecate:
- 使用`functools.singledispatchmethod` 代替 `dispatch.InstanceMethodDispatch`

Use`functools.singledispatchmethod` instead of `dispatch.InstanceMethodDispatch`
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,4 @@ int(tc_a)
#864000
```

#TODO TimeRange readme
5 changes: 3 additions & 2 deletions dftt_timecode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = 'dftt_timecode'
__author__ = 'You Ziyuan'
__version__ = '0.0.12'
__version__ = '0.0.13'

from dftt_timecode.core import DfttTimecode
from dftt_timecode.core.dftt_timecode import DfttTimecode
from dftt_timecode.core.dftt_timerange import DfttTimeRange
313 changes: 138 additions & 175 deletions dftt_timecode/core.py → dftt_timecode/core/dftt_timecode.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import setuptools

import dftt_timecode as package
with open("README.md", "r",encoding='UTF-8') as fh:
long_description = fh.read()

setuptools.setup(
name="dftt_timecode",
version="0.0.12",
name=package.name,
version=package.__version__,
author="You Ziyuan",
author_email="[email protected]",
description="Timecode library for film and TV industry, supports HFR and a bunch of cool features",
Expand Down
22 changes: 18 additions & 4 deletions test/test_dftt_timecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ def test_auto_type(timecode_value, timecode_type, fps, drop_frame, strict, resul
"timecode_value, timecode_type, fps, drop_frame, strict",
[
('01:00:00:23', 'smpte', 20, False, True),
('00:01:00;00', 'smpte', 23.97, False, True),
],
ids=['smpte', 'smpte_df']
ids=['smpte']
)
def test_invalid_timecode(timecode_value, timecode_type, fps, drop_frame, strict):
from dftt_timecode.error import DFTTTimecodeValueError
Expand Down Expand Up @@ -182,8 +181,11 @@ def test_set_strict(set_strict_data):

@pytest.mark.parametrize(argnames="timecode_value, timecode_type, fps, drop_frame, strict,output_smpte,output_frame,output_time,output_srt,output_fcpx,output_ffmpeg",
argvalues=[('00:00:01:00', 'auto', 24, False, True, '00:00:01:00',
'24', '1.0', '00:00:01,000', '1s', '00:00:01.00'), ],
ids=['smpte'])
'24', '1.0', '00:00:01,000', '1s', '00:00:01.00'),
('00:10:00;00', 'auto', 29.97, True, True, '00:10:00;00',
'17982', '600.0', '00:10:00,000', '600s', '00:10:00.00'),
],
ids=['NDF','DF'])
def test_timecode_output(timecode_value, timecode_type, fps, drop_frame, strict, output_smpte, output_frame, output_time, output_srt, output_fcpx, output_ffmpeg):
tc = TC(timecode_value, timecode_type, fps, drop_frame, strict)
assert tc.timecode_output() == timecode_value
Expand Down Expand Up @@ -554,3 +556,15 @@ def test_int(tc_value,xvalue):
tc=TC(*tc_value)
assert int(tc) == xvalue


@pytest.mark.parametrize(
argnames="tc_value,sample_rate,xvalue",
argvalues=[(('00:00:01:00', 'auto', 24, False, True),48000,48000),
(('00:00:01:01', 'auto', 24, False, True),48000,50000),
(('00:00:01:01', 'auto', 24, False, True),44100,45937),
],
ids=['ideal','single_frame','24fps_44100']
)
def test_audio_sample_count(tc_value,sample_rate,xvalue):
tc=TC(*tc_value)
assert tc.get_audio_sample_count(sample_rate) == xvalue
88 changes: 88 additions & 0 deletions test/test_dftt_timerange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from dftt_timecode import DfttTimeRange as TC_Range
from dftt_timecode import DfttTimecode as TC


import pytest


@pytest.mark.parametrize(
argnames="_start_tc,_end_tc,_fps",
argvalues=[
(TC('00:00:00:00','auto',fps=24),TC('00:00:00:20','auto',fps=24),24),
(TC('00:00:00:00','auto',fps=24),1.0,24),
(1.0,TC('00:00:02:20','auto',fps=24),24),
(1.0,50,24)
],
ids=['TC_TC','TC_Other','Other_TC','Other_Other'])
def test_init(_start_tc,_end_tc,_fps):
tc_range=TC_Range(start_tc=_start_tc,end_tc=_end_tc,fps=_fps)
assert isinstance(tc_range,TC_Range)
for tc in tc_range:
assert isinstance(tc,TC)



@pytest.mark.parametrize(
'range_value,x_duration_value',
[
({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':TC('00:00:01:00','auto',fps=24)},1),
({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':TC('00:00:01:00','auto',fps=24),'forward':False},86399),
({'start_tc':TC('23:59:59:00','auto',fps=24),'end_tc':TC('00:00:01:00','auto',fps=24)},2),
({'start_tc':TC('00:00:01:00','auto',fps=24),'end_tc':TC('23:59:59:00','auto',fps=24),'forward':False},2),

({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':2.0},2),
({'start_tc':TC('00:00:02:00','auto',fps=24),'end_tc':0.0,'forward':False},2),
({'start_tc':TC('23:59:59:00','auto',fps=24),'end_tc':'00:00:00:00'},1),
({'start_tc':TC('00:00:01:00','auto',fps=24),'end_tc':'23:59:59:00','forward':False},2),

({'start_tc':'2s' ,'end_tc':TC('4.0','auto',fps=24)},2),
({'start_tc':2.0 ,'end_tc':TC('00:00:00:00','auto',fps=24),'forward':False},2),
({'start_tc':'86399s' ,'end_tc':TC('00:00:00:00','auto',fps=24)},1),
({'start_tc':'00:00:01:00' ,'end_tc':TC('23:59:59:00','auto',fps=24),'forward':False},2),

({'start_tc':'2s' ,'end_tc':4.0},2),
({'start_tc':2.0 ,'end_tc':0,'forward':False},2),
({'start_tc':'86399s' ,'end_tc':0},1),
({'start_tc':'00:00:01:00' ,'end_tc':'23:59:59:00','forward':False},2),

],
ids=['TC_TC','TC_TC_Reverse','TC_TC_Midnight','TC_TC_Reverse_Mignight',
'TC_Other','TC_Other_Reverse','TC_Other_Midnight','TC_Other_Reverse_Mignight',
'Other_TC','Other_TC_Reverse','Other_TC_Midnight','Other_TC_Reverse_Mignight',
'Other_Other','Other_Other_Reverse','Other_Other_Midnight','Other_Other_Reverse_Mignight',
])
def test_duration(range_value,x_duration_value):
tc_range=TC_Range(**range_value)
assert tc_range.duration == x_duration_value


@pytest.mark.parametrize(
argnames="range_value,x_framecount_value",
argvalues=[
({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':TC('00:00:01:01','auto',fps=24)},25),
({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':TC('00:00:00:01','auto',fps=24),'forward':False},2073599),
({'start_tc':TC('23:59:59:00','auto',fps=24),'end_tc':TC('00:00:00:01','auto',fps=24)},2),
({'start_tc':TC('00:00:01:00','auto',fps=24),'end_tc':TC('23:59:59:00','auto',fps=24),'forward':False},2),

({'start_tc':TC('00:00:00:00','auto',fps=24),'end_tc':2.0},2),
({'start_tc':TC('00:00:02:00','auto',fps=24),'end_tc':0.0,'forward':False},2),
({'start_tc':TC('23:59:59:00','auto',fps=24),'end_tc':'00:00:00:00'},1),
({'start_tc':TC('00:00:01:00','auto',fps=24),'end_tc':'23:59:59:00','forward':False},2),

({'start_tc':'2s' ,'end_tc':TC('4.0','auto',fps=24)},2),
({'start_tc':2.0 ,'end_tc':TC('00:00:00:00','auto',fps=24),'forward':False},2),
({'start_tc':'86399s' ,'end_tc':TC('00:00:00:00','auto',fps=24)},1),
({'start_tc':'00:00:01:00' ,'end_tc':TC('23:59:59:00','auto',fps=24),'forward':False},2),

({'start_tc':'2s' ,'end_tc':4.0},2),
({'start_tc':2.0 ,'end_tc':0,'forward':False},2),
({'start_tc':'86399s' ,'end_tc':0},1),
({'start_tc':'00:00:01:00' ,'end_tc':'23:59:59:00','forward':False},2),
],
ids=['TC_TC','TC_TC_Reverse','TC_TC_Midnight','TC_TC_Reverse_Mignight',
'TC_Other','TC_Other_Reverse','TC_Other_Midnight','TC_Other_Reverse_Mignight',
'Other_TC','Other_TC_Reverse','Other_TC_Midnight','Other_TC_Reverse_Mignight',
'Other_Other','Other_Other_Reverse','Other_Other_Midnight','Other_Other_Reverse_Mignight',])
def test_framecount(range_value,x_framecount_value):
tc_range=TC_Range(**range_value)
assert tc_range.framecount == x_framecount_value