Skip to content

Commit

Permalink
Use MainAPI to get folder prefix (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna712 authored Jan 15, 2025
1 parent f1b95ff commit eb9b309
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
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

0 comments on commit eb9b309

Please sign in to comment.