~ihabunek/vampires

7eb4edea96093a4cdc0dc950f5022547ddbdafaf — Ivan Habunek 7 months ago 5d4d09d
Clean up code
4 files changed, 85 insertions(+), 77 deletions(-)

D audio/.keep
M index.html
M parse.py
D slides/.keep
D audio/.keep => audio/.keep +0 -0
M index.html => index.html +76 -76
@@ 8,19 8,20 @@
    <style type="text/css">
      body { max-width: 1024px; margin: auto; font-family: sans-serif }
      footer { font-size: 0.9rem; margin-top: 5rem }
      .redacted { background-color: black; color: white; display: inline-block; }

      .redacted { background-color: black; color: white; padding: 0 0.5rem }
      .strike { text-decoration: line-through }
      .centered { text-align: center }
      .player { width: 640px }
      .w-full { width: 100% }
      #audio { margin-top: 1rem }

      #audio { margin-top: 1rem }
      #slide {
        width: 100%;
        height: 0;
        padding-bottom: 75%;
        overflow: hidden;
        background-image: url("slides/slide_00.jpg");
        background-image: url("slides/slide_01.jpg");
        background-position: center;
        background-repeat: no-repeat;
        background-size: contain;


@@ 66,87 67,86 @@
  </body>

  <script type="text/javascript">
    const audio = document.querySelector("audio")

    // TODO: timings need tweaking
    const slideTimings = [
      0.0,     // 1
      25.9,    // 2
      51.3,    // 3
      110.3,   // 4
      125.4,   // 5
      156.0,   // 6
      231.6,   // 7
      268.7,   // 8
      294.3,   // 9
      307.6,   // 10
      318.1,   // 11
      333.1,   // 12
      344.7,   // 13
      356.3,   // 14
      374.3,   // 15
      388.1,   // 16
      403.1,   // 17
      449.7,   // 18
      486.1,   // 19
      542.1,   // 20
      567.7,   // 21
      631.4,   // 22
      705.7,   // 23
      749.6,   // 24
      830.6,   // 25
      844.7,   // 26
      860.7,   // 27
      913.4,   // 28
      921.4,   // 29
      928.0,   // 30
      969.4,   // 31
      1018.7,  // 32
      1082.3,  // 33
      1129.1,  // 34
      1140.0,  // 35
      1150.7,  // 36
      1161.1,  // 37
      1269.4,  // 38
      1330.6,  // 39
      1356.6,  // 40
      1389.9,  // 41
      1423.1,  // 42
      1500.6,  // 43
      1587.6,  // 44
      1595.6,  // 45
      1607.7,  // 46
      1622.7,  // 47
      1643.3,  // 48
      1695.1,  // 49
      1729.6,  // 50
      1754.1,  // 51
      1794.6,  // 52
      1862.6,  // 53
      1890.0,  // 54
      1964.7,  // 55
      2006.3,  // 56
      2074.3,  // 57
      2135.4,  // 58
    ]
    const slideTimings = {
      "slides/slide_01.jpg": 0.0,
      "slides/slide_02.jpg": 25.9,
      "slides/slide_03.jpg": 51.3,
      "slides/slide_04.jpg": 110.3,
      "slides/slide_05.jpg": 125.4,
      "slides/slide_06.jpg": 156.0,
      "slides/slide_07.jpg": 231.6,
      "slides/slide_08.jpg": 268.7,
      "slides/slide_09.jpg": 294.3,
      "slides/slide_10.jpg": 307.6,
      "slides/slide_11.jpg": 318.1,
      "slides/slide_12.jpg": 333.1,
      "slides/slide_13.jpg": 344.7,
      "slides/slide_14.jpg": 356.3,
      "slides/slide_15.jpg": 374.3,
      "slides/slide_16.jpg": 388.1,
      "slides/slide_17.jpg": 403.1,
      "slides/slide_18.jpg": 449.7,
      "slides/slide_19.jpg": 486.1,
      "slides/slide_20.jpg": 542.1,
      "slides/slide_21.jpg": 567.7,
      "slides/slide_22.jpg": 631.4,
      "slides/slide_23.jpg": 705.7,
      "slides/slide_24.jpg": 749.6,
      "slides/slide_25.jpg": 830.6,
      "slides/slide_26.jpg": 844.7,
      "slides/slide_27.jpg": 860.7,
      "slides/slide_28.jpg": 913.4,
      "slides/slide_29.jpg": 921.4,
      "slides/slide_30.jpg": 928.0,
      "slides/slide_31.jpg": 969.4,
      "slides/slide_32.jpg": 1018.7,
      "slides/slide_33.jpg": 1082.3,
      "slides/slide_34.jpg": 1129.1,
      "slides/slide_35.jpg": 1140.0,
      "slides/slide_36.jpg": 1150.7,
      "slides/slide_37.jpg": 1161.1,
      "slides/slide_38.jpg": 1269.4,
      "slides/slide_39.jpg": 1330.6,
      "slides/slide_40.jpg": 1356.6,
      "slides/slide_41.jpg": 1389.9,
      "slides/slide_42.jpg": 1423.1,
      "slides/slide_43.jpg": 1500.6,
      "slides/slide_44.jpg": 1587.6,
      "slides/slide_45.jpg": 1595.6,
      "slides/slide_46.jpg": 1607.7,
      "slides/slide_47.jpg": 1622.7,
      "slides/slide_48.jpg": 1643.3,
      "slides/slide_49.jpg": 1695.1,
      "slides/slide_50.jpg": 1729.6,
      "slides/slide_51.jpg": 1754.1,
      "slides/slide_52.jpg": 1794.6,
      "slides/slide_53.jpg": 1862.6,
      "slides/slide_54.jpg": 1890.0,
      "slides/slide_55.jpg": 1964.7,
      "slides/slide_56.jpg": 2006.3,
      "slides/slide_57.jpg": 2074.3,
      "slides/slide_58.jpg": 2135.4
    }

    document.getElementById("total").innerText = slideTimings.length
    const audio = document.querySelector("audio")
    const slide = document.getElementById("slide")
    const current = document.getElementById("current")
    const total = document.getElementById("total")

    const slides = Object.keys(slideTimings)
    const times = Object.values(slideTimings)

    const getSlide = (timestamp) => {
      const index =  slideTimings.findIndex(slideTimestamp => {
        return slideTimestamp > timestamp
      })
    total.innerText = slides.length

    const getIndex = (timestamp) => {
      const index =  times.findIndex(slideTimestamp => slideTimestamp > timestamp)
      return index == -1 ? slideTimings.length - 1 : index - 1
    }

    const slide = document.getElementById("slide")
    const current = document.getElementById("current")

    audio.addEventListener("timeupdate", event => {
      const index = getSlide(event.target.currentTime)
      const src = index < 10 ? `slides/slide_0${index}.jpg` : `slides/slide_${index}.jpg`
      slide.style.backgroundImage = "url(" + src + ")"
      const index = getIndex(event.target.currentTime)
      slide.style.backgroundImage = "url(" + slides[index] + ")"
      current.innerText = index + 1
    });
  </script>

M parse.py => parse.py +9 -1
@@ 1,14 1,19 @@
#!/usr/bin/env python3

import os
import sys

from lxml import etree
from base64 import b64decode


def extract_slides(root):
    if not os.path.isdir("slides"):
        os.mkdir("slides")

    for index, node in enumerate(root.findall(".//DefineBitsJPEG2")):
        data = node.find("data").find("data").text
        filename = f"slides/slide_{index:0>2}.jpg"
        filename = f"slides/slide_{index + 1:0>2}.jpg"
        print(f"Saving: {filename}")

        with open(filename, "wb") as f:


@@ 56,6 61,9 @@ def _expand_audio_segments(root):


def extract_segmented_audio(root):
    if not os.path.isdir("audio"):
        os.mkdir("audio")

    total = 0
    all_data = b""
    for index, (data, count) in enumerate(_expand_audio_segments(root)):

D slides/.keep => slides/.keep +0 -0