mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
cleanup
This commit is contained in:
parent
fb3bb67933
commit
ff6da91fa4
@ -26,4 +26,9 @@ const val TWITTER_URL = "https://twitter.com/libretube"
|
||||
* Share Dialog
|
||||
*/
|
||||
const val PIPED_FRONTEND_URL = "https://piped.kavin.rocks"
|
||||
const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
|
||||
const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
|
||||
|
||||
/**
|
||||
* Retrofit Instance
|
||||
*/
|
||||
const val PIPED_API_URL = "https://pipedapi.kavin.rocks/"
|
||||
|
@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.github.libretube.PIPED_API_URL
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.ActivityMainBinding
|
||||
import com.github.libretube.fragments.PlayerFragment
|
||||
@ -74,14 +75,14 @@ class MainActivity : AppCompatActivity() {
|
||||
CronetHelper.initCronet(this.applicationContext)
|
||||
|
||||
RetrofitInstance.url =
|
||||
PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!!
|
||||
PreferenceHelper.getString(this, "selectInstance", PIPED_API_URL)!!
|
||||
// set auth instance
|
||||
RetrofitInstance.authUrl =
|
||||
if (PreferenceHelper.getBoolean(this, "auth_instance_toggle", false)) {
|
||||
PreferenceHelper.getString(
|
||||
this,
|
||||
"selectAuthInstance",
|
||||
"https://pipedapi.kavin.rocks/"
|
||||
PIPED_API_URL
|
||||
)!!
|
||||
} else {
|
||||
RetrofitInstance.url
|
||||
|
@ -28,7 +28,6 @@ class DownloadDialog : DialogFragment() {
|
||||
private val TAG = "DownloadDialog"
|
||||
private lateinit var binding: DialogDownloadBinding
|
||||
|
||||
private lateinit var streams: Streams
|
||||
private lateinit var videoId: String
|
||||
private var duration = 0
|
||||
|
||||
@ -86,7 +85,7 @@ class DownloadDialog : DialogFragment() {
|
||||
private fun fetchStreams() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getStreams(videoId!!)
|
||||
RetrofitInstance.api.getStreams(videoId)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
@ -102,8 +101,8 @@ class DownloadDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun initDownloadOptions(streams: Streams) {
|
||||
var vidName = arrayListOf<String>()
|
||||
var vidUrl = arrayListOf<String>()
|
||||
val vidName = arrayListOf<String>()
|
||||
val vidUrl = arrayListOf<String>()
|
||||
|
||||
// add empty selection
|
||||
vidName.add(getString(R.string.no_video))
|
||||
@ -116,8 +115,8 @@ class DownloadDialog : DialogFragment() {
|
||||
vidUrl.add(vid.url!!)
|
||||
}
|
||||
|
||||
var audioName = arrayListOf<String>()
|
||||
var audioUrl = arrayListOf<String>()
|
||||
val audioName = arrayListOf<String>()
|
||||
val audioUrl = arrayListOf<String>()
|
||||
|
||||
// add empty selection
|
||||
audioName.add(getString(R.string.no_audio))
|
||||
|
@ -59,7 +59,7 @@ class ShareDialog(
|
||||
val instancePref = PreferenceHelper.getString(
|
||||
requireContext(),
|
||||
"selectInstance",
|
||||
"https://pipedapi.kavin.rocks"
|
||||
PIPED_FRONTEND_URL
|
||||
)
|
||||
|
||||
// get the api urls of the other custom instances
|
||||
|
11
app/src/main/java/com/github/libretube/obj/DownloadType.kt
Normal file
11
app/src/main/java/com/github/libretube/obj/DownloadType.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
/**
|
||||
* object for saving the download type
|
||||
*/
|
||||
object DownloadType {
|
||||
const val AUDIO = 0
|
||||
const val VIDEO = 1
|
||||
const val MUX = 2
|
||||
const val NONE = 3
|
||||
}
|
@ -19,6 +19,7 @@ import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.DownloadType
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
import java.io.File
|
||||
|
||||
@ -26,17 +27,19 @@ var IS_DOWNLOAD_RUNNING = false
|
||||
|
||||
class DownloadService : Service() {
|
||||
val TAG = "DownloadService"
|
||||
|
||||
private lateinit var notification: NotificationCompat.Builder
|
||||
|
||||
private var downloadId: Long = -1
|
||||
private lateinit var videoId: String
|
||||
private lateinit var videoUrl: String
|
||||
private lateinit var audioUrl: String
|
||||
private lateinit var extension: String
|
||||
private var duration: Int = 0
|
||||
private var downloadType: Int = 3
|
||||
|
||||
private lateinit var audioDir: File
|
||||
private lateinit var videoDir: File
|
||||
private lateinit var notification: NotificationCompat.Builder
|
||||
private lateinit var downloadType: String
|
||||
private lateinit var libretubeDir: File
|
||||
private lateinit var tempDir: File
|
||||
override fun onCreate() {
|
||||
@ -50,11 +53,11 @@ class DownloadService : Service() {
|
||||
audioUrl = intent.getStringExtra("audioUrl")!!
|
||||
duration = intent.getIntExtra("duration", 1)
|
||||
extension = PreferenceHelper.getString(this, "video_format", ".mp4")!!
|
||||
downloadType = if (audioUrl != "" && videoUrl != "") "mux"
|
||||
else if (audioUrl != "") "audio"
|
||||
else if (videoUrl != "") "video"
|
||||
else "none"
|
||||
if (downloadType != "none") {
|
||||
downloadType = if (audioUrl != "" && videoUrl != "") DownloadType.MUX
|
||||
else if (audioUrl != "") DownloadType.AUDIO
|
||||
else if (videoUrl != "") DownloadType.VIDEO
|
||||
else DownloadType.NONE
|
||||
if (downloadType != DownloadType.NONE) {
|
||||
downloadNotification(intent)
|
||||
downloadManager()
|
||||
} else {
|
||||
@ -108,7 +111,7 @@ class DownloadService : Service() {
|
||||
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||
)
|
||||
when (downloadType) {
|
||||
"mux" -> {
|
||||
DownloadType.MUX -> {
|
||||
audioDir = File(tempDir, "$videoId-audio")
|
||||
videoDir = File(tempDir, "$videoId-video")
|
||||
downloadId = downloadManagerRequest(
|
||||
@ -118,7 +121,7 @@ class DownloadService : Service() {
|
||||
videoDir
|
||||
)
|
||||
}
|
||||
"video" -> {
|
||||
DownloadType.VIDEO -> {
|
||||
videoDir = File(libretubeDir, "$videoId-video")
|
||||
downloadId = downloadManagerRequest(
|
||||
getString(R.string.video),
|
||||
@ -127,7 +130,7 @@ class DownloadService : Service() {
|
||||
videoDir
|
||||
)
|
||||
}
|
||||
"audio" -> {
|
||||
DownloadType.AUDIO -> {
|
||||
audioDir = File(libretubeDir, "$videoId-audio")
|
||||
downloadId = downloadManagerRequest(
|
||||
getString(R.string.audio),
|
||||
@ -148,7 +151,7 @@ class DownloadService : Service() {
|
||||
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
||||
// Checking if the received broadcast is for our enqueued download by matching download id
|
||||
if (downloadId == id) {
|
||||
if (downloadType == "mux") {
|
||||
if (downloadType == DownloadType.MUX) {
|
||||
downloadManagerRequest(
|
||||
getString(R.string.audio),
|
||||
getString(R.string.downloading),
|
||||
|
Loading…
Reference in New Issue
Block a user