From 0d42ea545c3b53d4c49bdc1217d45674fe6abed3 Mon Sep 17 00:00:00 2001 From: shabinder Date: Mon, 8 Mar 2021 22:11:08 +0530 Subject: [PATCH] Database dependency reconfigured & web-app bug troubleshooting --- .../com/shabinder/spotiflyer/MainActivity.kt | 3 +- .../kotlin/multiplatform-setup.gradle.kts | 2 +- common/dependency-injection/build.gradle.kts | 1 - .../com/shabinder/common/di/AndroidDir.kt | 6 ++- .../shabinder/common/di/YoutubeProvider.kt | 36 ---------------- .../kotlin/com/shabinder/common/di/DI.kt | 13 +++--- .../kotlin/com/shabinder/common/di/Dir.kt | 6 ++- .../common/di/FetchPlatformQueryResult.kt | 8 ++-- .../com/shabinder/common/di/TokenStore.kt | 11 +++-- .../shabinder/common/di/YoutubeProvider.kt | 1 - .../common/di/providers/GaanaProvider.kt | 43 ------------------- .../common/di/providers/SpotifyProvider.kt | 36 +--------------- .../common/di/providers/YoutubeMp3.kt | 1 - .../com/shabinder/common/di/DesktopDir.kt | 9 +++- .../shabinder/common/di/YoutubeProvider.kt | 38 ---------------- .../kotlin/com/shabinder/common/di/WebDir.kt | 9 +++- .../shabinder/common/di/YoutubeProvider.kt | 1 - desktop/src/jvmMain/kotlin/Main.kt | 2 +- web-app/src/main/kotlin/App.kt | 2 +- web-app/src/main/kotlin/client.kt | 1 - 20 files changed, 46 insertions(+), 183 deletions(-) diff --git a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt index d3aa7cf6..877fca17 100644 --- a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt +++ b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt @@ -55,7 +55,6 @@ const val disableDozeCode = 1223 @ExperimentalAnimationApi class MainActivity : ComponentActivity(), PaymentResultListener { - private val database: Database by inject() private val fetcher: FetchPlatformQueryResult by inject() private val dir: Dir by inject() private lateinit var root: SpotiFlyerRoot @@ -115,7 +114,7 @@ class MainActivity : ComponentActivity(), PaymentResultListener { componentContext, dependencies = object : SpotiFlyerRoot.Dependencies{ override val storeFactory = LoggingStoreFactory(DefaultStoreFactory) - override val database = this@MainActivity.database + override val database = this@MainActivity.dir.db override val fetchPlatformQueryResult = this@MainActivity.fetcher override val directories: Dir = this@MainActivity.dir override val showPopUpMessage: (String) -> Unit = ::uikitShowPopUpMessage diff --git a/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts b/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts index 16f050e5..6c610f15 100644 --- a/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts +++ b/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts @@ -21,7 +21,7 @@ kotlin { sourceSets { named("commonMain") { dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2") } } diff --git a/common/dependency-injection/build.gradle.kts b/common/dependency-injection/build.gradle.kts index a336d9e8..957729bc 100644 --- a/common/dependency-injection/build.gradle.kts +++ b/common/dependency-injection/build.gradle.kts @@ -17,7 +17,6 @@ kotlin { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1") implementation(Ktor.clientCore) - //implementation(Ktor.clientCio) implementation(Ktor.clientSerialization) implementation(Ktor.clientLogging) implementation(Ktor.clientJson) diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt index 4ac04057..ed22230f 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt @@ -11,6 +11,7 @@ import co.touchlab.kermit.Kermit import com.mpatric.mp3agic.Mp3File import com.shabinder.common.database.appContext import com.shabinder.common.models.TrackDetails +import com.shabinder.database.Database import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -23,7 +24,8 @@ import java.net.HttpURLConnection import java.net.URL actual class Dir actual constructor( - private val logger: Kermit + private val logger: Kermit, + private val database: Database? ) { private val scope = CoroutineScope(Dispatchers.IO) @@ -170,4 +172,6 @@ actual class Dir actual constructor( null } } + + actual val db: Database? = database } \ No newline at end of file diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt index 09d3b74b..27854192 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt @@ -18,19 +18,16 @@ package com.shabinder.common.di import co.touchlab.kermit.Kermit import com.github.kiulian.downloader.YoutubeDownloader -import com.shabinder.common.database.DownloadRecordDatabaseQueries import com.shabinder.common.models.DownloadStatus import com.shabinder.common.models.PlatformQueryResult import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.spotify.Source -import com.shabinder.database.Database import io.ktor.client.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext actual class YoutubeProvider actual constructor( private val httpClient: HttpClient, - private val database: Database, private val logger: Kermit, private val dir: Dir, ){ @@ -44,9 +41,6 @@ actual class YoutubeProvider actual constructor( private val sampleDomain2 = "youtube.com" private val sampleDomain3 = "youtu.be" - private val db: DownloadRecordDatabaseQueries - get() = database.downloadRecordDatabaseQueries - actual suspend fun query(fullLink: String): PlatformQueryResult?{ val link = fullLink.removePrefix("https://").removePrefix("http://") if(link.contains("playlist",true) || link.contains("list",true)){ @@ -133,22 +127,6 @@ actual class YoutubeProvider actual constructor( videoID = it.videoId() ) } - - withContext(Dispatchers.IO) { - db.add( - type = "PlayList", - name = if (name.length > 17) { - "${name.subSequence(0, 16)}..." - } else { - name - }, - link = "https://www.youtube.com/playlist?list=$searchId", - coverUrl = "https://i.ytimg.com/vi/${ - videos.firstOrNull()?.videoId() - }/hqdefault.jpg", - totalFiles = videos.size.toLong(), - ) - } } catch (e: Exception) { e.printStackTrace() logger.d{"An Error Occurred While Processing!"} @@ -204,20 +182,6 @@ actual class YoutubeProvider actual constructor( ) ) title = name - - withContext(Dispatchers.IO) { - db.add( - type = "Track", - name = if (name.length > 17) { - "${name.subSequence(0, 16)}..." - } else { - name - }, - link = "https://www.youtube.com/watch?v=$searchId", - coverUrl = "https://i.ytimg.com/vi/$searchId/hqdefault.jpg", - totalFiles = 1, - ) - } } catch (e: Exception) { e.printStackTrace() logger.e{"An Error Occurred While Processing!,$searchId"} diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/DI.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/DI.kt index a1a247e7..cf5a2dee 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/DI.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/DI.kt @@ -23,17 +23,16 @@ fun initKoin(enableNetworkLogs: Boolean = false, appDeclaration: KoinAppDeclarat } fun commonModule(enableNetworkLogs: Boolean) = module { - single { Dir(get()) } - single { createDatabase() } + single { createHttpClient(enableNetworkLogs = enableNetworkLogs) } + single { Dir(get(),createDatabase()) } single { Kermit(getLogger()) } single { TokenStore(get(),get()) } single { YoutubeMusic(get(),get()) } - single { SpotifyProvider(get(),get(),get(),get()) } - single { GaanaProvider(get(),get(),get(),get()) } - single { YoutubeProvider(get(),get(),get(),get()) } - single { YoutubeMp3(get(),get(),get(),get()) } + single { SpotifyProvider(get(),get(),get()) } + single { GaanaProvider(get(),get(),get()) } + single { YoutubeProvider(get(),get(),get()) } + single { YoutubeMp3(get(),get(),get()) } single { FetchPlatformQueryResult(get(),get(),get(),get(),get(),get()) } - single { createHttpClient(enableNetworkLogs = enableNetworkLogs) } } val kotlinxSerializer = KotlinxSerializer( Json { diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Dir.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Dir.kt index c0d8e438..8e0b8f08 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Dir.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Dir.kt @@ -1,8 +1,10 @@ package com.shabinder.common.di import co.touchlab.kermit.Kermit +import com.shabinder.common.database.createDatabase import com.shabinder.common.models.DownloadResult import com.shabinder.common.models.TrackDetails +import com.shabinder.database.Database import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* @@ -11,8 +13,10 @@ import kotlinx.coroutines.flow.flow import kotlin.math.roundToInt expect class Dir( - logger: Kermit + logger: Kermit, + database: Database? = createDatabase() ) { + val db :Database? fun isPresent(path:String):Boolean fun fileSeparator(): String fun defaultDir(): String diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/FetchPlatformQueryResult.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/FetchPlatformQueryResult.kt index 5ce5026c..d2be47d7 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/FetchPlatformQueryResult.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/FetchPlatformQueryResult.kt @@ -16,10 +16,10 @@ class FetchPlatformQueryResult( val youtubeProvider: YoutubeProvider, val youtubeMusic: YoutubeMusic, val youtubeMp3: YoutubeMp3, - private val database: Database + private val dir: Dir ) { - private val db:DownloadRecordDatabaseQueries - get() = database.downloadRecordDatabaseQueries + private val db:DownloadRecordDatabaseQueries? + get() = dir.db?.downloadRecordDatabaseQueries suspend fun query(link:String): PlatformQueryResult?{ val result = when{ @@ -41,7 +41,7 @@ class FetchPlatformQueryResult( } result?.run { withContext(Dispatchers.Default){ - db.add( + db?.add( folderType, title, link, coverUrl, trackList.size.toLong() ) } diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/TokenStore.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/TokenStore.kt index 945bd7cf..7c5c7144 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/TokenStore.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/TokenStore.kt @@ -4,25 +4,24 @@ import co.touchlab.kermit.Kermit import com.shabinder.common.database.TokenDBQueries import com.shabinder.common.di.spotify.authenticateSpotify import com.shabinder.common.models.spotify.TokenData -import com.shabinder.database.Database import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.datetime.Clock class TokenStore( - private val tokenDB: Database, + private val dir: Dir, private val logger: Kermit, ) { - private val db: TokenDBQueries - get() = tokenDB.tokenDBQueries + private val db: TokenDBQueries? + get() = dir.db?.tokenDBQueries private fun save(token: TokenData){ if(!token.access_token.isNullOrBlank() && token.expiry != null) - db.add(token.access_token!!, token.expiry!! + Clock.System.now().epochSeconds) + db?.add(token.access_token!!, token.expiry!! + Clock.System.now().epochSeconds) } suspend fun getToken(): TokenData? { - var token: TokenData? = db.select().executeAsOneOrNull()?.let { + var token: TokenData? = db?.select()?.executeAsOneOrNull()?.let { TokenData(it.accessToken,null,it.expiry) } logger.d{"System Time:${Clock.System.now().epochSeconds} , Token Expiry:${token?.expiry}"} diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt index 211355cf..9b378e6a 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt @@ -7,7 +7,6 @@ import io.ktor.client.* expect class YoutubeProvider( httpClient: HttpClient, - database: Database, logger: Kermit, dir: Dir ) { diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/GaanaProvider.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/GaanaProvider.kt index c74ac8f4..dd91a539 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/GaanaProvider.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/GaanaProvider.kt @@ -17,7 +17,6 @@ package com.shabinder.common.di.providers import co.touchlab.kermit.Kermit -import com.shabinder.common.database.DownloadRecordDatabaseQueries import com.shabinder.common.di.Dir import com.shabinder.common.di.finalOutputDir import com.shabinder.common.di.gaana.GaanaRequests @@ -26,21 +25,15 @@ import com.shabinder.common.models.PlatformQueryResult import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.gaana.GaanaTrack import com.shabinder.common.models.spotify.Source -import com.shabinder.database.Database import io.ktor.client.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext class GaanaProvider( override val httpClient: HttpClient, - private val database: Database, private val logger: Kermit, private val dir: Dir, ): GaanaRequests { private val gaanaPlaceholderImageUrl = "https://a10.gaanacdn.com/images/social/gaana_social.jpg" - private val db: DownloadRecordDatabaseQueries - get() = database.downloadRecordDatabaseQueries suspend fun query(fullLink: String): PlatformQueryResult?{ //Link Schema: https://gaana.com/type/link @@ -90,15 +83,6 @@ class GaanaProvider( trackList = listOf(it).toTrackDetailsList(folderType, subFolder) title = it.track_title coverUrl = it.artworkLink - withContext(Dispatchers.Default) { - db.add( - type = "Track", - name = title, - link = "https://gaana.com/$type/$link", - coverUrl = coverUrl, - totalFiles = 1, - ) - } } } "album" -> { @@ -121,15 +105,6 @@ class GaanaProvider( trackList = it.tracks.toTrackDetailsList(folderType, subFolder) title = link coverUrl = it.custom_artworks.size_480p - withContext(Dispatchers.Default) { - db.add( - type = "Album", - name = title, - link = "https://gaana.com/$type/$link", - coverUrl = coverUrl, - totalFiles = trackList.size.toLong(), - ) - } } } "playlist" -> { @@ -153,15 +128,6 @@ class GaanaProvider( title = link //coverUrl.value = "TODO" coverUrl = gaanaPlaceholderImageUrl - withContext(Dispatchers.Default) { - db.add( - type = "Playlist", - name = title, - link = "https://gaana.com/$type/$link", - coverUrl = coverUrl, - totalFiles = it.tracks.size.toLong(), - ) - } } } "artist" -> { @@ -189,15 +155,6 @@ class GaanaProvider( } } trackList = it.tracks?.toTrackDetailsList(folderType, subFolder) ?: emptyList() - withContext(Dispatchers.Default) { - db.add( - type = "Artist", - name = artistDetails?.name ?: link, - link = "https://gaana.com/$type/$link", - coverUrl = coverUrl, - totalFiles = trackList.size.toLong(), - ) - } } } else -> {//TODO Handle Error} diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt index 756dec09..3e3de8ce 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt @@ -17,7 +17,6 @@ package com.shabinder.common.di.providers import co.touchlab.kermit.Kermit -import com.shabinder.common.database.DownloadRecordDatabaseQueries import com.shabinder.common.di.* import com.shabinder.common.di.spotify.SpotifyRequests import com.shabinder.common.models.PlatformQueryResult @@ -26,7 +25,6 @@ import com.shabinder.common.models.spotify.Album import com.shabinder.common.models.spotify.Image import com.shabinder.common.models.spotify.Source import com.shabinder.common.models.spotify.Track -import com.shabinder.database.Database import io.ktor.client.* import io.ktor.client.features.* import io.ktor.client.features.json.* @@ -34,18 +32,16 @@ import io.ktor.client.request.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class SpotifyProvider( private val tokenStore: TokenStore, - private val database: Database, private val logger: Kermit, private val dir: Dir, ) : SpotifyRequests { init { logger.d { "Creating Spotify Provider" } - GlobalScope.launch(Dispatchers.Default) {authenticateSpotify()} + //GlobalScope.launch(Dispatchers.Default) {authenticateSpotify()} } override suspend fun authenticateSpotify(): HttpClient?{ @@ -70,9 +66,6 @@ class SpotifyProvider( override lateinit var httpClient: HttpClient - private val db:DownloadRecordDatabaseQueries - get() = database.downloadRecordDatabaseQueries - suspend fun query(fullLink: String): PlatformQueryResult?{ if(!this::httpClient.isInitialized){ @@ -139,15 +132,6 @@ class SpotifyProvider( title = it.name.toString() coverUrl = (it.album?.images?.elementAtOrNull(1)?.url ?: it.album?.images?.elementAtOrNull(0)?.url).toString() - withContext(Dispatchers.Default) { - db.add( - type = "Track", - name = title, - link = "https://open.spotify.com/$type/$link", - coverUrl = coverUrl, - totalFiles = 1, - ) - } } } @@ -184,15 +168,6 @@ class SpotifyProvider( title = albumObject.name.toString() coverUrl = (albumObject.images?.elementAtOrNull(1)?.url ?: albumObject.images?.elementAtOrNull(0)?.url).toString() - withContext(Dispatchers.Default) { - db.add( - type = "Album", - name = title, - link = "https://open.spotify.com/$type/$link", - coverUrl = coverUrl, - totalFiles = trackList.size.toLong(), - ) - } } } } @@ -235,15 +210,6 @@ class SpotifyProvider( title = playlistObject.name.toString() coverUrl = playlistObject.images?.elementAtOrNull(1)?.url ?: playlistObject.images?.firstOrNull()?.url.toString() - withContext(Dispatchers.Default) { - db.add( - type = "Playlist", - name = title, - link = "https://open.spotify.com/$type/$link", - coverUrl = coverUrl, - totalFiles = tempTrackList.size.toLong(), - ) - } } "episode" -> {//TODO } diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt index 84f93048..4cd87a71 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt @@ -8,7 +8,6 @@ import io.ktor.client.* class YoutubeMp3( override val httpClient: HttpClient, - private val database: Database, private val logger: Kermit, private val dir: Dir, ):Yt1sMp3 { diff --git a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopDir.kt b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopDir.kt index 5cdb70a2..0920751e 100644 --- a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopDir.kt +++ b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopDir.kt @@ -5,6 +5,7 @@ import androidx.compose.ui.graphics.asImageBitmap import co.touchlab.kermit.Kermit import com.mpatric.mp3agic.Mp3File import com.shabinder.common.models.TrackDetails +import com.shabinder.database.Database import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -21,7 +22,10 @@ import javax.imageio.ImageIO -actual class Dir actual constructor(private val logger: Kermit) { +actual class Dir actual constructor( + private val logger: Kermit, + private val database: Database?, + ) { init { createDirectories() @@ -120,6 +124,9 @@ actual class Dir actual constructor(private val logger: Kermit) { null } } + + actual val db: Database? + get() = database } fun BufferedImage.toImageBitmap() = Image.makeFromEncoded( toByteArray(this) diff --git a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt index dbe36369..6a5a0713 100644 --- a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt +++ b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt @@ -18,19 +18,14 @@ package com.shabinder.common.di import co.touchlab.kermit.Kermit import com.github.kiulian.downloader.YoutubeDownloader -import com.shabinder.common.database.DownloadRecordDatabaseQueries import com.shabinder.common.models.DownloadStatus import com.shabinder.common.models.PlatformQueryResult import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.spotify.Source -import com.shabinder.database.Database import io.ktor.client.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext actual class YoutubeProvider actual constructor( private val httpClient: HttpClient, - private val database: Database, private val logger: Kermit, private val dir: Dir, ){ @@ -45,9 +40,6 @@ actual class YoutubeProvider actual constructor( private val sampleDomain2 = "youtube.com" private val sampleDomain3 = "youtu.be" - private val db: DownloadRecordDatabaseQueries - get() = database.downloadRecordDatabaseQueries - actual suspend fun query(fullLink: String): PlatformQueryResult?{ val link = fullLink.removePrefix("https://").removePrefix("http://") if(link.contains("playlist",true) || link.contains("list",true)){ @@ -130,22 +122,6 @@ actual class YoutubeProvider actual constructor( videoID = it.videoId() ) } - - withContext(Dispatchers.IO) { - db.add( - type = "PlayList", - name = if (name.length > 17) { - "${name.subSequence(0, 16)}..." - } else { - name - }, - link = "https://www.youtube.com/playlist?list=$searchId", - coverUrl = "https://i.ytimg.com/vi/${ - videos.firstOrNull()?.videoId() - }/hqdefault.jpg", - totalFiles = videos.size.toLong(), - ) - } } catch (e: Exception) { e.printStackTrace() logger.d{"An Error Occurred While Processing!"} @@ -201,20 +177,6 @@ actual class YoutubeProvider actual constructor( ) ) title = name - - withContext(Dispatchers.IO) { - db.add( - type = "Track", - name = if (name.length > 17) { - "${name.subSequence(0, 16)}..." - } else { - name - }, - link = "https://www.youtube.com/watch?v=$searchId", - coverUrl = "https://i.ytimg.com/vi/$searchId/hqdefault.jpg", - totalFiles = 1, - ) - } } catch (e: Exception) { e.printStackTrace() logger.e{"An Error Occurred While Processing!,$searchId"} diff --git a/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/WebDir.kt b/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/WebDir.kt index b2ea609b..6b523f76 100644 --- a/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/WebDir.kt +++ b/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/WebDir.kt @@ -2,9 +2,13 @@ package com.shabinder.common.di import co.touchlab.kermit.Kermit import com.shabinder.common.models.TrackDetails +import com.shabinder.database.Database import org.w3c.dom.ImageBitmap -actual class Dir actual constructor(private val logger: Kermit) { +actual class Dir actual constructor( + private val logger: Kermit, + private val database: Database?, +) { /*init { createDirectories() @@ -51,4 +55,7 @@ actual class Dir actual constructor(private val logger: Kermit) { private suspend fun freshImage(url:String): ImageBitmap?{ return null } + + actual val db: Database? + get() = database } diff --git a/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt b/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt index 1125425b..abf7b0b9 100644 --- a/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt +++ b/common/dependency-injection/src/jsMain/kotlin/com/shabinder/common/di/YoutubeProvider.kt @@ -7,7 +7,6 @@ import io.ktor.client.* actual class YoutubeProvider actual constructor( httpClient: HttpClient, - database: Database, logger: Kermit, dir: Dir ) { diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt index 4d05d03e..8c5dd18a 100644 --- a/desktop/src/jvmMain/kotlin/Main.kt +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -48,9 +48,9 @@ private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = componentContext = componentContext, dependencies = object : SpotiFlyerRoot.Dependencies { override val storeFactory = DefaultStoreFactory - override val database: Database? = koin.get() override val fetchPlatformQueryResult: FetchPlatformQueryResult = koin.get() override val directories: Dir = koin.get() + override val database: Database? = directories.db override val showPopUpMessage: (String) -> Unit = ::uikitShowPopUpMessage override val downloadProgressReport = DownloadProgressFlow } diff --git a/web-app/src/main/kotlin/App.kt b/web-app/src/main/kotlin/App.kt index 77bbb440..8f44ccff 100644 --- a/web-app/src/main/kotlin/App.kt +++ b/web-app/src/main/kotlin/App.kt @@ -34,9 +34,9 @@ class App(props: AppProps): RComponent(props) { private val root = SpotiFlyerRoot(ctx, object : SpotiFlyerRoot.Dependencies{ override val storeFactory: StoreFactory = DefaultStoreFactory - override val database: Database? = null override val fetchPlatformQueryResult = dependencies.fetchPlatformQueryResult override val directories = dependencies.directories + override val database: Database? = directories.db override val showPopUpMessage: (String) -> Unit = {}//TODO override val downloadProgressReport: MutableSharedFlow> = MutableSharedFlow(1) diff --git a/web-app/src/main/kotlin/client.kt b/web-app/src/main/kotlin/client.kt index bd57486a..4c93919d 100644 --- a/web-app/src/main/kotlin/client.kt +++ b/web-app/src/main/kotlin/client.kt @@ -20,7 +20,6 @@ fun main() { } } - object AppDependencies : KoinComponent { val logger: Kermit val directories: Dir