Skip to content

Commit

Permalink
print quiteaplaylist and google links for deleted videos (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalva97 authored Oct 1, 2022
1 parent 9f52948 commit 23ab845
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 465 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version "1.7.20"
kotlin("multiplatform") version "1.7.10"
kotlin("plugin.serialization") version "1.6.10"
// id("com.github.johnrengelman.shadow") version "7.1.2" // TODO also add support for jvm
id("com.adarshr.test-logger") version "3.2.0"
Expand Down
536 changes: 120 additions & 416 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/commonMain/kotlin/models/Channel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models

data class Channel(val name: String, val url: String) {
companion object {
operator fun invoke(video: YoutubeVideo): Channel {
val first = video.channel?.first()
return Channel(first?.name ?: "unknown channel", first?.url ?: "unknown url")
}
}
}
7 changes: 7 additions & 0 deletions src/commonMain/kotlin/models/ChannelStatistics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

data class ChannelStatistics(val channel: Channel, val timesClicked: Int) {
override fun toString(): String {
return " - [${channel.name} - ${timesClicked}](${channel.url})"
}
}
33 changes: 15 additions & 18 deletions src/commonMain/kotlin/models/VideoStatistics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ package models
import kotlinx.datetime.Instant

data class VideoStatistics(
val title: String,
private val title: String,
val firstTimeWatched: Instant,
val timesClicked: Int,
val url: String,
val channel: Channel,
) {
override fun toString(): String {
return " - [${getVideoName(this)} - ${timesClicked}](${url})"
}

private fun getVideoName(music: VideoStatistics): String {
return music.title.replace(VIDEO_PREFIX, "")
}
}
val name: String = getVideoName(title)
val isDeleted: Boolean = name == url

data class ChannelStatistics(val channel: Channel, val timesClicked: Int) {
override fun toString(): String {
return " - [${channel.name} - ${timesClicked}](${channel.url})"
return if (isDeleted) {
" - Deleted Video $videoID - [quiteaplaylist]($QUITE_A_PLAYLIST$url) - [Google]($GOOGLE$url)"
} else {
" - [${name} - ${timesClicked}](${url})"
}
}
}

data class Channel(val name: String, val url: String) {
companion object {
operator fun invoke(video: YoutubeVideo): Channel {
val first = video.channel?.first()
return Channel(first?.name ?: "unknown channel", first?.url ?: "unknown url")
}
}
private val VideoStatistics.videoID
get() = url.split('=').last()

private fun getVideoName(title: String): String {
return title.replace(VIDEO_PREFIX, "")
}

private const val VIDEO_PREFIX = "Watched "
private const val QUITE_A_PLAYLIST = "https://quiteaplaylist.com/search?url="
private const val GOOGLE = "https://www.google.com/search?q="
25 changes: 0 additions & 25 deletions src/commonTest/kotlin/MonthTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import kotlinx.datetime.Instant
import models.Channel
import models.VideoStatistics
import kotlin.test.Test
import kotlin.test.assertEquals

Expand All @@ -16,33 +13,11 @@ class MonthTest {
}
}

val someRandomVideo = VideoStatistics(
title = "Watched Cepheid - Gaia (feat. Nonon & Sithu Aye)",
firstTimeWatched = Instant.parse("2020-05-14T15:48:29.760Z"),
timesClicked = 6,
url = "https://www.youtube.com/watch?v=SZvrKO763Mc",
channel = Channel(
name = "Watched Cepheid -Gaia(feat.Nonon & Sithu Aye)",
url = "https://www.youtube.com/watch?v=SZvrKO763Mc"
)
)

const val someRandomVideoString = """### MAY
- [Cepheid - Gaia (feat. Nonon & Sithu Aye) - 6](https://www.youtube.com/watch?v=SZvrKO763Mc)
"""

val anotherRandomVideo = VideoStatistics(
title = "Watched Owl vision - zyborg | Music Visualization",
firstTimeWatched = Instant.parse("2021-02-13T19:52:45.459Z"),
timesClicked = 3,
url = "https://www.youtube.com/watch?v=HkNU0FTBYEI",
channel = Channel(
name = "Watched Owl vision - zyborg | Music Visualization",
url = "https://www.youtube.com/watch?v=HkNU0FTBYEI"
)
)

const val anotherRandomVideoString = """### FEBRUARY
- [Owl vision - zyborg | Music Visualization - 3](https://www.youtube.com/watch?v=HkNU0FTBYEI)
Expand Down
11 changes: 10 additions & 1 deletion src/commonTest/kotlin/VideoStatisticsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ class VideoStatisticsTest {
fun toString_returnsMarkdownFormattedEntry() {
assertEquals(statisticsText, someRandomVideo.toString())
}

@Test
fun toString_returnsCorrectTextWhenVideoIsDeleted() {
assertEquals(deletedVideoText, someRandomDeletedVideo.toString())
}

}

private const val statisticsText =
" - [Cepheid - Gaia (feat. Nonon & Sithu Aye) - 6](https://www.youtube.com/watch?v=SZvrKO763Mc)"
" - [Cepheid - Gaia (feat. Nonon & Sithu Aye) - 6](https://www.youtube.com/watch?v=SZvrKO763Mc)"

private const val deletedVideoText =
" - Deleted Video _rfxqRRN2hM - [quiteaplaylist](https://quiteaplaylist.com/search?url=https://www.youtube.com/watch?v=_rfxqRRN2hM) - [Google](https://www.google.com/search?q=https://www.youtube.com/watch?v=_rfxqRRN2hM)"
6 changes: 3 additions & 3 deletions src/commonTest/kotlin/YoutubeHistoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class YoutubeHistoryTest {
fun topTenVideos_sortingIsByMostTimesClickedVideo() {
val top10 = YoutubeHistory(sampleData, 0).topTenVideos()

assertTrue(top10[0].title == "Watched Sabaton - To Hell And Back")
assertTrue(top10[1].title == "Watched WIND ROSE - Diggy Diggy Hole (Official Video) | Napalm Records")
assertTrue(top10[2].title == "Watched Happy Halloween (feat. Megumi) 【Intense Symphonic Metal Cover】")
assertTrue(top10[0].name == "Sabaton - To Hell And Back")
assertTrue(top10[1].name == "WIND ROSE - Diggy Diggy Hole (Official Video) | Napalm Records")
assertTrue(top10[2].name == "Happy Halloween (feat. Megumi) 【Intense Symphonic Metal Cover】")
}

@Test
Expand Down
37 changes: 37 additions & 0 deletions src/commonTest/kotlin/sampleData.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
import kotlinx.datetime.Instant
import models.Channel
import models.VideoStatistics

val someRandomVideo = VideoStatistics(
title = "Watched Cepheid - Gaia (feat. Nonon & Sithu Aye)",
firstTimeWatched = Instant.parse("2020-05-14T15:48:29.760Z"),
timesClicked = 6,
url = "https://www.youtube.com/watch?v=SZvrKO763Mc",
channel = Channel(
name = "Watched Cepheid -Gaia(feat.Nonon & Sithu Aye)",
url = "https://www.youtube.com/watch?v=SZvrKO763Mc"
)
)

val someRandomDeletedVideo = VideoStatistics(
title = "Watched https://www.youtube.com/watch?v\u003d_rfxqRRN2hM",
firstTimeWatched = Instant.parse("2018-12-06T00:30:28.390Z"),
timesClicked = 6,
url = "https://www.youtube.com/watch?v\u003d_rfxqRRN2hM",
channel = Channel(
name = "Some Channel Name here",
url = "https://www.youtube.com/watch?v=SZvrKO763Mc"
)
)

val anotherRandomVideo = VideoStatistics(
title = "Watched Owl vision - zyborg | Music Visualization",
firstTimeWatched = Instant.parse("2021-02-13T19:52:45.459Z"),
timesClicked = 3,
url = "https://www.youtube.com/watch?v=HkNU0FTBYEI",
channel = Channel(
name = "Watched Owl vision - zyborg | Music Visualization",
url = "https://www.youtube.com/watch?v=HkNU0FTBYEI"
)
)

// TODO reformat
const val sampleData = """
[
Expand Down
2 changes: 1 addition & 1 deletion web/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("js")
id("org.jetbrains.compose") version "1.2.0-alpha01-dev750"
id("org.jetbrains.compose") version "1.2.0-beta02"
}

group = "com.github.shalva97"
Expand Down

0 comments on commit 23ab845

Please sign in to comment.