Skip to content

Commit 3d9f3bf

Browse files
authored
Fixes from 16-rc1 (#2142)
1 parent b8b48b0 commit 3d9f3bf

File tree

7 files changed

+97
-121
lines changed

7 files changed

+97
-121
lines changed

app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerViewModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,9 @@ class PlayerViewModel @JvmOverloads constructor(
12931293
getHosterVideoLinksJob = viewModelScope.launchIO {
12941294
_hosterState.update { _ ->
12951295
hosterList.map { hoster ->
1296-
if (hoster.videoList == null) {
1296+
if (hoster.lazy) {
1297+
HosterState.Idle(hoster.hosterName)
1298+
} else if (hoster.videoList == null) {
12971299
HosterState.Loading(hoster.hosterName)
12981300
} else {
12991301
val videoList = hoster.videoList!!
@@ -1468,7 +1470,11 @@ class PlayerViewModel @JvmOverloads constructor(
14681470
_hosterState.updateAt(index, HosterState.Loading(hosterName))
14691471

14701472
viewModelScope.launchIO {
1471-
val hosterState = EpisodeLoader.loadHosterVideos(currentSource.value!!, hosterList.value[index])
1473+
val hosterState = EpisodeLoader.loadHosterVideos(
1474+
source = currentSource.value!!,
1475+
hoster = hosterList.value[index],
1476+
force = true,
1477+
)
14721478
_hosterState.updateAt(index, hosterState)
14731479
}
14741480
}

app/src/main/java/eu/kanade/tachiyomi/ui/player/loader/EpisodeLoader.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ class EpisodeLoader {
6464
*/
6565
private suspend fun getHostersOnHttp(episode: Episode, source: AnimeHttpSource): List<Hoster> {
6666
// TODO(1.6): Remove else block when dropping support for ext lib <1.6
67-
return if (source.javaClass.declaredMethods.any { it.name == "getHosterList" }) {
67+
return if (source.javaClass.declaredMethods.any {
68+
it.name in
69+
listOf("getHosterList", "hosterListRequest", "hosterListParse")
70+
}
71+
) {
6872
source.getHosterList(episode.toSEpisode())
6973
.let { source.run { it.sortHosters() } }
7074
} else {
@@ -130,12 +134,18 @@ class EpisodeLoader {
130134
* @param hoster the hoster.
131135
*/
132136
private suspend fun getVideos(source: AnimeSource, hoster: Hoster): List<Video> {
133-
return when {
137+
val videos = when {
134138
hoster.videoList != null && source is AnimeHttpSource -> hoster.videoList!!.parseVideoUrls(source)
135139
hoster.videoList != null -> hoster.videoList!!
136140
source is AnimeHttpSource -> getVideosOnHttp(source, hoster)
137141
else -> error("source not supported")
138142
}
143+
144+
return if (source is AnimeHttpSource) {
145+
source.run { videos.sortVideos() }
146+
} else {
147+
videos
148+
}
139149
}
140150

141151
/**
@@ -146,7 +156,6 @@ class EpisodeLoader {
146156
*/
147157
private suspend fun getVideosOnHttp(source: AnimeHttpSource, hoster: Hoster): List<Video> {
148158
return source.getVideoList(hoster)
149-
.let { source.run { it.sortVideos() } }
150159
.parseVideoUrls(source)
151160
}
152161

@@ -160,7 +169,11 @@ class EpisodeLoader {
160169
}
161170
}
162171

163-
suspend fun loadHosterVideos(source: AnimeSource, hoster: Hoster): HosterState {
172+
suspend fun loadHosterVideos(source: AnimeSource, hoster: Hoster, force: Boolean = false): HosterState {
173+
if (!force && hoster.lazy) {
174+
return HosterState.Idle(hoster.hosterName)
175+
}
176+
164177
return try {
165178
val videos = getVideos(source, hoster)
166179
HosterState.Ready(hoster.hosterName, videos, List(videos.size) { Video.State.QUEUE })

core/common/src/main/java/eu/kanade/tachiyomi/network/Requests.kt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import okhttp3.FormBody
77
import okhttp3.Headers
88
import okhttp3.HttpUrl
99
import okhttp3.HttpUrl.Companion.toHttpUrl
10+
import okhttp3.OkHttpClient
1011
import okhttp3.Request
1112
import okhttp3.RequestBody
13+
import okhttp3.Response
1214
import java.util.concurrent.TimeUnit.MINUTES
1315

1416
private val DEFAULT_CACHE_CONTROL = CacheControl.Builder().maxAge(10, MINUTES).build()
@@ -79,3 +81,56 @@ fun DELETE(
7981
.cacheControl(cache)
8082
.build()
8183
}
84+
85+
/**
86+
* Send a GET request
87+
*
88+
* @since extensions-lib 16
89+
*
90+
* @param url [String] the url to send the request to
91+
* @param headers [Headers] the request headers, defaults to the headers generated by HttpSource.headersBuilder()
92+
* @param cache [CacheControl] the cache used, defaults to the one provided by the app
93+
*/
94+
suspend fun OkHttpClient.get(
95+
url: String,
96+
headers: Headers = DEFAULT_HEADERS,
97+
cache: CacheControl = DEFAULT_CACHE_CONTROL,
98+
): Response {
99+
return newCall(GET(url, headers, cache)).awaitSuccess()
100+
}
101+
102+
/**
103+
* Send a GET request
104+
*
105+
* @since extensions-lib 16
106+
*
107+
* @param url [HttpUrl] the url to send the request to
108+
* @param headers [Headers] the request headers, defaults to the headers generated by HttpSource.headersBuilder()
109+
* @param cache [CacheControl] the cache used, defaults to the one provided by the app
110+
*/
111+
suspend fun OkHttpClient.get(
112+
url: HttpUrl,
113+
headers: Headers = DEFAULT_HEADERS,
114+
cache: CacheControl = DEFAULT_CACHE_CONTROL,
115+
): Response {
116+
return newCall(GET(url, headers, cache)).awaitSuccess()
117+
}
118+
119+
/**
120+
* Send a POST request
121+
*
122+
* @since extensions-lib 16
123+
*
124+
* @param url [String] the url to send the request to
125+
* @param headers [Headers] the request headers, defaults to the headers generated by HttpSource.headersBuilder()
126+
* @param body [RequestBody] the request body, defaults to the one provided by the app
127+
* @param cache [CacheControl] the cache used, defaults to the one provided by the app
128+
*/
129+
suspend fun OkHttpClient.post(
130+
url: String,
131+
headers: Headers = DEFAULT_HEADERS,
132+
body: RequestBody = DEFAULT_BODY,
133+
cache: CacheControl = DEFAULT_CACHE_CONTROL,
134+
): Response {
135+
return newCall(POST(url, headers, body, cache)).awaitSuccess()
136+
}

gradle/kotlinx.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
2-
kotlin_version = "2.1.10"
3-
serialization_version = "1.8.0"
2+
kotlin_version = "2.2.0"
3+
serialization_version = "1.9.0"
44
xml_serialization_version = "0.90.3"
55

66
[libraries]
@@ -29,4 +29,4 @@ serialization = ["serialization-json", "serialization-json-okio", "serialization
2929
[plugins]
3030
android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin_version" }
3131
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin_version" }
32-
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin_version" }
32+
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin_version" }

source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/animesource/model/Hoster.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open class Hoster(
1111
val hosterName: String = "",
1212
val videoList: List<Video>? = null,
1313
val internalData: String = "",
14+
val lazy: Boolean = false,
1415
) {
1516
@Transient
1617
@Volatile
@@ -28,8 +29,9 @@ open class Hoster(
2829
hosterName: String = this.hosterName,
2930
videoList: List<Video>? = this.videoList,
3031
internalData: String = this.internalData,
32+
lazy: Boolean = this.lazy,
3133
): Hoster {
32-
return Hoster(hosterUrl, hosterName, videoList, internalData)
34+
return Hoster(hosterUrl, hosterName, videoList, internalData, lazy)
3335
}
3436

3537
companion object {
@@ -53,6 +55,7 @@ data class SerializableHoster(
5355
val hosterName: String = "",
5456
val videoList: String? = null,
5557
val internalData: String = "",
58+
val lazy: Boolean = false,
5659
) {
5760
companion object {
5861
fun List<Hoster>.serialize(): String =
@@ -63,6 +66,7 @@ data class SerializableHoster(
6366
host.hosterName,
6467
host.videoList?.serialize(),
6568
host.internalData,
69+
host.lazy,
6670
)
6771
},
6872
)
@@ -75,6 +79,7 @@ data class SerializableHoster(
7579
sHost.hosterName,
7680
sHost.videoList?.toVideoList(),
7781
sHost.internalData,
82+
sHost.lazy,
7883
)
7984
}
8085
}

source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/animesource/model/Video.kt

Lines changed: 7 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data class TimeStamp(
2626
val type: ChapterType = ChapterType.Other,
2727
)
2828

29-
open class Video(
29+
data class Video(
3030
var videoUrl: String = "",
3131
val videoTitle: String = "",
3232
val resolution: Int? = null,
@@ -41,8 +41,6 @@ open class Video(
4141
val ffmpegVideoArgs: List<Pair<String, String>> = emptyList(),
4242
val internalData: String = "",
4343
val initialized: Boolean = false,
44-
// TODO(1.6): Remove after ext lib bump
45-
val videoPageUrl: String = "",
4644
) {
4745

4846
// TODO(1.6): Remove after ext lib bump
@@ -51,10 +49,12 @@ open class Video(
5149
get() = videoTitle
5250

5351
// TODO(1.6): Remove after ext lib bump
54-
@Deprecated("Use videoPageUrl instead", ReplaceWith("videoPageUrl"))
5552
val url: String
5653
get() = videoPageUrl
5754

55+
// TODO(1.6): Remove after ext lib bump
56+
private var videoPageUrl: String = ""
57+
5858
// TODO(1.6): Remove after ext lib bump
5959
constructor(
6060
url: String,
@@ -64,45 +64,14 @@ open class Video(
6464
subtitleTracks: List<Track> = emptyList(),
6565
audioTracks: List<Track> = emptyList(),
6666
) : this(
67-
videoPageUrl = url,
6867
videoTitle = quality,
6968
videoUrl = videoUrl ?: "null",
7069
headers = headers,
7170
subtitleTracks = subtitleTracks,
7271
audioTracks = audioTracks,
73-
)
74-
75-
// TODO(1.6): Remove after ext lib bump
76-
constructor(
77-
videoUrl: String = "",
78-
videoTitle: String = "",
79-
resolution: Int? = null,
80-
bitrate: Int? = null,
81-
headers: Headers? = null,
82-
preferred: Boolean = false,
83-
subtitleTracks: List<Track> = emptyList(),
84-
audioTracks: List<Track> = emptyList(),
85-
timestamps: List<TimeStamp> = emptyList(),
86-
mpvArgs: List<Pair<String, String>> = emptyList(),
87-
ffmpegStreamArgs: List<Pair<String, String>> = emptyList(),
88-
ffmpegVideoArgs: List<Pair<String, String>> = emptyList(),
89-
internalData: String = "",
90-
) : this(
91-
videoUrl = videoUrl,
92-
videoTitle = videoTitle,
93-
resolution = resolution,
94-
bitrate = bitrate,
95-
headers = headers,
96-
preferred = preferred,
97-
subtitleTracks = subtitleTracks,
98-
audioTracks = audioTracks,
99-
timestamps = timestamps,
100-
mpvArgs = mpvArgs,
101-
ffmpegStreamArgs = ffmpegStreamArgs,
102-
ffmpegVideoArgs = ffmpegVideoArgs,
103-
internalData = internalData,
104-
videoPageUrl = "",
105-
)
72+
) {
73+
this.videoPageUrl = url
74+
}
10675

10776
// TODO(1.6): Remove after ext lib bump
10877
@Suppress("UNUSED_PARAMETER")
@@ -121,74 +90,6 @@ open class Video(
12190
field = value
12291
}
12392

124-
fun copy(
125-
videoUrl: String = this.videoUrl,
126-
videoTitle: String = this.videoTitle,
127-
resolution: Int? = this.resolution,
128-
bitrate: Int? = this.bitrate,
129-
headers: Headers? = this.headers,
130-
preferred: Boolean = this.preferred,
131-
subtitleTracks: List<Track> = this.subtitleTracks,
132-
audioTracks: List<Track> = this.audioTracks,
133-
timestamps: List<TimeStamp> = this.timestamps,
134-
mpvArgs: List<Pair<String, String>> = this.mpvArgs,
135-
ffmpegStreamArgs: List<Pair<String, String>> = this.ffmpegStreamArgs,
136-
ffmpegVideoArgs: List<Pair<String, String>> = this.ffmpegVideoArgs,
137-
internalData: String = this.internalData,
138-
): Video {
139-
return Video(
140-
videoUrl = videoUrl,
141-
videoTitle = videoTitle,
142-
resolution = resolution,
143-
bitrate = bitrate,
144-
headers = headers,
145-
preferred = preferred,
146-
subtitleTracks = subtitleTracks,
147-
audioTracks = audioTracks,
148-
timestamps = timestamps,
149-
mpvArgs = mpvArgs,
150-
ffmpegStreamArgs = ffmpegStreamArgs,
151-
ffmpegVideoArgs = ffmpegVideoArgs,
152-
internalData = internalData,
153-
)
154-
}
155-
156-
fun copy(
157-
videoUrl: String = this.videoUrl,
158-
videoTitle: String = this.videoTitle,
159-
resolution: Int? = this.resolution,
160-
bitrate: Int? = this.bitrate,
161-
headers: Headers? = this.headers,
162-
preferred: Boolean = this.preferred,
163-
subtitleTracks: List<Track> = this.subtitleTracks,
164-
audioTracks: List<Track> = this.audioTracks,
165-
timestamps: List<TimeStamp> = this.timestamps,
166-
mpvArgs: List<Pair<String, String>> = this.mpvArgs,
167-
ffmpegStreamArgs: List<Pair<String, String>> = this.ffmpegStreamArgs,
168-
ffmpegVideoArgs: List<Pair<String, String>> = this.ffmpegVideoArgs,
169-
internalData: String = this.internalData,
170-
initialized: Boolean = this.initialized,
171-
videoPageUrl: String = this.videoPageUrl,
172-
): Video {
173-
return Video(
174-
videoUrl = videoUrl,
175-
videoTitle = videoTitle,
176-
resolution = resolution,
177-
bitrate = bitrate,
178-
headers = headers,
179-
preferred = preferred,
180-
subtitleTracks = subtitleTracks,
181-
audioTracks = audioTracks,
182-
timestamps = timestamps,
183-
mpvArgs = mpvArgs,
184-
ffmpegStreamArgs = ffmpegStreamArgs,
185-
ffmpegVideoArgs = ffmpegVideoArgs,
186-
internalData = internalData,
187-
initialized = initialized,
188-
videoPageUrl = videoPageUrl,
189-
)
190-
}
191-
19293
enum class State {
19394
QUEUE,
19495
LOAD_VIDEO,
@@ -217,8 +118,6 @@ data class SerializableVideo(
217118
val ffmpegVideoArgs: List<Pair<String, String>> = emptyList(),
218119
val internalData: String = "",
219120
val initialized: Boolean = false,
220-
// TODO(1.6): Remove after ext lib bump
221-
val videoPageUrl: String = "",
222121
) {
223122

224123
companion object {
@@ -240,7 +139,6 @@ data class SerializableVideo(
240139
vid.ffmpegVideoArgs,
241140
vid.internalData,
242141
vid.initialized,
243-
vid.videoPageUrl,
244142
)
245143
},
246144
)
@@ -265,7 +163,6 @@ data class SerializableVideo(
265163
sVid.ffmpegVideoArgs,
266164
sVid.internalData,
267165
sVid.initialized,
268-
sVid.videoPageUrl,
269166
)
270167
}
271168
}

source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/animesource/online/AnimeHttpSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource {
469469
* @param video the chapter whose page list has to be fetched
470470
*/
471471
protected open fun videoUrlRequest(video: Video): Request {
472-
return GET(video.videoPageUrl, headers)
472+
return GET(video.url, headers)
473473
}
474474

475475
/**

0 commit comments

Comments
 (0)