-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
105 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="debug"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
<logger name="org.eclipse.jetty" level="INFO"/> | ||
<logger name="io.netty" level="INFO"/> | ||
</configuration> |
70 changes: 12 additions & 58 deletions
70
server/src/main/kotlin/io/github/jsixface/codexvert/api/VideoApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,27 @@ | ||
package io.github.jsixface.codexvert.api | ||
|
||
import io.github.jsixface.codexvert.db.IVideoFilesRepo | ||
import io.github.jsixface.codexvert.ffprobe.IParser | ||
import io.github.jsixface.codexvert.logger | ||
import io.github.jsixface.codexvert.utils.CodecUtils.parseMediaInfo | ||
import io.github.jsixface.common.TrackType | ||
import io.github.jsixface.codexvert.utils.toVideoFile | ||
import io.github.jsixface.common.VideoFile | ||
import kotlin.io.path.Path | ||
import kotlin.io.path.PathWalkOption | ||
import kotlin.io.path.extension | ||
import kotlin.io.path.getLastModifiedTime | ||
import kotlin.io.path.isDirectory | ||
import kotlin.io.path.name | ||
import kotlin.io.path.pathString | ||
import kotlin.io.path.walk | ||
import java.nio.file.Path | ||
|
||
typealias VideoList = Map<String, VideoFile> | ||
typealias VideoList = List<VideoFile> | ||
|
||
|
||
class VideoApi { | ||
class VideoApi(private val parser: IParser, private val repo: IVideoFilesRepo) { | ||
|
||
private val logger = logger() | ||
|
||
fun refreshDirs(): Boolean { | ||
suspend fun refreshDirs(): Boolean { | ||
logger.info("Refreshing videos...") | ||
val data = SavedData.load() | ||
val scan = mutableMapOf<String, VideoFile>() | ||
data.settings.libraryLocations.forEach { l -> | ||
val loc = Path(l) | ||
loc.walk(PathWalkOption.FOLLOW_LINKS).forEach { p -> | ||
if (p.isDirectory().not() && data.settings.videoExtensions.contains(p.extension.lowercase())) { | ||
scan[p.pathString] = VideoFile( | ||
path = p.pathString, | ||
fileName = p.name, | ||
modifiedTime = p.getLastModifiedTime().toMillis() | ||
) | ||
} | ||
} | ||
} | ||
val toParse: VideoList = consolidateData(data.details, scan) | ||
val deleted = removeDeleted(data.details, scan) | ||
parseMediaFiles(data.details, toParse) | ||
return if (toParse.isNotEmpty() || deleted) { | ||
logger.info("Saving new data") | ||
data.save() | ||
true | ||
} else false | ||
return parser.parseAll(data.settings.libraryLocations, data.settings.videoExtensions) | ||
} | ||
|
||
fun getVideos(): VideoList = SavedData.load().details | ||
|
||
private fun parseMediaFiles(details: MutableMap<String, VideoFile>, toParse: VideoList) { | ||
toParse.values.forEach { videoFile -> | ||
parseMediaInfo(videoFile.path)?.let { tracks -> | ||
details[videoFile.path] = videoFile.copy( | ||
videos = tracks.filter { t -> t.type == TrackType.Video }, | ||
audios = tracks.filter { t -> t.type == TrackType.Audio }, | ||
subtitles = tracks.filter { t -> t.type == TrackType.Subtitle }, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun consolidateData(data: MutableMap<String, VideoFile>, scan: VideoList): VideoList { | ||
val toScan = scan.filterValues { data[it.path]?.modifiedTime != it.modifiedTime } | ||
toScan.forEach { data[it.key] = it.value } // Source object change | ||
return toScan | ||
} | ||
suspend fun getVideos(): VideoList = repo.getAll().map { it.toVideoFile() } | ||
|
||
private fun removeDeleted(data: MutableMap<String, VideoFile>, scan: VideoList): Boolean { | ||
val toDelete = data.keys.filter { !scan.containsKey(it) } | ||
toDelete.forEach { data.remove(it) } | ||
return toDelete.isNotEmpty() | ||
suspend fun getVideo(path: String): VideoFile? { | ||
return repo.getFile(Path.of(path))?.toVideoFile() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
server/src/main/kotlin/io/github/jsixface/codexvert/utils/CodecUtils.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters