Skip to content

Commit

Permalink
Changed YoutubeExtractor (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
doGior authored Jan 21, 2025
1 parent cfc219c commit 1436c15
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}

Expand All @@ -32,7 +33,7 @@ open class YoutubeExtractor : ExtractorApi() {
override val name = "YouTube"

companion object {
private var ytVideos: MutableMap<String, List<VideoStream>> = mutableMapOf()
private var ytVideos: MutableMap<String, String> = mutableMapOf()
private var ytVideosSubtitles: MutableMap<String, List<SubtitlesStream>> = mutableMapOf()
}

Expand Down Expand Up @@ -61,27 +62,33 @@ open class YoutubeExtractor : ExtractorApi() {

}
s.fetchPage()
ytVideos[url] = s.videoStreams
ytVideos[url] = s.hlsUrl

ytVideosSubtitles[url] = try {
s.subtitlesDefault.filterNotNull()
} catch (e: Exception) {
logError(e)
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)
}
}
}

0 comments on commit 1436c15

Please sign in to comment.