Skip to content

Commit

Permalink
Fix times on podcast RSS chapters (#390)
Browse files Browse the repository at this point in the history
* Fix times on podcast RSS chapters
they are milliseconds, not seconds
closes #389

* Fixed automated linting issues
  • Loading branch information
Apreche authored Oct 23, 2023
1 parent 9b951ac commit bcf7e83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion podcasts/feedgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def add_item_elements(self, handler: xmlutils.SimplerXMLGenerator, item: Dict[st
)
for chapter in chapters:
chapter_attrs = {}
start_time = utils.seconds_to_timespan(chapter.start_time)
start_time = utils.milliseconds_to_timespan(chapter.start_time)
chapter_attrs["start"] = start_time
chapter_attrs["title"] = chapter.title
url = getattr(chapter, "url", None)
Expand Down
20 changes: 20 additions & 0 deletions podcasts/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ def test_seconds_to_timespan(self):
utils.seconds_to_timespan(seconds),
npt
)

def test_milliseconds_to_timespan(self):
test_values = [
(3499, "03"),
(3501, "04"),
(5000, "05"),
(37000, "37"),
(61000, "01:01"),
(468000, "07:48"),
(3540000, "59:00"),
(5752000, "1:35:52"),
(48430000, "13:27:10"),
(48430900, "13:27:11"),
(360000000, "100:00:00"),
]
for milliseconds, npt in test_values:
self.assertEqual(
utils.milliseconds_to_timespan(milliseconds),
npt
)
5 changes: 5 additions & 0 deletions podcasts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ def seconds_to_timespan(seconds=0):
output += f"{minutes:02}:"
output += f"{seconds:02}"
return output


def milliseconds_to_timespan(milliseconds=0):
seconds = round(milliseconds / 1000)
return seconds_to_timespan(seconds)

0 comments on commit bcf7e83

Please sign in to comment.