Skip to content

Commit

Permalink
Add module that produces YT chapters from markers CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed Jan 16, 2025
1 parent d81d39d commit ced8cad
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 4 deletions.
17 changes: 17 additions & 0 deletions lib/changelog/kits/marker_kit.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Changelog.Kits.MarkerKit do
alias ChangelogWeb.TimeView
NimbleCSV.define(CsvParser, separator: "\t", escape: "\"")

# Name Start Duration Time Format Type Description
def to_youtube(string) do
string
|> CsvParser.parse_string()
|> Enum.map(fn [name, start | _] -> "#{duration(start)} #{name}" end)
|> Enum.join("\n")
end

# Converting to seconds and back removes decimals and extra padding
defp duration(start) do
start |> TimeView.seconds() |> TimeView.duration()
end
end
19 changes: 15 additions & 4 deletions lib/changelog_web/views/time_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ defmodule ChangelogWeb.TimeView do

def seconds(duration) do
case String.split(duration, ":") do
[h, m, s] -> to_seconds(:hours, h) + to_seconds(:minutes, m) + to_seconds(s)
[m, s] -> to_seconds(:minutes, m) + to_seconds(s)
[s] -> to_seconds(s)
_ -> 0
[h, m, s, ms] ->
to_seconds(:hours, h) + to_seconds(:minutes, m) + to_seconds(s) + to_seconds(:ms, ms)

[h, m, s] ->
to_seconds(:hours, h) + to_seconds(:minutes, m) + to_seconds(s)

[m, s] ->
to_seconds(:minutes, m) + to_seconds(s)

[s] ->
to_seconds(s)

_ ->
0
end
end

Expand Down Expand Up @@ -139,6 +149,7 @@ defmodule ChangelogWeb.TimeView do

defp to_seconds(:hours, str), do: string_to_rounded_integer(str) * 3600
defp to_seconds(:minutes, str), do: string_to_rounded_integer(str) * 60
defp to_seconds(:ms, str), do: round(string_to_rounded_integer(str) / 60)
defp to_seconds(str), do: string_to_rounded_integer(str)

defp string_to_rounded_integer(str) do
Expand Down
27 changes: 27 additions & 0 deletions test/changelog/kits/marker_kit_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Changelog.MarkerKitTest do
use ExUnit.Case
import Changelog.TestCase
alias Changelog.Kits.MarkerKit

describe "to_youtube/1" do
test "works for News 127" do
[csv, desired] =
"/markers/news-127.csv"
|> fixtures_path()
|> File.read!()
|> String.split("---")

assert MarkerKit.to_youtube(csv) == String.trim(desired)
end

test "works for Iterviews 624" do
[csv, desired] =
"/markers/interviews-624.csv"
|> fixtures_path()
|> File.read!()
|> String.split("---")

assert MarkerKit.to_youtube(csv) == String.trim(desired)
end
end
end
4 changes: 4 additions & 0 deletions test/changelog_web/views/time_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ defmodule ChangelogWeb.TimeViewTest do
assert seconds("10:00:00") == 36_000
end

test "when duration is hour, minutes, seconds, and milliseconds" do
assert seconds("01:35:10:70") == 5711
end

test "when duration has fraction of a sentence" do
assert seconds("59.17") == 59
assert seconds("01:35:10.70") == 5711
Expand Down
50 changes: 50 additions & 0 deletions test/fixtures/markers/interviews-624.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Name Start Duration Time Format Type Description
When NPR calls 00:01:41:14 00:00:00:00 24 fps Cue
What is embedded? 00:03:23:18 00:00:00:00 24 fps Cue
Programming non-computers 00:07:09:08 00:00:00:00 24 fps Cue
How Elecia got started 00:11:40:22 00:00:00:00 24 fps Cue
The moment of discovery 00:14:13:04 00:00:00:00 24 fps Cue
Mentoring for embedded 00:15:48:22 00:00:00:00 24 fps Cue
Wokwi is cool 00:18:43:00 00:00:00:00 24 fps Cue
The chasm between sim and real 00:22:16:18 00:00:00:00 24 fps Cue
The constraints of embedded 00:26:49:12 00:00:00:00 24 fps Cue
SILICON VALLEY 00:30:13:10 00:00:00:00 24 fps Cue
How big is the embedded world? 00:30:51:18 00:00:00:00 24 fps Cue
Open source + embedded 00:34:49:16 00:00:00:00 24 fps Cue
Elecia loves Kalman filters! 00:36:19:18 00:00:00:00 24 fps Cue
Elecia's thoughts on self-driving cars 00:40:04:20 00:00:00:00 24 fps Cue
Self-driving on a closed-system 00:49:27:12 00:00:00:00 24 fps Cue
GoPro is embedded 00:51:29:18 00:00:00:00 24 fps Cue
Traeger smokers are embedded 00:55:29:20 00:00:00:00 24 fps Cue
What do you want to build next? 01:01:28:04 00:00:00:00 24 fps Cue
Crunch Labs! 01:04:51:14 00:00:00:00 24 fps Cue
What else is cool? 01:07:58:18 00:00:00:00 24 fps Cue
Embedded is going everywhere 01:09:51:04 00:00:00:00 24 fps Cue
IoT, let us 'opt out' 01:15:10:20 00:00:00:00 24 fps Cue
Embedded.fm and other places 01:18:47:08 00:00:00:00 24 fps Cue
Wrapping up 01:22:55:18 00:00:00:00 24 fps Cue
---
01:41 When NPR calls
03:23 What is embedded?
07:09 Programming non-computers
11:40 How Elecia got started
14:13 The moment of discovery
15:48 Mentoring for embedded
18:43 Wokwi is cool
22:16 The chasm between sim and real
26:49 The constraints of embedded
30:13 SILICON VALLEY
30:51 How big is the embedded world?
34:49 Open source + embedded
36:19 Elecia loves Kalman filters!
40:04 Elecia's thoughts on self-driving cars
49:27 Self-driving on a closed-system
51:29 GoPro is embedded
55:29 Traeger smokers are embedded
1:01:28 What do you want to build next?
1:04:51 Crunch Labs!
1:07:58 What else is cool?
1:09:51 Embedded is going everywhere
1:15:10 IoT, let us 'opt out'
1:18:47 Embedded.fm and other places
1:22:55 Wrapping up
18 changes: 18 additions & 0 deletions test/fixtures/markers/news-127.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Name Start Duration Time Format Type Description
What up, streaming nerds? 00:00:00.000 0:55.854 decimal Cue
The new $30,000 side hustle 0:55.854 1:00.189 decimal Cue
Mistakes we make in large codebases 1:56.044 1:02.989 decimal Cue
Apple is killing Swift 2:59.033 0:58.213 decimal Cue
Sponsor: Retool 3:57.247 1:13.584 decimal Cue
Turns GitHub repos into interactive diagrams 5:10.826 0:32.453 decimal Cue
Exploring a stablecoin bank 5:43.279 1:26.438 decimal Cue
That's the news for now 7:09.718 1:05.632 decimal Cue
---
00:00 What up, streaming nerds?
00:56 The new $30,000 side hustle
01:56 Mistakes we make in large codebases
02:59 Apple is killing Swift
03:57 Sponsor: Retool
05:11 Turns GitHub repos into interactive diagrams
05:43 Exploring a stablecoin bank
07:10 That's the news for now

0 comments on commit ced8cad

Please sign in to comment.