forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideo.scala
48 lines (38 loc) · 1.05 KB
/
Video.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package lila.video
case class Video(
_id: Video.ID, // youtube ID
title: String,
author: String,
targets: List[Target],
tags: List[Tag],
lang: Lang,
ads: Boolean,
startTime: Int, // in seconds
metadata: Youtube.Metadata,
createdAt: DateTime
):
inline def id = _id
def thumbnail = s"https://img.youtube.com/vi/$id/0.jpg"
def similarity(other: Video) =
(tags intersect other.tags).size +
(targets intersect other.targets).size +
(if (author == other.author) 1 else 0)
def durationString =
metadata.duration.map { seconds =>
"%02d:%02d".format(seconds / 60, seconds % 60)
}
override def toString = s"[$id] $title ($author)"
object Target:
val BEGINNER = 1
val INTERMEDIATE = 2
val ADVANCED = 3
val EXPERT = 4
def name(target: Int) =
target match
case BEGINNER => "beginner"
case INTERMEDIATE => "intermediate"
case ADVANCED => "advanced"
case EXPERT => "expert"
case _ => ""
object Video:
type ID = String