Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Former-commit-id: 9c3076577b6eb55ffc9d9f6642098a5bf632e398 [formerly 23c5fff]
Former-commit-id: ebc671f2657f28141fee753ead9ff519db624fb9
  • Loading branch information
ingbyr committed Nov 16, 2017
2 parents 3c0ba8c + ed5da11 commit 2329d51
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 180 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GUI-YouGet
![](https://img.shields.io/badge/v0.2-pass-green.svg)
![](https://img.shields.io/badge/v0.2.1-pass-green.svg)
![](https://img.shields.io/github/forks/ingbyr/GUI-YouGet.svg)
![](https://img.shields.io/github/stars/ingbyr/GUI-YouGet.svg)
![](https://img.shields.io/badge/license-MIT-blue.svg)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
group 'com.ingbyr.guiyouget'
version '0.3'
version '0.2.1'

buildscript {
ext.kotlin_version = '1.1.51'
ext.kotlin_version = '1.1.60'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion core/youtube-dl.exe.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
798471fbe50d7e01206adad86ef7e109e138766e
a00eb4f12a25036a1d2ab772654032a4579944d4
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import com.jfoenix.controls.JFXListView
import javafx.scene.control.Label
import org.slf4j.LoggerFactory
import tornadofx.*
import java.util.*

class MediaListController : Controller() {

private val logger = LoggerFactory.getLogger(MediaListController::class.java)

//todo 获取失败时国际化文本
init {
messages = ResourceBundle.getBundle("i18n/MediaListView")
}

fun subscribeEvents() {
subscribe<RequestMediasWithYoutubeDL> {
try {
Expand All @@ -27,8 +31,8 @@ class MediaListController : Controller() {
} catch (e: Exception) {
logger.error(e.toString())
fire(DisplayMediasWithYoutubeDL(JsonObject(mapOf(
"title" to "Failed to get media info",
"description" to "Make sure that URL is correct"))))
"title" to messages["getInfoFailed"],
"description" to messages["getInfoFailedDes"]))))
}
}

Expand All @@ -38,7 +42,7 @@ class MediaListController : Controller() {
fire(DisplayMediasWithYouGet(json))
} catch (e: Exception) {
logger.error(e.toString())
fire(DisplayMediasWithYouGet(JsonObject(mapOf("title" to "Failed to get media info"))))
fire(DisplayMediasWithYouGet(JsonObject(mapOf("title" to messages["getInfoFailed"]))))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.ingbyr.guiyouget.core.YoutubeDL
import com.ingbyr.guiyouget.events.DownloadingRequestWithYouGet
import com.ingbyr.guiyouget.events.DownloadingRequestWithYoutubeDL
import com.ingbyr.guiyouget.events.ResumeDownloading
import com.ingbyr.guiyouget.utils.CoreUtils
import org.slf4j.LoggerFactory
import tornadofx.*

Expand All @@ -14,28 +13,29 @@ class ProgressController : Controller() {
private var youget: YouGet? = null
private var youtubedl: YoutubeDL? = null
private var formatID: String? = null
private var coreType: String? = null

fun subscribeEvents() {
subscribe<DownloadingRequestWithYoutubeDL> {
youtubedl = it.youtubedl
formatID = it.formatID
coreType = CoreUtils.YOUTUBE_DL
it.youtubedl.runDownloadCommand(it.formatID)
}

subscribe<DownloadingRequestWithYouGet> {
youget = it.youget
formatID = it.formatID
coreType = CoreUtils.YOU_GET
it.youget.runDownloadCommand(it.formatID)
}

subscribe<ResumeDownloading> {
when (coreType) {
CoreUtils.YOUTUBE_DL -> youtubedl?.runDownloadCommand(formatID!!)
CoreUtils.YOU_GET -> youget?.runDownloadCommand(formatID!!)
}
youtubedl?.let {
logger.debug("resume downloading with youtube-dl")
it.runDownloadCommand(formatID!!)
}
youget?.let {
logger.debug("resume downloading with youget")
it.runDownloadCommand(formatID!!)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class UpdatesController : Controller() {
val url = CoreUtils.yougetUpdateURL(remoteVersion)
logger.debug("[you-get] update url $url")
okhttp.downloadFile(url,
Paths.get(System.getProperty("user.dir"), "core", "you-get.exe").toFile(),
Paths.get(System.getProperty("user.dir"), "core", "you-get.exe").toString(),
CoreUtils.YOU_GET_VERSION,
remoteVersion)
} else {
Expand All @@ -75,7 +75,7 @@ class UpdatesController : Controller() {
val url = CoreUtils.youtubedlUpdateURL(remoteVersion)
logger.debug("[youtube-dl] update url $url")
okhttp.downloadFile(url,
Paths.get(System.getProperty("user.dir"), "core", "youtube-dl.exe").toFile(),
Paths.get(System.getProperty("user.dir"), "core", "youtube-dl.exe").toString(),
CoreUtils.YOUTUBE_DL_VERSION,
remoteVersion)
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/com/ingbyr/guiyouget/core/CoreController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ abstract class CoreController : Controller() {
messages = ResourceBundle.getBundle("i18n/core")
}

val logger = LoggerFactory.getLogger(CoreController::class.java)

fun runCommand(args: MutableList<String>): StringBuilder {
val output = StringBuilder()
val builder = ProcessBuilder(args)
Expand Down
89 changes: 45 additions & 44 deletions src/main/kotlin/com/ingbyr/guiyouget/core/OkHttpController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import com.ingbyr.guiyouget.events.UpdateYouGetStates
import com.ingbyr.guiyouget.events.UpdateYoutubeDLStates
import com.ingbyr.guiyouget.utils.CoreUtils
import okhttp3.*
import okio.Okio
import org.slf4j.LoggerFactory
import tornadofx.*
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.nio.file.Paths
import java.util.*


Expand All @@ -19,6 +19,10 @@ class OkHttpController : Controller() {
private val client = OkHttpClient()
private val parser = Parser()

init {
messages = ResourceBundle.getBundle("i18n/core")
}

fun requestString(url: String): String? {
val request = Request.Builder().get().url(url).build()
var msg: String? = null
Expand All @@ -41,14 +45,18 @@ class OkHttpController : Controller() {
}
}

fun downloadFile(url: String, file: File, k: String? = null, v: String? = null) {
fun downloadFile(url: String, file: String, k: String? = null, v: String? = null) {
val request = Request.Builder().url(url).build()
logger.debug("save file to ${file.absolutePath}")
client.newCall(request).enqueue(DownloadFileCallBack(file, k, v))
logger.debug("file path is $file")
try {
client.newCall(request).enqueue(DownloadFileCallBack(file, k, v))
} catch (e: Exception) {
logger.error(e.message)
}
}
}

class DownloadFileCallBack(private val file: File, private val k: String?, private val v: String?) : Callback, Controller() {
class DownloadFileCallBack(private val file: String, private val k: String?, private val v: String?) : Callback, Controller() {
init {
messages = ResourceBundle.getBundle("i18n/core")
}
Expand All @@ -58,58 +66,51 @@ class DownloadFileCallBack(private val file: File, private val k: String?, priva
override fun onFailure(call: Call?, e: IOException?) {
when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
logger.debug("failed to update youtube-dl")
fire(UpdateYoutubeDLStates(messages["failed"]))
}
CoreUtils.YOU_GET_VERSION -> {
logger.debug("failed to update you-get")
fire(UpdateYouGetStates(messages["failed"]))
}
}
logger.error(e.toString())
}

override fun onResponse(call: Call?, response: Response) {
if (!response.isSuccessful) throw IOException("Unexpected code " + response)
val byteStream = response.body()?.byteStream()
val length = response.body()?.contentLength()
logger.debug("length $length")
val os: FileOutputStream
try {
os = FileOutputStream(file)
} catch (e: Exception) {
logger.error(e.toString())
return
}
if (response.isSuccessful) {
val sink = Okio.buffer(Okio.sink(Paths.get(file).toFile()))
sink.writeAll(response.body()!!.source())
sink.close()
response.close()

var bytesRead = -1
val buffer = ByteArray(2048)
var process = 0L
try {
do {
if (byteStream != null) {
bytesRead = byteStream.read(buffer)
}
if (bytesRead == -1) break
process += bytesRead
logger.trace(process.toString())
os.write(buffer, 0, bytesRead)
} while (true)
} catch (e: Exception) {
logger.error(e.toString())

}
// Update config of APP
if (k != null && v != null) {
app.config[k] = v
app.config.save()
}

when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
fire(UpdateYoutubeDLStates(messages["completed"]))
when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
fire(UpdateYoutubeDLStates(messages["completed"]))
}
CoreUtils.YOU_GET_VERSION -> {
fire(UpdateYouGetStates(messages["completed"]))
}
}
CoreUtils.YOU_GET_VERSION -> {
fire(UpdateYouGetStates(messages["completed"]))
} else {
logger.error("bad request")
response.close()
when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
logger.debug("failed to update youtube-dl")
fire(UpdateYoutubeDLStates(messages["failed"]))
}
CoreUtils.YOU_GET_VERSION -> {
logger.debug("failed to update you-get")
fire(UpdateYouGetStates(messages["failed"]))
}
}
}
// Update config of APP
if (k != null && v != null) {
app.config[k] = v
app.config.save()
}
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/ingbyr/guiyouget/core/YouGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import com.beust.klaxon.Parser
import com.ingbyr.guiyouget.events.StopDownloading
import com.ingbyr.guiyouget.events.UpdateProgressWithYouGet
import com.ingbyr.guiyouget.utils.CoreUtils
import org.slf4j.LoggerFactory
import tornadofx.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.nio.file.Paths

class YouGet(val url: String) : CoreController() {
companion object {
val logger = LoggerFactory.getLogger(this::class.java)
}

val core = Paths.get(System.getProperty("user.dir"), "core", "you-get.exe").toAbsolutePath().toString()
private val parser = Parser()
private var progress = 0.0
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/com/ingbyr/guiyouget/core/YoutubeDL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import com.beust.klaxon.Parser
import com.ingbyr.guiyouget.events.StopDownloading
import com.ingbyr.guiyouget.events.UpdateProgressWithYoutubeDL
import com.ingbyr.guiyouget.utils.CoreUtils
import org.slf4j.LoggerFactory
import tornadofx.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.nio.file.Paths


class YoutubeDL(private val url: String) : CoreController() {
companion object {
val logger = LoggerFactory.getLogger(this::class.java)
}

val core = Paths.get(System.getProperty("user.dir"), "core", "youtube-dl.exe").toAbsolutePath().toString()
private val parser = Parser()
private var progress = 0.0
Expand Down Expand Up @@ -82,7 +87,7 @@ class YoutubeDL(private val url: String) : CoreController() {
} else {
if (p != null && p.isAlive) {
logger.debug("stop process $p")
p.destroy()
p.destroyForcibly()
}
break
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/ingbyr/guiyouget/utils/CoreUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object CoreUtils {
val YOUTUBE_DL_VERSION = "youtube-dl-version"
val YOU_GET = "you-get"
val YOU_GET_VERSION = "you-get-version"
val STORAGE_PATH = "storagePath"

val PROXY_TYPE = "proxy-type"
val PROXY_ADDRESS = "proxy-address"
Expand Down
Loading

0 comments on commit 2329d51

Please sign in to comment.