Skip to content

Commit

Permalink
Do not make yt-dlp and ffmpeg executable on Windows, (#51)
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
StefanLobbenmeier authored May 28, 2024
1 parent 72fc529 commit 9fc9088
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import java.io.InputStream
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermissions
import java.util.zip.ZipInputStream
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

private val logger = KotlinLogging.logger {}

Expand All @@ -33,7 +33,7 @@ suspend fun HttpClient.downloadFile(
return targetFile
}

return CoroutineScope(Dispatchers.IO).run {
return withContext(Dispatchers.IO) {
logger.info { "Starting download to $targetFile from $url" }

val downloadFile =
Expand All @@ -45,11 +45,17 @@ suspend fun HttpClient.downloadFile(
}

targetFile.parentFile.mkdirs()

val executable = PosixFilePermissions.fromString("rwxr-xr-x")
val permissions = PosixFilePermissions.asFileAttribute(executable)
Files.deleteIfExists(targetFile.toPath())
Files.createFile(targetFile.toPath(), permissions)

val platform = getPlatform()
if (platform.needsExecutableBit) {
val executable = PosixFilePermissions.fromString("rwxr-xr-x")
val permissions = PosixFilePermissions.asFileAttribute(executable)

Files.createFile(targetFile.toPath(), permissions)
} else {
Files.createFile(targetFile.toPath())
}

if (unzipFile) {
copyFirstEntryToFile(downloadFile.bodyAsChannel().toInputStream(), targetFile)
Expand All @@ -60,7 +66,7 @@ suspend fun HttpClient.downloadFile(
onProgress(DownloadCompleted)
logger.info { "Completed download to $targetFile from $url" }

return targetFile
targetFile
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class Platform(
val name: String,
val ytDlpName: YtDlpNames,
val ffmpegPlatform: FfmpegPlatforms,
val needsExecutableBit: Boolean,
) {
val settingsFile = Path.of(Directories.configDir).resolve("settings.json")
val binariesFolder = Path.of(Directories.dataDir).resolve("binaries")
Expand Down Expand Up @@ -46,7 +47,12 @@ fun getPlatform(): Platform {

return when {
name.contains("Windows") -> {
Platform(displayName, YtDlpNames.windows, FfmpegPlatforms.windows64)
Platform(
displayName,
YtDlpNames.windows,
FfmpegPlatforms.windows64,
needsExecutableBit = false
)
}
name.contains("Mac") -> {
val ytDlpName =
Expand All @@ -55,7 +61,7 @@ fun getPlatform(): Platform {
} else {
YtDlpNames.osx
}
Platform(displayName, ytDlpName, FfmpegPlatforms.osx64)
Platform(displayName, ytDlpName, FfmpegPlatforms.osx64, needsExecutableBit = true)
}
else -> {
val ffmpegPlatform =
Expand All @@ -65,7 +71,7 @@ fun getPlatform(): Platform {
else -> FfmpegPlatforms.linux64
}

Platform(displayName, YtDlpNames.python, ffmpegPlatform)
Platform(displayName, YtDlpNames.python, ffmpegPlatform, needsExecutableBit = true)
}
}
}

0 comments on commit 9fc9088

Please sign in to comment.