Merge pull request #6845 from Bnyro/master

feat: support for importing playlist as list of video ids / urls
This commit is contained in:
Bnyro 2024-12-02 21:51:40 +01:00 committed by GitHub
commit 09754d3e8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View File

@ -8,5 +8,6 @@ enum class ImportFormat(@StringRes val value: Int) {
FREETUBE(R.string.import_format_freetube),
YOUTUBECSV(R.string.import_format_youtube_csv),
YOUTUBEJSON(R.string.youtube),
PIPED(R.string.import_format_piped)
PIPED(R.string.import_format_piped),
URLSORIDS(R.string.import_format_list_of_urls)
}

View File

@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.core.net.toUri
import com.github.libretube.R
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.PlaylistsHelper
@ -229,6 +230,26 @@ object ImportHelper {
}
}
ImportFormat.URLSORIDS -> {
activity.contentResolver.openInputStream(uri)?.use { inputStream ->
val playlist = PipedImportPlaylist(name = TextUtils.defaultPlaylistName)
playlist.videos = inputStream.bufferedReader().readLines()
.flatMap { it.split(",") }
.mapNotNull { videoUrlOrId ->
if (videoUrlOrId.length == 11) {
videoUrlOrId
} else {
TextUtils.getVideoIdFromUri(videoUrlOrId.toUri())
}
}
if (playlist.videos.isNotEmpty()) {
importPlaylists.add(playlist)
}
}
}
else -> throw IllegalArgumentException()
}

View File

@ -41,7 +41,8 @@ class BackupRestoreSettings : BasePreferenceFragment() {
private val importPlaylistFormatList = listOf(
ImportFormat.PIPED,
ImportFormat.FREETUBE,
ImportFormat.YOUTUBECSV
ImportFormat.YOUTUBECSV,
ImportFormat.URLSORIDS
)
private val exportPlaylistFormatList = listOf(
ImportFormat.PIPED,

View File

@ -480,6 +480,7 @@
<string name="import_format_freetube" translatable="false">FreeTube</string>
<string name="import_format_youtube_csv" translatable="false">YouTube (CSV)</string>
<string name="import_format_youtube_json" translatable="false">YouTube (JSON)</string>
<string name="import_format_list_of_urls">List of URls or video IDs</string>
<string name="home_tab_content">Home tab content</string>
<string name="show_search_suggestions">Show search suggestions</string>
<string name="audio_track_format">%1$s - %2$s</string>