diff --git a/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YoutubeProvider.kt b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YoutubeProvider.kt index 444d11df..3caccd31 100644 --- a/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YoutubeProvider.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YoutubeProvider.kt @@ -22,6 +22,7 @@ import com.beust.klaxon.JsonArray import com.beust.klaxon.JsonObject import com.beust.klaxon.Parser import com.shabinder.spotiflyer.models.YoutubeTrack +import com.shabinder.spotiflyer.utils.log import me.xdrop.fuzzywuzzy.FuzzySearch import kotlin.math.absoluteValue @@ -119,15 +120,20 @@ fun getYTTracks(response: String):List{ if(detail.obj("musicResponsiveListItemFlexColumnRenderer")?.size!! < 2) continue // if not a dummy, collect All Variables - detail.obj("musicResponsiveListItemFlexColumnRenderer") + val details = detail.obj("musicResponsiveListItemFlexColumnRenderer") ?.obj("text") - ?.array("runs")?.get(0)?.get("text")?.let { - availableDetails.add( - it.toString() - ) + ?.array("runs") ?: listOf() + for (d in details){ + d["text"]?.let { + if(it.toString() != " • "){ + availableDetails.add( + it.toString() + ) + } } + } } - //log("Text Api",availableDetails.toString()) +// log("YT Music details",availableDetails.toString()) /* ! Filter Out non-Song/Video results and incomplete results here itself ! From what we know about detail order, note that [1] - indicate result type @@ -135,7 +141,7 @@ fun getYTTracks(response: String):List{ if ( availableDetails.size == 5 && availableDetails[1] in listOf("Song","Video") ){ // skip if result is in hours instead of minutes (no song is that long) - if(availableDetails[4].split(':').size != 2) continue //Has Been Giving Issues + if(availableDetails[4].split(':').size != 2) continue /* ! grab Video ID @@ -145,7 +151,7 @@ fun getYTTracks(response: String):List{ ! reference the dict keys by index */ - val videoId:String = result.last().obj("watchEndpoint")?.get("videoId") as String + val videoId:String? = result.last().obj("watchEndpoint")?.get("videoId") as String? val ytTrack = YoutubeTrack( name = availableDetails[0], type = availableDetails[1], @@ -154,10 +160,11 @@ fun getYTTracks(response: String):List{ videoId = videoId ) youtubeTracks.add(ytTrack) + } } } - + log("YT Search",youtubeTracks.joinToString(" abc \n")) return youtubeTracks } diff --git a/app/src/main/java/com/shabinder/spotiflyer/worker/ForegroundService.kt b/app/src/main/java/com/shabinder/spotiflyer/worker/ForegroundService.kt index 398028f0..60212514 100644 --- a/app/src/main/java/com/shabinder/spotiflyer/worker/ForegroundService.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/worker/ForegroundService.kt @@ -190,6 +190,7 @@ class ForegroundService : Service(){ trackDurationSec = it.durationSec ).keys.firstOrNull() log("Service VideoID", videoId ?: "Not Found") + //println(response.body().toString()) if (videoId.isNullOrBlank()) { sendTrackBroadcast(Status.FAILED.name, it) failed++