Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
feat(chapters): Adds ability to retrieve chapters via url
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Apr 19, 2018
1 parent b694a14 commit 55e328d
Show file tree
Hide file tree
Showing 33 changed files with 778 additions and 340 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ _site
dist
coverage
docs/media

# logs
yarn-error.log
80 changes: 80 additions & 0 deletions docs/fixtures/chapters/fg55.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"start":"00:00:00.000",
"title":"Intro",
"href":"",
"image":""
},
{
"start":"00:00:43.137",
"title":"Begr\u00fc\u00dfung",
"href":"",
"image":""
},
{
"start":"00:01:15.911",
"title":"Universit\u00e4ts-Sternwarte M\u00fcnchen",
"href":"",
"image":""
},
{
"start":"00:05:34.891",
"title":"Post von der NASA",
"href":"",
"image":""
},
{
"start":"00:07:50.061",
"title":"\u00d6ffentlichkeitsarbeit und Verschw\u00f6rungstheorien",
"href":"",
"image":""
},
{
"start":"00:29:18.737",
"title":"Politische Rationalit\u00e4t",
"href":"",
"image":""
},
{
"start":"00:39:42.311",
"title":"Die \u00d6konomisierung der Wissenschaft",
"href":"",
"image":""
},
{
"start":"00:50:23.655",
"title":"Klimawandel als Krise",
"href":"",
"image":""
},
{
"start":"01:04:00.398",
"title":"Die Kunst des Wissens",
"href":"",
"image":""
},
{
"start":"01:16:29.296",
"title":"Wissenschaft in der Schule",
"href":"",
"image":""
},
{
"start":"01:23:29.909",
"title":"Wie lehrt man das Wissen der Welt?",
"href":"",
"image":""
},
{
"start":"01:34:35.032",
"title":"Konzentration auf das Wichtige",
"href":"",
"image":""
},
{
"start":"01:44:11.290",
"title":"Ausklang",
"href":"",
"image":""
}
]
2 changes: 1 addition & 1 deletion docs/fixtures/fg45.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@
"comment": null
}
],
"transcripts": "https://podlove-player.surge.sh/fixtures/transcripts/fg45.json"
"transcripts": "./fixtures/transcripts/fg45.json"
}
1 change: 1 addition & 0 deletions docs/fixtures/transcripts/fg55.json

Large diffs are not rendered by default.

81 changes: 1 addition & 80 deletions docs/transcripts-develop.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,86 +57,7 @@
"mimeType":"audio\/mpeg"
}
],
"chapters":[
{
"start":"00:00:00.000",
"title":"Intro",
"href":"",
"image":""
},
{
"start":"00:00:43.137",
"title":"Begr\u00fc\u00dfung",
"href":"",
"image":""
},
{
"start":"00:01:15.911",
"title":"Universit\u00e4ts-Sternwarte M\u00fcnchen",
"href":"",
"image":""
},
{
"start":"00:05:34.891",
"title":"Post von der NASA",
"href":"",
"image":""
},
{
"start":"00:07:50.061",
"title":"\u00d6ffentlichkeitsarbeit und Verschw\u00f6rungstheorien",
"href":"",
"image":""
},
{
"start":"00:29:18.737",
"title":"Politische Rationalit\u00e4t",
"href":"",
"image":""
},
{
"start":"00:39:42.311",
"title":"Die \u00d6konomisierung der Wissenschaft",
"href":"",
"image":""
},
{
"start":"00:50:23.655",
"title":"Klimawandel als Krise",
"href":"",
"image":""
},
{
"start":"01:04:00.398",
"title":"Die Kunst des Wissens",
"href":"",
"image":""
},
{
"start":"01:16:29.296",
"title":"Wissenschaft in der Schule",
"href":"",
"image":""
},
{
"start":"01:23:29.909",
"title":"Wie lehrt man das Wissen der Welt?",
"href":"",
"image":""
},
{
"start":"01:34:35.032",
"title":"Konzentration auf das Wichtige",
"href":"",
"image":""
},
{
"start":"01:44:11.290",
"title":"Ausklang",
"href":"",
"image":""
}
],
"chapters":"fixtures/chapters/fg55.json",
"contributors":[
{
"name":"Tim Pritlove",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-es6-promise": "^1.1.1",
"babel-plugin-lodash": "3.3.2",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-runtime": "6.23.0",
Expand Down
43 changes: 39 additions & 4 deletions src/effects/chapters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import { get } from 'lodash'
import { getOr, compose } from 'lodash/fp'
import { get, findIndex, isString } from 'lodash'
import { getOr, compose, map } from 'lodash/fp'

import { currentChapter, currentChapterIndex } from 'utils/chapters'
import { currentChapter, currentChapterIndex, setActiveByPlaytime, setActiveByIndex } from 'utils/chapters'
import { handleActions } from 'utils/effects'
import { toPlayerTime } from 'utils/time'
import request from 'utils/request'

import actions from 'store/actions'

import { PREVIOUS_CHAPTER, NEXT_CHAPTER, SET_CHAPTER, SET_PLAYTIME, UPDATE_PLAYTIME } from 'store/types'
import { INIT, PREVIOUS_CHAPTER, NEXT_CHAPTER, SET_CHAPTER, SET_PLAYTIME, UPDATE_PLAYTIME } from 'store/types'

const chapterMeta = (chapter, next) => ({
start: toPlayerTime(chapter.start),
end: toPlayerTime(next.start),
title: chapter.title
})

const parseChapters = duration => (result, chapter, index, chapters) => {
const end = get(chapters, index + 1, { start: duration })
return [...result, chapterMeta(chapter, end)]
}

const fallbackToLastChapter = (playtime = 0) => (chapters = []) => {
const index = findIndex(chapters, { active: true })

return (index > 0 || playtime === 0) ? chapters : chapters.map(setActiveByIndex(chapters.length - 1))
}

const chapterIndexFromState = compose(
currentChapterIndex,
Expand All @@ -25,6 +44,22 @@ const chapterUpdate = ({ dispatch }, { payload }, state) => {
}

export default handleActions({
[INIT]: ({ dispatch }, { payload }, state) => {
const chapters = get(payload, 'chapters', [])
const playtime = get(state, 'playtime', 0)
const duration = get(state, 'duration', 0)

const requestChapters = isString(chapters) ? request(chapters) : Promise.resolve(chapters)

requestChapters
.catch(() => [])
.then(chapters => chapters.reduce(parseChapters(toPlayerTime(duration)), []))
.then(chapters => chapters.map(setActiveByPlaytime(playtime)))
.then(fallbackToLastChapter(playtime))
.then(actions.initChapters)
.then(dispatch)
},

[PREVIOUS_CHAPTER]: ({ dispatch }, action, state) => {
const index = chapterIndexFromState(state)
const current = currentChapterFromState(state)
Expand Down
Loading

0 comments on commit 55e328d

Please sign in to comment.