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

feat: support for importing temporary playlists from YouTube #5870

Merged
merged 1 commit into from
Apr 6, 2024
Merged
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
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@
<data android:pathPrefix="/playlist" />
<!-- search prefix -->
<data android:pathPrefix="/results" />
<!-- temporary playlist prefix -->
<data android:pathPrefix="/watch_videos" />
</intent-filter>

<!-- Support being detected as media player -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const val playerData = "playerData"
const val id = "id"
const val videoId = "videoId"
const val videoIds = "videoIds"

Check failure on line 8 in app/src/main/java/com/github/libretube/constants/IntentData.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Property name should use the screaming snake case notation when the value can not be changed Raw Output: app/src/main/java/com/github/libretube/constants/IntentData.kt:8:15: error: Property name should use the screaming snake case notation when the value can not be changed (standard:property-naming)
const val channelId = "channelId"
const val channelName = "channelName"
const val playlistId = "playlistId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.github.libretube.helpers.WindowHelper
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.dialogs.ErrorDialog
import com.github.libretube.ui.dialogs.ImportTempPlaylistDialog
import com.github.libretube.ui.fragments.AudioPlayerFragment
import com.github.libretube.ui.fragments.DownloadsFragment
import com.github.libretube.ui.fragments.PlayerFragment
Expand Down Expand Up @@ -426,6 +427,16 @@
intent?.getStringExtra(IntentData.playlistId)?.let {
navController.navigate(NavDirections.openPlaylist(playlistId = it))
}
intent?.getStringArrayExtra(IntentData.videoIds)?.let {
ImportTempPlaylistDialog()
.apply {
arguments = bundleOf(

Check failure on line 433 in app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt:433:33: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
IntentData.playlistName to intent?.getStringExtra(IntentData.playlistName),
IntentData.videoIds to it

Check failure on line 435 in app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt:435:50: error: Missing trailing comma before ")" (standard:trailing-comma-on-call-site)
)
}
.show(supportFragmentManager, null)
}
intent?.getStringExtra(IntentData.videoId)?.let {
// the bottom navigation bar has to be created before opening the video
// otherwise the player layout measures aren't calculated properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class RouterActivity : BaseActivity() {
lastSegment == "playlist" -> {
putExtra(IntentData.playlistId, uri.getQueryParameter("list"))
}
lastSegment == "watch_videos" -> {
putExtra(IntentData.playlistName, uri.getQueryParameter("title"))
val videoIds = uri.getQueryParameter("video_ids")?.split(",")
putExtra(IntentData.videoIds, videoIds?.toTypedArray())
}
else -> {
val id = if (lastSegment == "watch") uri.getQueryParameter("v") else lastSegment
putExtra(IntentData.videoId, id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.libretube.ui.dialogs

import android.app.Dialog
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.obj.PipedImportPlaylist
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Date

class ImportTempPlaylistDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val title = arguments?.getString(IntentData.playlistName)

Check failure on line 21 in app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt:21:21: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
?.takeIf { it.isNotEmpty() }
?: Date().toString()
val videoIds = arguments?.getStringArray(IntentData.videoIds).orEmpty()

return MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.import_temp_playlist)
.setMessage(
requireContext()
.getString(R.string.import_temp_playlist_summary, title, videoIds.size)

Check failure on line 30 in app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt:30:92: error: Missing trailing comma before ")" (standard:trailing-comma-on-call-site)
)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.okay) { _, _ ->
val context = requireContext().applicationContext

CoroutineScope(Dispatchers.IO).launch {
try {
val playlist = PipedImportPlaylist(

Check failure on line 38 in app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt:38:40: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
name = title,
videos = videoIds.toList()

Check failure on line 40 in app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt:40:55: error: Missing trailing comma before ")" (standard:trailing-comma-on-call-site)
)

PlaylistsHelper.importPlaylists(listOf(playlist))
context.toastFromMainDispatcher(R.string.playlistCreated)
} catch (e: Exception) {
Log.e(TAG(), e.toString())
e.localizedMessage?.let {
context.toastFromMainDispatcher(it)
}
}
}
}
.create()
}
}

Check failure on line 55 in app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 File must end with a newline (\n) Raw Output: app/src/main/java/com/github/libretube/ui/dialogs/ImportTempPlaylistDialog.kt:55:1: error: File must end with a newline (\n) (standard:final-newline)
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,6 @@
<string name="tooltip_create_playlist">Create playlist</string>
<string name="tooltip_scroll_to_top">Scroll to top</string>
<string name="also_clear_watch_positions">Also clear watch positions</string>
<string name="import_temp_playlist">Import temporary playlist?</string>
<string name="import_temp_playlist_summary">Do you want to create a new playlist named \'%1$s\'? The playlist will contain %2$d videos.</string>
</resources>
Loading