Skip to content

Commit

Permalink
Add apiUrl for updating yt-dlp from other repos
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Feb 1, 2023
1 parent a3b9717 commit 970b819
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void updateYoutubeDL() {

updating = true;
progressBar.setVisibility(View.VISIBLE);
Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().updateYoutubeDL(getApplication()))
Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().updateYoutubeDL(getApplication(), null))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(status -> {
Expand All @@ -113,7 +113,7 @@ private void updateYoutubeDL() {
}
updating = false;
}, e -> {
if(BuildConfig.DEBUG) Log.e(TAG, "failed to update", e);
if (BuildConfig.DEBUG) Log.e(TAG, "failed to update", e);
progressBar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this, "update failed", Toast.LENGTH_LONG).show();
updating = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ object YoutubeDL {

@Synchronized
@Throws(YoutubeDLException::class)
fun updateYoutubeDL(appContext: Context): UpdateStatus? {
fun updateYoutubeDL(appContext: Context, apiUrl: String? = null): UpdateStatus? {
assertInit()
return try {
YoutubeDLUpdater.update(appContext)
YoutubeDLUpdater.update(appContext, apiUrl)
} catch (e: IOException) {
throw YoutubeDLException("failed to update youtube-dl", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import java.net.URL
internal object YoutubeDLUpdater {
private const val releasesUrl = "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest"
private const val youtubeDLVersionKey = "youtubeDLVersion"

@Throws(IOException::class, YoutubeDLException::class)
fun update(appContext: Context): UpdateStatus {
val json = checkForUpdate(appContext) ?: return UpdateStatus.ALREADY_UP_TO_DATE
fun update(appContext: Context, apiUrl: String? = null): UpdateStatus {
val json = checkForUpdate(appContext, apiUrl) ?: return UpdateStatus.ALREADY_UP_TO_DATE
val downloadUrl = getDownloadUrl(json)
val file = download(appContext, downloadUrl)
val ytdlpDir = getYoutubeDLDir(appContext)
Expand All @@ -44,8 +45,8 @@ internal object YoutubeDLUpdater {
}

@Throws(IOException::class)
private fun checkForUpdate(appContext: Context): JsonNode? {
val url = URL(releasesUrl)
private fun checkForUpdate(appContext: Context, apiUrl: String? = null): JsonNode? {
val url = URL(apiUrl ?: releasesUrl)
val json: JsonNode = YoutubeDL.objectMapper.readTree(url)
val newVersion = getTag(json)
val oldVersion = SharedPrefsHelper[appContext, youtubeDLVersionKey]
Expand Down

0 comments on commit 970b819

Please sign in to comment.