add info json only for videos not playlists
This commit is contained in:
parent
1af89c0afc
commit
b2c55890ae
2 changed files with 34 additions and 18 deletions
|
|
@ -103,10 +103,6 @@ class WebViewActivity : BaseActivity() {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
cookieManager = CookieManager.getInstance()
|
|
||||||
cookieManager.removeAllCookies(null)
|
|
||||||
cookieManager.flush()
|
|
||||||
|
|
||||||
preferences = PreferenceManager.getDefaultSharedPreferences(this@WebViewActivity)
|
preferences = PreferenceManager.getDefaultSharedPreferences(this@WebViewActivity)
|
||||||
|
|
||||||
webViewClient = object : AccompanistWebViewClient() {
|
webViewClient = object : AccompanistWebViewClient() {
|
||||||
|
|
@ -157,6 +153,9 @@ class WebViewActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cookieManager = CookieManager.getInstance()
|
||||||
|
cookieManager.removeAllCookies(null)
|
||||||
|
cookieManager.flush()
|
||||||
webViewCompose.apply {
|
webViewCompose.apply {
|
||||||
setContent { WebViewView() }
|
setContent { WebViewView() }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -598,23 +598,40 @@ 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"
|
||||||
|
File(cachePath).mkdirs()
|
||||||
|
|
||||||
val id = if (url.isYoutubeURL()) {
|
var id = url
|
||||||
url.getIDFromYoutubeURL() ?: url
|
if (url.isYoutubeURL()) {
|
||||||
} else url
|
id = url.getIDFromYoutubeURL() ?: url
|
||||||
|
}
|
||||||
|
|
||||||
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
|
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
|
||||||
this.addCommands(listOf("--print-to-file", "video:%()#j", "${cachePath}/${infoJsonName}.info.json"))
|
//yt-dlp doesnt overwrite info json, so delete manually
|
||||||
|
File("${cachePath}/${infoJsonName}video.info.json").delete()
|
||||||
|
this.addCommands(listOf("--print-to-file", "video:%()j", "${cachePath}/${infoJsonName}video.info.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
private fun getInfoJsonFile(url: String): File? {
|
private fun getInfoJsonFile(url: String): File? {
|
||||||
val cachePath = "${FileUtil.getCachePath(context)}infojsons"
|
val cachePath = "${FileUtil.getCachePath(context)}infojsons"
|
||||||
val id = if (url.isYoutubeURL()) {
|
|
||||||
url.getIDFromYoutubeURL() ?: url
|
var id = url
|
||||||
} else url
|
if (url.isYoutubeURL()) {
|
||||||
|
id = url.getIDFromYoutubeURL() ?: url
|
||||||
|
}
|
||||||
|
|
||||||
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
|
val infoJsonName = MessageDigest.getInstance("MD5").digest(id.toByteArray()).toHexString()
|
||||||
val infoJsonFile = File(cachePath).walkTopDown().firstOrNull { it.name == "${infoJsonName}.info.json" }
|
var infoJsonFile : File? = null
|
||||||
|
File(cachePath).walkBottomUp().filter { it.name.startsWith(infoJsonName) }.forEach {
|
||||||
|
if (it.name == "${infoJsonName}playlist.info.json") {
|
||||||
|
infoJsonFile = it
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it.name == "${infoJsonName}video.info.json") {
|
||||||
|
infoJsonFile = it
|
||||||
|
}
|
||||||
|
}
|
||||||
return infoJsonFile
|
return infoJsonFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -629,7 +646,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
||||||
request.addOption("--quiet")
|
request.addOption("--quiet")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val response = YoutubeDL.execute(request)
|
val response = YoutubeDL.getInstance().execute(request)
|
||||||
return response.out.replace(FileUtil.getCachePath(context) + "${item.id}/", "").trim()
|
return response.out.replace(FileUtil.getCachePath(context) + "${item.id}/", "").trim()
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
return ex.message ?: ""
|
return ex.message ?: ""
|
||||||
|
|
@ -991,14 +1008,14 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
||||||
!sharedPreferences.getBoolean("disable_write_info_json", false) &&
|
!sharedPreferences.getBoolean("disable_write_info_json", false) &&
|
||||||
!request.toString().contains("--download-sections")
|
!request.toString().contains("--download-sections")
|
||||||
|
|
||||||
if (canUseWriteInfoJson) {
|
if (canUseWriteInfoJson && downloadItem.playlistURL.isNullOrBlank()) {
|
||||||
val infoJsonURL = if (useItemURL) downloadItem.url else downloadItem.playlistURL ?: downloadItem.url
|
val infoJsonURL = downloadItem.url
|
||||||
val infoJsonFile = getInfoJsonFile(infoJsonURL)
|
val infoJsonFile = getInfoJsonFile(infoJsonURL)
|
||||||
//ignore info file if its older than 5 hours. puny measure to prevent expired formats in some cases
|
//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)) {
|
if (infoJsonFile != null && System.currentTimeMillis() - infoJsonFile.lastModified() <= (1000 * 60 * 60 * 5)) {
|
||||||
ytDlRequest.addWriteInfoJson(infoJsonURL)
|
|
||||||
} else {
|
|
||||||
request.addOption("--load-info-json", infoJsonFile.absolutePath)
|
request.addOption("--load-info-json", infoJsonFile.absolutePath)
|
||||||
|
}else {
|
||||||
|
ytDlRequest.addWriteInfoJson(infoJsonURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue