Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed YoutubeExtractor #1496

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Loading