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