brought back info json

This commit is contained in:
deniscerri 2025-12-18 19:21:30 +01:00
parent 4efac41435
commit 18d32225d2
No known key found for this signature in database
GPG key ID: 95C43D517D830350
3 changed files with 36 additions and 26 deletions

View file

@ -598,16 +598,24 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
@OptIn(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
private fun YoutubeDLRequest.addWriteInfoJson(url: String) { private fun YoutubeDLRequest.addWriteInfoJson(url: String) {
val cachePath = "${FileUtil.getCachePath(context)}infojsons" val cachePath = "${FileUtil.getCachePath(context)}infojsons"
val infoJsonName = MessageDigest.getInstance("MD5").digest(url.toByteArray()).toHexString()
val id = if (url.isYoutubeURL()) {
url.getIDFromYoutubeURL() ?: url
} else url
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
this.addCommands(listOf("--print-to-file", "video:%()#j", "${cachePath}/${infoJsonName}.info.json")) this.addCommands(listOf("--print-to-file", "video:%()#j", "${cachePath}/${infoJsonName}.info.json"))
} }
@OptIn(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
private fun getInfoJsonPath(url: String): String? { private fun getInfoJsonFile(url: String): File? {
val cachePath = "${FileUtil.getCachePath(context)}infojsons" val cachePath = "${FileUtil.getCachePath(context)}infojsons"
val infoJsonName = MessageDigest.getInstance("MD5").digest(url.toByteArray()).toHexString() val id = if (url.isYoutubeURL()) {
url.getIDFromYoutubeURL() ?: url
} else url
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
val infoJsonFile = File(cachePath).walkTopDown().firstOrNull { it.name == "${infoJsonName}.info.json" } val infoJsonFile = File(cachePath).walkTopDown().firstOrNull { it.name == "${infoJsonName}.info.json" }
return infoJsonFile?.absolutePath return infoJsonFile
} }
fun getFilenameTemplatePreview(item: DownloadItem, filenameTemplate: String): String { fun getFilenameTemplatePreview(item: DownloadItem, filenameTemplate: String): String {
@ -615,13 +623,10 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
val request = buildYoutubeDLRequest(item) val request = buildYoutubeDLRequest(item)
request.addOption("--print", "%(filename)s") request.addOption("--print", "%(filename)s")
request.addOption("--skip-download") request.addOption("--skip-download")
request.addOption("--simulate")
val infoJsonPath = getInfoJsonPath(item.url) request.addOption("--no-check-certificates")
if (infoJsonPath == null) { request.addOption("--no-check-formats")
request.addWriteInfoJson(item.url) request.addOption("--quiet")
} else {
request.addOption("--load-info-json", infoJsonPath)
}
try { try {
val response = YoutubeDL.execute(request) val response = YoutubeDL.execute(request)
@ -978,19 +983,24 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
ytDlRequest.setYoutubeExtractorArgs(downloadItem.url) ytDlRequest.setYoutubeExtractorArgs(downloadItem.url)
} }
//TODO REVIEW TO ADD THIS AGAIN LATER? /*
// if (!sharedPreferences.getBoolean("disable_write_info_json", false)) { * https://github.com/yt-dlp/yt-dlp/issues/11947
// val cachePath = "${FileUtil.getCachePath(context)}infojsons" * Cant use info json when using download sections
// val infoJsonName = MessageDigest.getInstance("MD5").digest(downloadItem.url.toByteArray()).toHexString() * */
// val canUseWriteInfoJson =
// val infoJsonFile = File(cachePath).walkTopDown().firstOrNull { it.name == "${infoJsonName}.info.json" } !sharedPreferences.getBoolean("disable_write_info_json", false) &&
// //ignore info file if its older than 5 hours. puny measure to prevent expired formats in some cases !request.toString().contains("--download-sections")
// if (infoJsonFile == null || System.currentTimeMillis() - infoJsonFile.lastModified() > (1000 * 60 * 60 * 5)) {
// request.addCommands(listOf("--print-to-file", "video:%()#j", "${cachePath}/${infoJsonName}.info.json")) if (canUseWriteInfoJson) {
// }else { val infoJsonURL = if (useItemURL) downloadItem.url else downloadItem.playlistURL ?: downloadItem.url
// request.addOption("--load-info-json", infoJsonFile.absolutePath) val infoJsonFile = getInfoJsonFile(infoJsonURL)
// } //ignore info file if its older than 5 hours. puny measure to prevent expired formats in some cases
// } if (infoJsonFile == null || System.currentTimeMillis() - infoJsonFile.lastModified() > (1000 * 60 * 60 * 5)) {
ytDlRequest.addWriteInfoJson(infoJsonURL)
} else {
request.addOption("--load-info-json", infoJsonFile.absolutePath)
}
}
} }
if (sharedPreferences.getString("prevent_duplicate_downloads", "")!! == "download_archive"){ if (sharedPreferences.getString("prevent_duplicate_downloads", "")!! == "download_archive"){

View file

@ -70,7 +70,7 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/downloading" android:enabled="false" app:isPreferenceVisible="false"> <PreferenceCategory android:title="@string/downloading">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:widgetLayout="@layout/preferece_material_switch" android:widgetLayout="@layout/preferece_material_switch"
android:icon="@drawable/if_file_rename" android:icon="@drawable/if_file_rename"

View file

@ -72,7 +72,7 @@
<ListPreference <ListPreference
android:icon="@drawable/baseline_recommend_24" android:icon="@drawable/baseline_recommend_24"
android:key="recommendations_home" android:key="recommendations_home"
android:defaultValue="newpipe" android:defaultValue=""
android:entries="@array/video_recommendations" android:entries="@array/video_recommendations"
android:entryValues="@array/video_recommnedations_values" android:entryValues="@array/video_recommnedations_values"
app:summary="@string/video_recommendations_summary" app:summary="@string/video_recommendations_summary"