mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
remove ffmpeg and allow downloading by video name
This commit is contained in:
parent
7c8ba4e552
commit
8e86b35477
@ -97,8 +97,6 @@ dependencies {
|
||||
// Do not update jackson annotations! It does not supports < API 26.
|
||||
implementation libs.jacksonAnnotations
|
||||
|
||||
implementation libs.mobileffmpeg
|
||||
|
||||
coreLibraryDesugaring libs.desugaring
|
||||
implementation libs.cronet.embedded
|
||||
implementation libs.cronet.okhttp
|
||||
|
@ -4,6 +4,7 @@ import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -41,6 +42,16 @@ class DownloadDialog : DialogFragment() {
|
||||
|
||||
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
|
||||
|
||||
binding.audioRadio.setOnClickListener {
|
||||
binding.videoSpinner.visibility = View.GONE
|
||||
binding.audioSpinner.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
binding.videoRadio.setOnClickListener {
|
||||
binding.audioSpinner.visibility = View.GONE
|
||||
binding.videoSpinner.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
builder.setView(binding.root)
|
||||
builder.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
@ -118,14 +129,15 @@ class DownloadDialog : DialogFragment() {
|
||||
if (binding.audioSpinner.size >= 1) binding.audioSpinner.setSelection(1)
|
||||
|
||||
binding.download.setOnClickListener {
|
||||
val selectedAudioUrl = audioUrl[binding.audioSpinner.selectedItemPosition]
|
||||
val selectedVideoUrl = vidUrl[binding.videoSpinner.selectedItemPosition]
|
||||
val selectedAudioUrl =
|
||||
if (binding.audioRadio.isChecked) audioUrl[binding.audioSpinner.selectedItemPosition] else ""
|
||||
val selectedVideoUrl =
|
||||
if (binding.videoRadio.isChecked) vidUrl[binding.videoSpinner.selectedItemPosition] else ""
|
||||
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
intent.putExtra("videoId", videoId)
|
||||
intent.putExtra("videoName", streams.title)
|
||||
intent.putExtra("videoUrl", selectedVideoUrl)
|
||||
intent.putExtra("audioUrl", selectedAudioUrl)
|
||||
intent.putExtra("duration", duration)
|
||||
context?.startService(intent)
|
||||
dismiss()
|
||||
}
|
||||
|
@ -1278,7 +1278,7 @@ class PlayerFragment : Fragment() {
|
||||
// get the name of the currently played chapter
|
||||
private fun getCurrentChapterIndex(): Int {
|
||||
val currentPosition = exoPlayer.currentPosition
|
||||
var chapterIndex: Int? = null
|
||||
var chapterIndex = 0
|
||||
|
||||
chapters.forEachIndexed { index, chapter ->
|
||||
// check whether the chapter start is greater than the current player position
|
||||
@ -1287,7 +1287,7 @@ class PlayerFragment : Fragment() {
|
||||
chapterIndex = index
|
||||
}
|
||||
}
|
||||
return chapterIndex!!
|
||||
return chapterIndex
|
||||
}
|
||||
|
||||
private fun setMediaSource(
|
||||
|
@ -17,7 +17,6 @@ import android.os.IBinder
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import com.github.libretube.DOWNLOAD_CHANNEL_ID
|
||||
import com.github.libretube.DOWNLOAD_FAILURE_NOTIFICATION_ID
|
||||
import com.github.libretube.DOWNLOAD_PENDING_NOTIFICATION_ID
|
||||
@ -35,11 +34,9 @@ class DownloadService : Service() {
|
||||
private lateinit var notification: NotificationCompat.Builder
|
||||
|
||||
private var downloadId: Long = -1
|
||||
private lateinit var videoId: String
|
||||
private lateinit var videoName: 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
|
||||
@ -52,13 +49,11 @@ class DownloadService : Service() {
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
videoId = intent?.getStringExtra("videoId")!!
|
||||
videoName = intent?.getStringExtra("videoName")!!
|
||||
videoUrl = intent.getStringExtra("videoUrl")!!
|
||||
audioUrl = intent.getStringExtra("audioUrl")!!
|
||||
duration = intent.getIntExtra("duration", 1)
|
||||
extension = PreferenceHelper.getString(PreferenceKeys.DOWNLOAD_VIDEO_FORMAT, ".mp4")!!
|
||||
downloadType = if (audioUrl != "" && videoUrl != "") DownloadType.MUX
|
||||
else if (audioUrl != "") DownloadType.AUDIO
|
||||
|
||||
downloadType = if (audioUrl != "") DownloadType.AUDIO
|
||||
else if (videoUrl != "") DownloadType.VIDEO
|
||||
else DownloadType.NONE
|
||||
if (downloadType != DownloadType.NONE) {
|
||||
@ -115,18 +110,8 @@ class DownloadService : Service() {
|
||||
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||
)
|
||||
when (downloadType) {
|
||||
DownloadType.MUX -> {
|
||||
audioDir = File(tempDir, "$videoId-audio")
|
||||
videoDir = File(tempDir, "$videoId-video")
|
||||
downloadId = downloadManagerRequest(
|
||||
getString(R.string.video),
|
||||
getString(R.string.downloading),
|
||||
videoUrl,
|
||||
videoDir
|
||||
)
|
||||
}
|
||||
DownloadType.VIDEO -> {
|
||||
videoDir = File(libretubeDir, "$videoId-video")
|
||||
videoDir = File(libretubeDir, videoName)
|
||||
downloadId = downloadManagerRequest(
|
||||
getString(R.string.video),
|
||||
getString(R.string.downloading),
|
||||
@ -135,7 +120,7 @@ class DownloadService : Service() {
|
||||
)
|
||||
}
|
||||
DownloadType.AUDIO -> {
|
||||
audioDir = File(libretubeDir, "$videoId-audio")
|
||||
audioDir = File(libretubeDir, videoName)
|
||||
downloadId = downloadManagerRequest(
|
||||
getString(R.string.audio),
|
||||
getString(R.string.downloading),
|
||||
@ -146,6 +131,7 @@ class DownloadService : Service() {
|
||||
}
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.e(TAG, "download error $e")
|
||||
downloadFailedNotification()
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,11 +152,6 @@ class DownloadService : Service() {
|
||||
downloadSucceededNotification()
|
||||
onDestroy()
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
muxDownloadedMedia()
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,7 +214,7 @@ class DownloadService : Service() {
|
||||
val builder = NotificationCompat.Builder(this@DownloadService, DOWNLOAD_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_download)
|
||||
.setContentTitle(resources.getString(R.string.success))
|
||||
.setContentText(getString(R.string.fail))
|
||||
.setContentText(getString(R.string.downloadsucceeded))
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
with(NotificationManagerCompat.from(this@DownloadService)) {
|
||||
// notificationId is a unique int for each notification that you must define
|
||||
@ -241,39 +222,6 @@ class DownloadService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun muxDownloadedMedia() {
|
||||
val command = "-y -i $videoDir -i $audioDir -c copy $libretubeDir/${videoId}$extension"
|
||||
notification.setContentTitle("Muxing")
|
||||
FFmpegKit.executeAsync(
|
||||
command,
|
||||
{ session ->
|
||||
val state = session.state
|
||||
val returnCode = session.returnCode
|
||||
// CALLED WHEN SESSION IS EXECUTED
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
"FFmpeg process exited with state %s and rc %s.%s",
|
||||
state,
|
||||
returnCode,
|
||||
session.failStackTrace
|
||||
)
|
||||
)
|
||||
tempDir.deleteRecursively()
|
||||
if (returnCode.toString() != "0") downloadFailedNotification()
|
||||
else downloadSucceededNotification()
|
||||
onDestroy()
|
||||
},
|
||||
{
|
||||
// CALLED WHEN SESSION PRINTS LOGS
|
||||
Log.e(TAG, it.message.toString())
|
||||
}
|
||||
) {
|
||||
// CALLED WHEN SESSION GENERATES STATISTICS
|
||||
Log.e(TAG + "stat", it.time.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
try {
|
||||
unregisterReceiver(onDownloadComplete)
|
||||
|
@ -4,7 +4,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
@ -14,6 +13,28 @@
|
||||
android:text="@string/app_name"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:checkedButton="@id/video_radio"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/video_radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/video" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/audio_radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@string/audio" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/video_spinner"
|
||||
android:layout_width="match_parent"
|
||||
@ -24,12 +45,13 @@
|
||||
android:id="@+id/audio_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp" />
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/download"
|
||||
style="@style/CustomDialogButton"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@string/download" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -289,4 +289,5 @@
|
||||
<string name="no_search_result">No results found.</string>
|
||||
<string name="error_occurred">Error occurred</string>
|
||||
<string name="copied">Copied</string>
|
||||
<string name="downloadsucceeded">Download succeeded</string>
|
||||
</resources>
|
@ -4,15 +4,6 @@
|
||||
|
||||
<PreferenceCategory app:title="@string/downloads">
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue=".mp4"
|
||||
app:entries="@array/videoFormats"
|
||||
app:entryValues="@array/videoFormatsValues"
|
||||
app:icon="@drawable/ic_videocam"
|
||||
app:key="video_format"
|
||||
app:summary="@string/video_format_summary"
|
||||
app:title="@string/video_format" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="downloads"
|
||||
android:entries="@array/downloadLocation"
|
||||
|
Loading…
Reference in New Issue
Block a user