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

Use MainAPI to get folder prefix #1472

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
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 @@ -635,26 +635,10 @@ class ResultViewModel2 : ViewModel() {
}

private fun getFolder(currentType: TvType, titleName: String): String {
val sanitizedFileName = VideoDownloadManager.sanitizeFilename(titleName)
return when (currentType) {
TvType.Anime -> "Anime/$sanitizedFileName"
TvType.AnimeMovie -> "Movies"
TvType.AsianDrama -> "AsianDramas/$sanitizedFileName"
TvType.Audio -> "Audio"
TvType.AudioBook -> "AudioBooks"
TvType.Cartoon -> "Cartoons/$sanitizedFileName"
TvType.CustomMedia -> "Media"
TvType.Documentary -> "Documentaries"
TvType.Live -> "LiveStreams"
TvType.Movie -> "Movies"
TvType.Music -> "Music"
TvType.NSFW -> "NSFW"
TvType.OVA -> "OVAs"
TvType.Others -> "Others"
TvType.Podcast -> "Podcasts"
TvType.Torrent -> "Torrents"
TvType.TvSeries -> "TVSeries/$sanitizedFileName"
}
return if (currentType.isEpisodeBased()) {
val sanitizedFileName = VideoDownloadManager.sanitizeFilename(titleName)
"${currentType.getFolderPrefix()}/$sanitizedFileName"
} else currentType.getFolderPrefix()
}

private fun downloadSubtitle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,13 @@ fun LoadResponse?.isAnimeBased(): Boolean {
return (this.type == TvType.Anime || this.type == TvType.OVA) // && (this is AnimeLoadResponse)
}

/** Extension function of [TvType] to check if it's Episode based.
* @return True if the response type is Anime, AsianDrama, Cartoon or TvSeries.
* @see TvType
* */
/**
* Extension function to determine if the [TvType] is episode-based.
* This function checks if the type corresponds to an episode-based format. Episode-based types will be placed
* in subfolders that include the sanitized title name. This check is used for other logic as well.
*
* @return true if the [TvType] is episode-based, otherwise false.
*/
fun TvType?.isEpisodeBased(): Boolean {
return when (this) {
TvType.Anime,
Expand All @@ -1519,6 +1522,39 @@ fun TvType?.isEpisodeBased(): Boolean {
}
}

/**
* Extension function to get the folder prefix based on the [TvType].
* Non-episode-based types will return a base folder name, while episode-based types will
* have their files placed in subfolders using a sanitized title name.
*
* For the actual folder path, refer to `ResultViewModel2().getFolder()`, which combines
* the folder prefix and, if necessary, the sanitized name to a sub-folder. The folder prefix
* will be used in the root directory of the configured downloads directory.
*
* @return the folder prefix corresponding to the [TvType], which is used as the root directory.
*/
fun TvType.getFolderPrefix(): String {
return when (this) {
TvType.Anime -> "Anime"
TvType.AnimeMovie -> "Movies"
TvType.AsianDrama -> "AsianDramas"
TvType.Audio -> "Audio"
TvType.AudioBook -> "AudioBooks"
TvType.Cartoon -> "Cartoons"
TvType.CustomMedia -> "Media"
TvType.Documentary -> "Documentaries"
TvType.Live -> "LiveStreams"
TvType.Movie -> "Movies"
TvType.Music -> "Music"
TvType.NSFW -> "NSFW"
TvType.OVA -> "OVAs"
TvType.Others -> "Others"
TvType.Podcast -> "Podcasts"
TvType.Torrent -> "Torrents"
TvType.TvSeries -> "TVSeries"
}
}

/** Data class holds next airing Episode info.
* @param episode Next airing Episode number.
* @param unixTime Next airing Time in Unix time format.
Expand Down
Loading