Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playing streamable videos with url parameters and mp4 saving. #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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("?")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class EmbedViewActivity : BaseActivity(), EmbedView {
Single.create<String> {
val url = presenter.mp4Url
val path = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
PhotoViewActions.SAVED_FOLDER
)
if (!path.exists())
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down