Skip to content

Commit 6732e64

Browse files
committed
動画検索対象切り替え対応
1 parent 0629b6c commit 6732e64

File tree

7 files changed

+164758
-36
lines changed

7 files changed

+164758
-36
lines changed

src/assets/locales/ja.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"date": "日付設定",
7878
"time": "時間設定",
7979
"subject_label_color": "ラベル色",
80-
"video_keyword": "オプション機能:{source}の動画検索",
80+
"video_keyword": "オプション機能:{source}動画検索",
8181
"video_url": "参考動画URL",
8282
"video_thumbnail": "動画サムネイル・キャプション表示",
8383
"textbook_page": "教科書ページ",
@@ -90,7 +90,7 @@
9090
"required": "*マークのあるものは必須項目です",
9191
"search_videos": {
9292
"search": "検索",
93-
"search_result": "{source}の動画検索結果",
93+
"search_result": "{source}動画検索結果",
9494
"add_to_video_urls": "参考動画URLに登録する"
9595
}
9696
},

src/components/EditLessonScreenInner3.vue

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99
<div class="VideoSearch">
1010
<editor-input-field-pickable
1111
v-model="videoSearchWord"
12+
selector="video"
1213
:title="
1314
$t('components.editing_screen.labels.video_keyword', {
14-
source: 'NHK For School',
15+
source: '',
1516
})
1617
"
1718
:placeholder="$t('components.editing_screen.placeholder.video_keyword')"
1819
icon-name="mdi-magnify"
1920
:button-text="$t('components.editing_screen.search_videos.search')"
2021
@clickButton="handleVideoSearchWord"
22+
@changeMovie="handleChangeMovie"
2123
/>
2224

2325
<div v-if="videoSearchResult.length > 0" class="SearchResult">
2426
<h3 class="SearchResultTitle">
2527
{{
2628
$t('components.editing_screen.search_videos.search_result', {
27-
source: 'NHK For School',
29+
source: '',
2830
})
2931
}}
3032
</h3>
@@ -114,6 +116,7 @@ export default class EditLessonScreenInner3 extends Vue {
114116
})
115117
public value!: formData
116118
119+
videoSourceType: string = ''
117120
videoSearchWord: string = ''
118121
videoSearchResult: formData[] = []
119122
page: number = 1
@@ -122,11 +125,11 @@ export default class EditLessonScreenInner3 extends Vue {
122125
displayLists: formData[] = []
123126
124127
mounted() {
125-
fetch('/data/movies.json')
126-
.then((res) => res.json())
127-
.then((data) => {
128-
movies = data
129-
})
128+
// fetch('/data/movies.json')
129+
// .then((res) => res.json())
130+
// .then((data) => {
131+
// movies = data
132+
// })
130133
}
131134
132135
private get form(): formData {
@@ -147,6 +150,15 @@ export default class EditLessonScreenInner3 extends Vue {
147150
this.tempFormData = this.value
148151
}
149152
153+
private handleChangeMovie(selected) {
154+
this.videoSourceType = selected.sourceType
155+
fetch(`/data/${selected.dataFile}`)
156+
.then((res) => res.json())
157+
.then((data) => {
158+
movies = data
159+
})
160+
}
161+
150162
private handleVideoSearchWord() {
151163
if (this.videoSearchWord) {
152164
this.page = 1
@@ -158,33 +170,16 @@ export default class EditLessonScreenInner3 extends Vue {
158170
return fullText.includes(this.videoSearchWord)
159171
})
160172
.map((v) => {
161-
const videoId = v['教材_ID']
162-
const videoType = parseInt(videoId.slice(5, 6))
163-
const nfsMovieUrl = 'https://www2.nhk.or.jp/school/movie/'
164-
const videoDirectory = videoId.slice(0, 8)
165-
let videoThumbnailUrl = `https://www.nhk.or.jp/das/image/${videoDirectory}/${videoId}_S_005.jpg`
166-
let videoUrl
167-
switch (videoType) {
168-
case 1:
169-
case 2:
170-
videoUrl = `${nfsMovieUrl}bangumi.cgi?das_id=${videoId}&p=box`
173+
let videoInfo
174+
switch (this.videoSourceType) {
175+
case 'NHK':
176+
videoInfo = this.mapNhk(v)
171177
break
172-
case 3:
173-
case 4:
174-
videoUrl = `${nfsMovieUrl}clip.cgi?das_id=${videoId}&p=box`
178+
case 'junyiacademy':
179+
videoInfo = this.mapJunyiacademy(v)
175180
break
176-
default:
177-
videoUrl = null
178-
videoThumbnailUrl = ''
179-
}
180-
return {
181-
videoUrl,
182-
videoTitle: v['教材_タイトル'],
183-
videoSubTitle: v['教材_サブタイトル'],
184-
videoDescription: v['教材_説明'],
185-
videoPlayTime: v['教材_再生時間'],
186-
videoThumbnailUrl,
187181
}
182+
return videoInfo
188183
})
189184
190185
this.length = Math.ceil(this.videoSearchResult.length / this.pageSize)
@@ -204,6 +199,47 @@ export default class EditLessonScreenInner3 extends Vue {
204199
)
205200
}
206201
202+
private mapNhk(v) {
203+
const videoId = v.inherentProperties.教材_ID
204+
const videoType = parseInt(videoId.slice(5, 6))
205+
const nfsMovieUrl = 'https://www2.nhk.or.jp/school/movie/'
206+
const videoDirectory = videoId.slice(0, 8)
207+
let videoThumbnailUrl = `https://www.nhk.or.jp/das/image/${videoDirectory}/${videoId}_S_005.jpg`
208+
let videoUrl
209+
switch (videoType) {
210+
case 1:
211+
case 2:
212+
videoUrl = `${nfsMovieUrl}bangumi.cgi?das_id=${videoId}&p=box`
213+
break
214+
case 3:
215+
case 4:
216+
videoUrl = `${nfsMovieUrl}clip.cgi?das_id=${videoId}&p=box`
217+
break
218+
default:
219+
videoUrl = null
220+
videoThumbnailUrl = ''
221+
}
222+
return {
223+
videoUrl,
224+
videoTitle: v.title,
225+
videoSubTitle: v.inherentProperties.教材_サブタイトル,
226+
videoDescription: v.description,
227+
videoPlayTime: v.inherentProperties.教材_再生時間,
228+
videoThumbnailUrl,
229+
}
230+
}
231+
232+
private mapJunyiacademy(v) {
233+
return {
234+
videoUrl: v.inherentProperties.url,
235+
videoTitle: v.title,
236+
videoSubTitle: '',
237+
videoDescription: v.description,
238+
videoPlayTime: '',
239+
videoThumbnailUrl: v.inherentProperties.thumbnailUrl,
240+
}
241+
}
242+
207243
/* CORS 回避必須
208244
@Watch('form.videoUrl')
209245
onChangeVideoUrl() {

src/components/EditorInputFieldPickable.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<div>
3-
<span v-if="title" class="EditorField-Title">{{ title }}</span>
3+
<span v-if="title" class="EditorField-Title"
4+
>{{ title }}
5+
<movie-selector v-if="selector" @change="$emit('changeMovie', $event)" />
6+
</span>
47
<div class="EditorField-Form">
58
<editor-input-field
69
:value="value"
@@ -25,9 +28,10 @@
2528
import Vue from 'vue'
2629
import EditorInputField from '@/components/EditorInputField.vue'
2730
import BaseEditorButton from '@/components/BaseEditorButton.vue'
31+
import MovieSelector from '@/components/MovieSelector.vue'
2832
2933
export default Vue.extend({
30-
components: { EditorInputField, BaseEditorButton },
34+
components: { EditorInputField, BaseEditorButton, MovieSelector },
3135
props: {
3236
title: {
3337
type: String,
@@ -69,13 +73,18 @@ export default Vue.extend({
6973
required: false,
7074
default: '',
7175
},
76+
selector: {
77+
type: String,
78+
required: false,
79+
default: '',
80+
},
7281
},
7382
})
7483
</script>
7584

7685
<style lang="scss" scoped>
7786
.EditorField-Title {
78-
display: block;
87+
display: flex;
7988
font-size: 16px;
8089
font-weight: bold;
8190
color: $color-white;

src/components/MovieSelector.vue

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<template>
2+
<div class="MovieSelector">
3+
<v-select
4+
v-model="selectedMovie"
5+
:items="movies"
6+
item-text="name"
7+
item-value="sourceType"
8+
return-object
9+
class="MovieSelector"
10+
dense
11+
hide-details
12+
solo
13+
@change="$emit('change', $event)"
14+
/>
15+
</div>
16+
</template>
17+
18+
<script lang="ts">
19+
import Vue from 'vue'
20+
21+
type MovieListItem = { sourceType: string; name: string; dataFile: string }
22+
type LocalData = {
23+
selectedMovie: string
24+
movies: MovieListItem[]
25+
}
26+
27+
export default Vue.extend({
28+
data(): LocalData {
29+
return {
30+
selectedMovie: '',
31+
movies: [],
32+
}
33+
},
34+
mounted() {
35+
this.selectedMovie =
36+
this.$root.$i18n.locale === 'zh-tw' ? 'junyiacademy' : 'NHK'
37+
fetch('/data/movie-source.json')
38+
.then((res) => res.json())
39+
.then((data) => {
40+
this.movies = data
41+
this.$emit(
42+
'change',
43+
this.movies.find((m) => m.sourceType === this.selectedMovie)
44+
)
45+
})
46+
},
47+
})
48+
</script>

src/static/data/movie-source.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"sourceType": "NHK",
4+
"name": "NHK For Schoolの動画",
5+
"dataFile": "movies2-nhk.json"
6+
},
7+
{
8+
"sourceType": "junyiacademy",
9+
"name": "均一教育平台 junyiacademy",
10+
"dataFile": "movies-junyiacademy.json"
11+
}
12+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"title": "【暖身】認識 5 以內的數",
4+
"description": "翰林國小數學",
5+
"keywords": "【一上】數到 10",
6+
"source": "junyiacademy",
7+
"inherentProperties": {
8+
"url": "https://www.junyiacademy.org/course-compare/math-grade-1-a/j-m1ach1/v/c3DGTr7Vmsc",
9+
"thumbnailUrl": ""
10+
}
11+
},
12+
{
13+
"title": "【觀念】認識 5 以內的數",
14+
"description": "翰林國小數學",
15+
"keywords": "【一上】數到 10",
16+
"source": "junyiacademy",
17+
"inherentProperties": {
18+
"url": "https://www.junyiacademy.org/course-compare/math-grade-1-a/j-m1ach1/v/JMN5LjxD6ds",
19+
"thumbnailUrl": ""
20+
}
21+
}
22+
]

0 commit comments

Comments
 (0)