Skip to content

Commit

Permalink
Remove import from Google Takeout
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Jul 21, 2023
1 parent 00cc1a2 commit cf53ffd
Show file tree
Hide file tree
Showing 26 changed files with 0 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ fun BackupAndRestore(
viewModel.restore(context, uri)
}
}
val importLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) {
viewModel.import(context, uri)
}
}

Column(
Modifier
Expand All @@ -65,14 +60,6 @@ fun BackupAndRestore(
restoreLauncher.launch(arrayOf("application/octet-stream"))
}
)
PreferenceEntry(
title = stringResource(R.string.import_playlist),
description = stringResource(R.string.choose_csv_file_from_google_takeout),
icon = R.drawable.input,
onClick = {
importLauncher.launch(arrayOf("*/*"))
}
)
}

TopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@ package com.zionhuang.music.viewmodels
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.OpenableColumns
import android.widget.Toast
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.YouTube.MAX_GET_QUEUE_SIZE
import com.zionhuang.innertube.models.SongItem
import com.zionhuang.music.MainActivity
import com.zionhuang.music.R
import com.zionhuang.music.db.InternalDatabase
import com.zionhuang.music.db.MusicDatabase
import com.zionhuang.music.db.entities.PlaylistEntity
import com.zionhuang.music.db.entities.PlaylistEntity.Companion.generatePlaylistId
import com.zionhuang.music.db.entities.PlaylistSongMap
import com.zionhuang.music.extensions.div
import com.zionhuang.music.extensions.zipInputStream
import com.zionhuang.music.extensions.zipOutputStream
import com.zionhuang.music.models.toMediaMetadata
import com.zionhuang.music.playback.MusicService
import com.zionhuang.music.playback.MusicService.Companion.PERSISTENT_QUEUE_FILE
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.zip.ZipEntry
Expand Down Expand Up @@ -100,64 +89,6 @@ class BackupRestoreViewModel @Inject constructor(
}
}

fun import(context: Context, uri: Uri) {
runCatching {
val videoIds = mutableListOf<String>()
context.applicationContext.contentResolver.openInputStream(uri)?.use { inputStream ->
val br = inputStream.bufferedReader()
repeat(8) {
br.readLine()
}
var line = br.readLine()
while (line != null) {
line.split(",").firstOrNull()
?.takeIf { it.isNotEmpty() }
?.let {
videoIds.add(it.trim())
}
line = br.readLine()
}
}
val playlistName = context.contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
cursor.moveToFirst()
cursor.getString(nameIndex)
}?.removeSuffix(".csv") ?: context.getString(R.string.imported_playlist)
viewModelScope.launch {
val songs = videoIds.chunked(MAX_GET_QUEUE_SIZE).flatMap {
withContext(Dispatchers.IO) {
YouTube.queue(videoIds = it)
}.getOrNull().orEmpty()
}
database.transaction {
val playlistId = generatePlaylistId()
var position = 0
insert(
PlaylistEntity(
id = playlistId,
name = playlistName
)
)
songs.map(SongItem::toMediaMetadata)
.onEach(::insert)
.forEach {
insert(
PlaylistSongMap(
playlistId = playlistId,
songId = it.id,
position = position++
)
)
}
}
Toast.makeText(context, context.resources.getQuantityString(R.plurals.import_success, songs.size, playlistName, songs.size), Toast.LENGTH_SHORT).show()
}
}.onFailure {
it.printStackTrace()
Toast.makeText(context, R.string.restore_failed, Toast.LENGTH_SHORT).show()
}
}

companion object {
const val SETTINGS_FILENAME = "settings.preferences_pb"
}
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-DE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Sichern und Wiederherstellen</string>
<string name="backup">Datensicherung</string>
<string name="restore">Wiederherstellen</string>
<string name="choose_csv_file_from_google_takeout">Wählen Sie eine csv-Datei von Google Takeout</string>
<string name="imported_playlist">Importierte Wiedergabeliste</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Sicherung erfolgreich erstellt</string>
<string name="backup_create_failed">Konnte keine Sicherung erstellen</string>
<string name="restore_failed">Wiederherstellung der Sicherung fehlgeschlagen</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,7 @@
<string name="backup_restore">Záloha a obnovení</string>
<string name="backup">Zálohovat</string>
<string name="restore">Obnovit</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Záloha úspěšně vytvořena</string>
<string name="backup_create_failed">Nepodařilo se vytvořit zálohu</string>
<string name="restore_failed">Nepodařilo se obnovit zálohu</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-es-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Backup and restore</string>
<string name="backup">Backup</string>
<string name="restore">Restore</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup created successfully</string>
<string name="backup_create_failed">Couldn\'t create backup</string>
<string name="restore_failed">Failed to restore backup</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Copias de seguridad y restauración</string>
<string name="backup">Hacer copia de seguridad</string>
<string name="restore">Restaurar</string>
<string name="choose_csv_file_from_google_takeout">Selecciona un archivo csv de Google Takeout</string>
<string name="imported_playlist">Lista de reproducción importada</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Copia de seguridad creada con éxito</string>
<string name="backup_create_failed">No se ha podido crear la copia de seguridad</string>
<string name="restore_failed">Error al restaurar la copia de seguridad</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-fa-rIR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">پشتیبان‌گیری و بازگردانی</string>
<string name="backup">پشتیبان‌گیری</string>
<string name="restore">بازگردانی</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">پشتیبان باموفقیت ایجادشد</string>
<string name="backup_create_failed">پشتیبان ایجاد نشد</string>
<string name="restore_failed">بازیابی پشتیبان انجام‌نشد</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-fi-rFI/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Backup and restore</string>
<string name="backup">Backup</string>
<string name="restore">Restore</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup created successfully</string>
<string name="backup_create_failed">Couldn\'t create backup</string>
<string name="restore_failed">Failed to restore backup</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-fr-rFR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,7 @@
<string name="backup_restore">Backup and restore</string>
<string name="backup">Backup</string>
<string name="restore">Restore</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup created successfully</string>
<string name="backup_create_failed">Couldn\'t create backup</string>
<string name="restore_failed">Failed to restore backup</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Bizt.mentés és visszaállítás</string>
<string name="backup">Bizt.mentés</string>
<string name="restore">Visszaállítás</string>
<string name="choose_csv_file_from_google_takeout">Válasszon egy csv-fájlt a Google Takeout-ból</string>
<string name="imported_playlist">Importált lejátszási lista</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">A bizt.mentés sikeresen létrehozva</string>
<string name="backup_create_failed">Nem sikerült biztonsági mentést készíteni</string>
<string name="restore_failed">Nem sikerült visszaállítani a biztonsági másolatot</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-id/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,7 @@
<string name="backup_restore">Cadangkan dan pulihkan</string>
<string name="backup">Cadangkan</string>
<string name="restore">Pulihkan</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Cadangan berhasil dibuat</string>
<string name="backup_create_failed">Tidak dapat membuat cadangan</string>
<string name="restore_failed">Gagal untuk memulihkan cadangan</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Backup e ripristino</string>
<string name="backup">Backup</string>
<string name="restore">Ripristina</string>
<string name="choose_csv_file_from_google_takeout">Scegli un file csv da Google Takeout</string>
<string name="imported_playlist">Playlist importata</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup creato con successo</string>
<string name="backup_create_failed">Impossibile eseguire il backup</string>
<string name="restore_failed">Impossibile eseguire il ripristino dal backup</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,7 @@
<string name="backup_restore">バックアップとリストア</string>
<string name="backup">バックアップ</string>
<string name="restore">リストア</string>
<string name="choose_csv_file_from_google_takeout">Google TakeoutからCSVファイルを選択してください</string>
<string name="imported_playlist">インポートしたプレイリスト</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">バックアップの作成に成功しました</string>
<string name="backup_create_failed">バックアップを作成できませんでした</string>
<string name="restore_failed">バックアップのリストアに失敗しました</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,7 @@
<string name="backup_restore">Backup and restore</string>
<string name="backup">Backup</string>
<string name="restore">Restore</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup created successfully</string>
<string name="backup_create_failed">Couldn\'t create backup</string>
<string name="restore_failed">Failed to restore backup</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-ml-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">ബാക്കപ്പും വീണ്ടെടുക്കലും</string>
<string name="backup">ബാക്കപ്പ്</string>
<string name="restore">വീണ്ടെടുക്കൽ</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">ബാക്കപ്പ് സൃഷ്‌ടിച്ചു</string>
<string name="backup_create_failed">ബാക്കപ്പ് സൃഷ്ടിക്കാൻ കഴിഞ്ഞില്ല</string>
<string name="restore_failed">ബാക്കപ്പ് പുനഃസ്ഥാപിക്കാൻ കഴിഞ്ഞില്ല</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Backup en herstel</string>
<string name="backup">Backup</string>
<string name="restore">Herstellen</string>
<string name="choose_csv_file_from_google_takeout">Kies een csv-bestand van Google Takeout</string>
<string name="imported_playlist">Afspeellijst geimporteerd</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Back-up succesvol gemaakt.</string>
<string name="backup_create_failed">Back-up maken mislukt.</string>
<string name="restore_failed">Fout bij terugzetten back-up.</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-or-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">ନକଲ ସଂରକ୍ଷଣ ଏବଂ ପୁନରୁଦ୍ଧାର କରନ୍ତୁ</string>
<string name="backup">ନକଲ ସଂରକ୍ଷଣ</string>
<string name="restore">ପୁନରୁଦ୍ଧାର କରନ୍ତୁ</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">ବ୍ୟାକଅପ୍ ସଫଳତାର ସହିତ ସୃଷ୍ଟି ହେଲା</string>
<string name="backup_create_failed">ବ୍ୟାକଅପ୍ ସୃଷ୍ଟି କରିପାରିବ ନାହିଁ</string>
<string name="restore_failed">ବ୍ୟାକଅପ୍ ପୁନରୁଦ୍ଧାର କରିବାରେ ବିଫଳ</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-pa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">ਬੈਕਅੱਪ ਅਤੇ ਰੀਸਟੋਰ</string>
<string name="backup">ਬੈਕਅੱਪ</string>
<string name="restore">ਰੀਸਟੋਰ</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">ਬੈਕਅੱਪ ਸਫਲਤਾਪੂਰਵਕ ਬਣਾਇਆ ਗਿਆ</string>
<string name="backup_create_failed">ਬੈਕਅੱਪ ਨਹੀਂ ਬਣਾਇਆ ਜਾ ਸਕਿਆ</string>
<string name="restore_failed">ਬੈਕਅੱਪ ਰੀਸਟੋਰ ਕਰਨਾ ਅਸਫਲ ਰਿਹਾ</string>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@
<string name="backup_restore">Backup e restauração</string>
<string name="backup">Backup</string>
<string name="restore">Restaurar</string>
<string name="choose_csv_file_from_google_takeout">Choose a csv file from Google Takeout</string>
<string name="imported_playlist">Imported playlist</string>
<plurals name="import_success" tools:ignore="MissingQuantity">
<item quantity="one">Imported \"%s\" with %d song</item>
<item quantity="other">Imported \"%s\" with %d songs</item>
</plurals>
<string name="backup_create_success">Backup criado com sucesso</string>
<string name="backup_create_failed">Não foi possível criar o backup</string>
<string name="restore_failed">Falha ao restaurar o backup</string>
Expand Down
Loading

0 comments on commit cf53ffd

Please sign in to comment.