This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Former-commit-id: 9bed7d2a575582df6aee4067a980c8ff9fa9f9fd [formerly 10a46e0] Former-commit-id: a7de363b9da5c579999daf1ff3daf0d736560ba6
- Loading branch information
Showing
18 changed files
with
290 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"youget": "https://raw.githubusercontent.com/rg3/youtube-dl/master/youtube_dl/version.py", | ||
"youtubedl": "https://raw.githubusercontent.com/soimort/you-get/master/src/you_get/version.py", | ||
"youget": "https://raw.githubusercontent.com/soimort/you-get/master/src/you_get/version.py", | ||
"youtubedl": "https://raw.githubusercontent.com/rg3/youtube-dl/master/youtube_dl/version.py", | ||
"app-version": "0.2" | ||
} |
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
Binary file not shown.
Binary file not shown.
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
6 changes: 5 additions & 1 deletion
6
src/main/kotlin/com/ingbyr/guiyouget/controllers/ProgressController.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
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/com/ingbyr/guiyouget/controllers/UpdatesController.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.ingbyr.guiyouget.controllers | ||
|
||
import com.ingbyr.guiyouget.core.OkHttpController | ||
import com.ingbyr.guiyouget.events.RequestCheckUpdatesYouGet | ||
import com.ingbyr.guiyouget.events.RequestCheckUpdatesYoutubeDL | ||
import com.ingbyr.guiyouget.events.UpdateStates | ||
import com.ingbyr.guiyouget.utils.CoreUtils | ||
import org.slf4j.LoggerFactory | ||
import tornadofx.* | ||
import java.io.File | ||
|
||
class UpdatesController: Controller() { | ||
val logger = LoggerFactory.getLogger(this::class.java) | ||
val okhttp = OkHttpController() | ||
|
||
fun subscribeEvents() { | ||
subscribe<RequestCheckUpdatesYouGet> { | ||
fire(UpdateStates("Check for updates of you-get")) | ||
val remoteJson = okhttp.requestJson(CoreUtils.REMOTE_CONF_URL) | ||
if (remoteJson != null) { | ||
val youget = remoteJson["youget"] as String | ||
logger.debug("get remote version file url $youget") | ||
doUpdates(CoreUtils.YOU_GET, youget) | ||
} else { | ||
//todo update failed | ||
} | ||
} | ||
|
||
subscribe<RequestCheckUpdatesYoutubeDL> { | ||
fire(UpdateStates("Check for updates of youyube-dl")) | ||
val remoteJson = okhttp.requestJson(CoreUtils.REMOTE_CONF_URL) | ||
if (remoteJson != null) { | ||
val youtubedl = remoteJson["youtubedl"] as String | ||
logger.debug("get remote version file url $youtubedl") | ||
doUpdates(CoreUtils.YOUTUBE_DL, youtubedl) | ||
} else { | ||
//todo update failed | ||
} | ||
} | ||
} | ||
|
||
private fun doUpdates(core: String, url: String) { | ||
val vStr = okhttp.requestString(url) | ||
val v = Regex("'\\d+.+'").findAll(vStr.toString()).toList().flatMap(MatchResult::groupValues) | ||
val remoteVersion = v.first().substring(1, v.first().length - 1) | ||
when (core) { | ||
CoreUtils.YOU_GET -> { | ||
val localVersion = app.config["you-get-version"] as String | ||
logger.debug("remote version is $remoteVersion, local version is $localVersion") | ||
if (remoteVersion > localVersion) { | ||
// do updates | ||
fire(UpdateStates("New version $remoteVersion of you-get, downloading")) | ||
val url = CoreUtils.yougetUpdateURL(remoteVersion) | ||
logger.debug("you-get update url $url") | ||
okhttp.downloadFile(url, File(MainController::class.java.getResource("/core/you-get.exe").toURI())) | ||
} | ||
} | ||
CoreUtils.YOUTUBE_DL -> { | ||
val localVersion = app.config["youtube-dl-version"] as String | ||
if (remoteVersion > localVersion) { | ||
// do updates | ||
fire(UpdateStates("New version $remoteVersion of youtube-dl, downloading")) | ||
val url = CoreUtils.youtubedlUpdateURL(remoteVersion) | ||
logger.debug("youtube-dl update url $url") | ||
okhttp.downloadFile(url, File(MainController::class.java.getResource("/core/youtube-dl.exe").toURI())) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
src/main/kotlin/com/ingbyr/guiyouget/core/OkHttpController.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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.ingbyr.guiyouget.core | ||
|
||
import com.beust.klaxon.JsonObject | ||
import com.beust.klaxon.Parser | ||
import okhttp3.* | ||
import org.slf4j.LoggerFactory | ||
import tornadofx.* | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
|
||
|
||
class OkHttpController : Controller() { | ||
val logger = LoggerFactory.getLogger(this::class.java) | ||
val client = OkHttpClient() | ||
val parser = Parser() | ||
|
||
fun requestString(url: String): String? { | ||
val request = Request.Builder().get().url(url).build() | ||
var msg: String? = null | ||
client.newCall(request).execute().let { response -> | ||
msg = response.body()?.string() | ||
} | ||
return msg | ||
} | ||
|
||
fun requestJson(url: String): JsonObject? { | ||
val request = Request.Builder().get().url(url).build() | ||
var msg: String? = null | ||
client.newCall(request).execute().let { response -> | ||
msg = response.body()?.string() | ||
} | ||
if (msg != null) { | ||
return parser.parse(StringBuilder(msg)) as JsonObject | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
fun downloadFile(url: String, file: File) { | ||
val request = Request.Builder().url(url).build() | ||
logger.debug("save file to ${file.absolutePath}") | ||
client.newCall(request).enqueue(DownloadFileCallBack(file)) | ||
} | ||
} | ||
|
||
class DownloadFileCallBack(var file: File) : Callback, Controller() { | ||
val logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
override fun onFailure(call: Call?, e: IOException?) { | ||
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 | ||
} | ||
|
||
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 | ||
println(process) | ||
os.write(buffer, 0, bytesRead) | ||
} while (true) | ||
} catch (e: Exception) { | ||
logger.error(e.toString()) | ||
|
||
} | ||
|
||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/ingbyr/guiyouget/events/UpdatesEvents.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ingbyr.guiyouget.events | ||
|
||
import tornadofx.* | ||
|
||
// common event | ||
class UpdateStates(val status: String) : FXEvent() | ||
|
||
// you-get updates | ||
object RequestCheckUpdatesYouGet : FXEvent(EventBus.RunOn.BackgroundThread) | ||
|
||
object UpdateYouGet : FXEvent(EventBus.RunOn.BackgroundThread) | ||
|
||
// you-get updates | ||
object RequestCheckUpdatesYoutubeDL : FXEvent(EventBus.RunOn.BackgroundThread) | ||
|
||
object UpdateYoutubeDL : FXEvent(EventBus.RunOn.BackgroundThread) | ||
|
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 @@ | ||
package com.ingbyr.guiyouget.utils | ||
|
||
object CoreUtils { | ||
lateinit var current: String | ||
var REMOTE_CONF_URL = "https://raw.githubusercontent.com/ingbyr/GUI-YouGet/master/RemoteConf.json" | ||
val YOUTUBE_DL = "YOUTUBE_DL" | ||
val YOU_GET = "YOU_GET" | ||
|
||
fun yougetUpdateURL(ver:String) = "https://github.com/soimort/you-get/releases/download/v$ver/you-get-$ver-win32.exe" | ||
|
||
fun youtubedlUpdateURL(ver:String) = "https://github.com/rg3/youtube-dl/releases/download/$ver/youtube-dl.exe" | ||
} |
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
Oops, something went wrong.