mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge pull request #6845 from Bnyro/master
feat: support for importing playlist as list of video ids / urls
This commit is contained in:
commit
09754d3e8b
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user