From 1436c15113ae2a9f267d7e1c1bd35fff1f75301e Mon Sep 17 00:00:00 2001 From: Riccardo Giordano <43815981+doGior@users.noreply.github.com> Date: Tue, 21 Jan 2025 22:11:17 +0100 Subject: [PATCH] Changed YoutubeExtractor (#1496) --- .../extractors/YoutubeExtractor.kt | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt index 4e854630f..e6abfaea6 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt @@ -4,12 +4,12 @@ import com.lagradost.cloudstream3.SubtitleFile import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.utils.ExtractorApi import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.schemaStripRegex import org.schabi.newpipe.extractor.ServiceList import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory import org.schabi.newpipe.extractor.stream.SubtitlesStream -import org.schabi.newpipe.extractor.stream.VideoStream class YoutubeShortLinkExtractor : YoutubeExtractor() { override val mainUrl = "https://youtu.be" @@ -19,10 +19,11 @@ class YoutubeShortLinkExtractor : YoutubeExtractor() { } } -class YoutubeMobileExtractor : YoutubeExtractor() { +class YoutubeMobileExtractor : YoutubeExtractor() { override val mainUrl = "https://m.youtube.com" } -class YoutubeNoCookieExtractor : YoutubeExtractor() { + +class YoutubeNoCookieExtractor : YoutubeExtractor() { override val mainUrl = "https://www.youtube-nocookie.com" } @@ -32,7 +33,7 @@ open class YoutubeExtractor : ExtractorApi() { override val name = "YouTube" companion object { - private var ytVideos: MutableMap> = mutableMapOf() + private var ytVideos: MutableMap = mutableMapOf() private var ytVideosSubtitles: MutableMap> = mutableMapOf() } @@ -61,7 +62,8 @@ open class YoutubeExtractor : ExtractorApi() { } s.fetchPage() - ytVideos[url] = s.videoStreams + ytVideos[url] = s.hlsUrl + ytVideosSubtitles[url] = try { s.subtitlesDefault.filterNotNull() } catch (e: Exception) { @@ -69,19 +71,24 @@ open class YoutubeExtractor : ExtractorApi() { emptyList() } } - ytVideos[url]?.mapNotNull { - if (it.isVideoOnly() || it.height <= 0) return@mapNotNull null - - ExtractorLink( - this.name, - this.name, - it.content ?: return@mapNotNull null, - "", - it.height + ytVideos[url]?.let { + callback( + ExtractorLink( + this.name, + this.name, + it, + "", + Qualities.Unknown.value, + isM3u8 = true + ) ) - }?.forEach(callback) + } + ytVideosSubtitles[url]?.mapNotNull { - SubtitleFile(it.languageTag ?: return@mapNotNull null, it.content ?: return@mapNotNull null) + SubtitleFile( + it.languageTag ?: return@mapNotNull null, + it.content ?: return@mapNotNull null + ) }?.forEach(subtitleCallback) } -} \ No newline at end of file +}