diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedLinkPresenter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedLinkPresenter.kt index e8b8f45f9..5f2788ddc 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedLinkPresenter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedLinkPresenter.kt @@ -50,7 +50,7 @@ class EmbedLinkPresenter( } STREAMABLE_MATCHER -> { - val id = url.removeSuffix("/").substringAfterLast("/") + val id = url.getStreamableId() embedApi.getStreamableUrl(id) .subscribeOn(schedulers.backgroundThread()) .observeOn(schedulers.mainThread()) @@ -83,4 +83,8 @@ class EmbedLinkPresenter( val domain = uri.host return if (domain.startsWith("www.")) domain.substring(4) else domain } + + private fun String.getStreamableId(): String { + return this.removeSuffix("/").substringAfterLast("/").substringBefore("?") + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedViewActivity.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedViewActivity.kt index 5dc89a760..fa7dd627c 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedViewActivity.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/EmbedViewActivity.kt @@ -222,7 +222,7 @@ class EmbedViewActivity : BaseActivity(), EmbedView { Single.create { val url = presenter.mp4Url val path = File( - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), PhotoViewActions.SAVED_FOLDER ) if (!path.exists()) @@ -237,20 +237,20 @@ class EmbedViewActivity : BaseActivity(), EmbedView { val sink = Okio.buffer(Okio.sink(file)) sink.writeAll(result.body()!!.source()) sink.close() + it.onSuccess(file.path) } else { it.onError(Exception("Could not download the file, http code ${result.code()}")) } - it.onSuccess(path.path) }.subscribeOn(WykopSchedulers().backgroundThread()) .observeOn(WykopSchedulers().mainThread()) .subscribe({ val values = ContentValues() - values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()) - values.put(MediaStore.Images.Media.MIME_TYPE, getMimeType(it)) - values.put(MediaStore.MediaColumns.DATA, it) + values.put(MediaStore.Video.Media.DATE_TAKEN, System.currentTimeMillis()) + values.put(MediaStore.Video.Media.MIME_TYPE, getMimeType(it)) + values.put(MediaStore.Video.Media.DATA, it) + contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values) Toast.makeText(this, R.string.save_file_ok, Toast.LENGTH_SHORT).show() - contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) }, { wykopLog(Log::e, "Exception when trying to save file", it) Toast.makeText(this, R.string.save_file_failed, Toast.LENGTH_SHORT).show() diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YTPlayer.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YTPlayer.kt index 8d09ef1db..0f15e7c2c 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YTPlayer.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YTPlayer.kt @@ -56,7 +56,7 @@ object YouTubeUrlParser { private fun unwrapConsentYoutubeUrl(url: String): String { val match = consentRegex.find(url) ?: return url - return URLDecoder.decode(match.groupValues[1], "utf-8") + return URLDecoder.decode(match.groupValues[1], Charsets.UTF_8.name()) } }