mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
feat: support for importing playlist as list of video ids / urls
This commit is contained in:
parent
fd0b89cfc7
commit
4d712da06e
@ -8,5 +8,6 @@ enum class ImportFormat(@StringRes val value: Int) {
|
|||||||
FREETUBE(R.string.import_format_freetube),
|
FREETUBE(R.string.import_format_freetube),
|
||||||
YOUTUBECSV(R.string.import_format_youtube_csv),
|
YOUTUBECSV(R.string.import_format_youtube_csv),
|
||||||
YOUTUBEJSON(R.string.youtube),
|
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.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.JsonHelper
|
import com.github.libretube.api.JsonHelper
|
||||||
import com.github.libretube.api.PlaylistsHelper
|
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()
|
else -> throw IllegalArgumentException()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ class BackupRestoreSettings : BasePreferenceFragment() {
|
|||||||
private val importPlaylistFormatList = listOf(
|
private val importPlaylistFormatList = listOf(
|
||||||
ImportFormat.PIPED,
|
ImportFormat.PIPED,
|
||||||
ImportFormat.FREETUBE,
|
ImportFormat.FREETUBE,
|
||||||
ImportFormat.YOUTUBECSV
|
ImportFormat.YOUTUBECSV,
|
||||||
|
ImportFormat.URLSORIDS
|
||||||
)
|
)
|
||||||
private val exportPlaylistFormatList = listOf(
|
private val exportPlaylistFormatList = listOf(
|
||||||
ImportFormat.PIPED,
|
ImportFormat.PIPED,
|
||||||
|
@ -480,6 +480,7 @@
|
|||||||
<string name="import_format_freetube" translatable="false">FreeTube</string>
|
<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_csv" translatable="false">YouTube (CSV)</string>
|
||||||
<string name="import_format_youtube_json" translatable="false">YouTube (JSON)</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="home_tab_content">Home tab content</string>
|
||||||
<string name="show_search_suggestions">Show search suggestions</string>
|
<string name="show_search_suggestions">Show search suggestions</string>
|
||||||
<string name="audio_track_format">%1$s - %2$s</string>
|
<string name="audio_track_format">%1$s - %2$s</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user