Skip to content

Commit

Permalink
Aria2c installed + bug fix
Browse files Browse the repository at this point in the history
This commit contains the addition of the download library aria2c provided by youtubeDl-android to make download more reliable and fatser. Also a bug has been fixed in the song fragment where sometimes if there was no result for the given crash the app would crash. Also i added a better implementation of the progress bar bacuse using aria2c broke it
  • Loading branch information
kostas214 committed May 9, 2023
1 parent e50889b commit afc51f8
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 29 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdk 24
targetSdk 33
versionCode 1
versionName "1.1.1"
versionName "1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -51,6 +51,11 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
packagingOptions {
jniLibs {
useLegacyPackaging true
}
}
}

dependencies {
Expand All @@ -68,8 +73,9 @@ dependencies {


//YoutubeDl
implementation "com.github.yausername.youtubedl-android:library:3a0252d88b4ae573068c63c3d08fc52c66102d55"
implementation "com.github.yausername.youtubedl-android:ffmpeg:3a0252d88b4ae573068c63c3d08fc52c66102d55"
implementation 'com.github.yausername.youtubedl-android:library:-SNAPSHOT'
implementation 'com.github.yausername.youtubedl-android:ffmpeg:-SNAPSHOT' // Optional
implementation 'com.github.yausername.youtubedl-android:aria2c:-SNAPSHOT'

//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.SpotifyDownloader"
android:extractNativeLibs="true"
tools:targetApi="33"
android:name=".SpotifyDownloaderApplication">
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.spotifydownloader
import android.app.Application
import android.widget.Toast
import com.google.android.material.color.DynamicColors
import com.yausername.aria2c.Aria2c
import com.yausername.ffmpeg.FFmpeg
import com.yausername.youtubedl_android.YoutubeDL
import kotlinx.coroutines.Dispatchers
Expand All @@ -22,6 +23,7 @@ class SpotifyDownloaderApplication : Application(){
withContext(Dispatchers.IO) {
YoutubeDL.getInstance().init(this@SpotifyDownloaderApplication)
FFmpeg.getInstance().init(this@SpotifyDownloaderApplication)
Aria2c.getInstance().init(this@SpotifyDownloaderApplication);

YoutubeDL.getInstance().updateYoutubeDL(this@SpotifyDownloaderApplication)
println(YoutubeDL.getInstance().version(this@SpotifyDownloaderApplication))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class SongDownloadFragment : Fragment(R.layout.fragment_song_download) {
request.addOption("--audio-format", "mp3")
request.addOption("-R", "2")
request.addOption("--socket-timeout", "40")
request.addOption("--downloader", "libaria2c.so");
request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
println(request.buildCommand())


Expand All @@ -235,14 +237,15 @@ class SongDownloadFragment : Fragment(R.layout.fragment_song_download) {
try {
YoutubeDL.getInstance().execute(
request
) { progress: Float, _: Long, _: String? ->
) { _: Float, _: Long, status: String? ->
Log.d(tag,status!!)
if (binding.progressBar.progress<=90) {

if(progress>0){
runOnUiThread {
binding.progressBar.progress = progress.toInt()
binding.progressBar.incrementProgressBy(6)
}
}
//Log.d(tag,"Progress is $progress and the song is $songName")




Expand Down Expand Up @@ -289,6 +292,9 @@ class SongDownloadFragment : Fragment(R.layout.fragment_song_download) {
IOUtils.copy(ins, ops)
IOUtils.closeQuietly(ops)
IOUtils.closeQuietly(ins)
runOnUiThread {
binding.progressBar.incrementProgressBy(10)
}

}
else if (!(isDeviceOnline(context as Activity))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,24 @@ class SongFragment : Fragment(R.layout.fragment_song) {
val textInBox = binding.songNameEditText.text.toString()
val response = spotifyApi.getSearch(textInBox)

val searchResult = response.tracks.items[0]
val regex = Regex("[^A-Za-z0-9]")


songName = searchResult.name
imgUrl = searchResult.album.images[0].url
artistName = searchResult.artists[0].name
filename = regex.replace(searchResult.name, "")
albumName = searchResult.album.name
albumArtistName = searchResult.album.artists[0].name
releaseDate = searchResult.album.release_date
succesCode = 0


if (response.tracks.items.size !=0) {
val searchResult = response.tracks.items[0]
val regex = Regex("[^A-Za-z0-9]")
songName = searchResult.name
imgUrl = searchResult.album.images[0].url
artistName = searchResult.artists[0].name
filename = regex.replace(searchResult.name, "")
albumName = searchResult.album.name
albumArtistName = searchResult.album.artists[0].name
releaseDate = searchResult.album.release_date
succesCode = 0
}
else{
succesCode = 2
}



}catch (e:IOException){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ class downloadFragment : Fragment(R.layout.fragment_download) {
request.addOption("--audio-format", "mp3")
request.addOption("-R", "2")
request.addOption("--socket-timeout", "40")

request.addOption("--downloader", "libaria2c.so")
request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");




println(request.buildCommand())


Expand All @@ -321,17 +328,20 @@ class downloadFragment : Fragment(R.layout.fragment_download) {
try {
YoutubeDL.getInstance().execute(
request
) { progress: Float, _: Long, _: String? ->
//Log.d(tag,"Progress is $progress and the song is $songName")
if (progress >0){
songItems[position].progress = progress.toInt()
) { _: Float, _: Long, status: String? ->

Log.d(tag,status!!)

if (songItems[position].progress<=90) {
songItems[position].progress += 6
runOnUiThread {
adapter.notifyItemChanged(position)
}

}




}

}
Expand All @@ -356,6 +366,7 @@ class downloadFragment : Fragment(R.layout.fragment_download) {
}catch (e:IOException){
return 1
}

var destUri = data
val treeUri = Uri.parse(destUri.toString())
val docId = DocumentsContract.getTreeDocumentId(treeUri)
Expand All @@ -375,6 +386,12 @@ class downloadFragment : Fragment(R.layout.fragment_download) {
IOUtils.copy(ins, ops)
IOUtils.closeQuietly(ops)
IOUtils.closeQuietly(ins)
songItems[position].progress += 10
runOnUiThread {
adapter.notifyItemChanged(position)
}



}
else if (!(isDeviceOnline(context as Activity))) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

plugins {
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonFinalResIds=false
org.gradle.unsafe.configuration-cache=true

0 comments on commit afc51f8

Please sign in to comment.