diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 44a5b960..964bb325 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -9,7 +9,7 @@
-
+
',
+ '|',
+ '\"',
+ '.',
+ ':'
+ )
+ var name = fileName
+ for (c in illegalCharArray) {
+ name = fileName.replace(c, '_')
+ }
+ return name
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
index 9f60aef4..5cbd8d49 100644
--- a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
+++ b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
@@ -1,7 +1,6 @@
package com.shabinder.musicForEveryone.fragments
import android.os.Bundle
-import android.os.Environment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@@ -11,23 +10,20 @@ import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
-import com.github.kiulian.downloader.model.formats.Format
-import com.github.kiulian.downloader.model.quality.AudioQuality
import com.google.android.material.snackbar.Snackbar
import com.shabinder.musicForEveryone.R
import com.shabinder.musicForEveryone.SharedViewModel
import com.shabinder.musicForEveryone.bindImage
import com.shabinder.musicForEveryone.databinding.MainFragmentBinding
-import com.shabinder.musicForEveryone.utils.YoutubeConnector
+import com.shabinder.musicForEveryone.downloadHelper.DownloadHelper
import kaaes.spotify.webapi.android.SpotifyService
-import java.io.File
-class MainFragment : Fragment() {
+class MainFragment : Fragment(),DownloadHelper {
lateinit var binding:MainFragmentBinding
private lateinit var sharedViewModel: SharedViewModel
var spotify : SpotifyService? = null
-
+ var type:String = ""
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@@ -45,9 +41,9 @@ class MainFragment : Fragment() {
val spotifyLink = binding.spotifyLink.text.toString()
val link = spotifyLink.substringAfterLast('/' , "Error").substringBefore('?')
- val type = spotifyLink.substringBeforeLast('/' , "Error").substringAfterLast('/')
+ type = spotifyLink.substringBeforeLast('/' , "Error").substringAfterLast('/')
- Log.i("Fragment",link)
+ Log.i("Fragment", "$type : $link")
when(type){
"track" -> {
@@ -100,29 +96,9 @@ class MainFragment : Fragment() {
}
binding.btnDownload.setOnClickListener {
- val data = YoutubeConnector.search(
- "${binding.name.text} ${if(binding.artist.text != "TextView" ){binding.artist.text}else{""}}")
- ?.get(0)
- if (data==null){showToast("Youtube Request Failed!")}else{
- val ytDownloader = sharedViewModel.ytDownloader
- val video = ytDownloader?.getVideo(data.id)
- val details = video?.details()
-
- val outputDir = File(Environment.getExternalStorageDirectory().toString() + File.separator + "MyAudio")
- val format:Format = video?.findAudioWithQuality(AudioQuality.low)?.get(0) as Format
- val audioUrl = format.url()
- if (audioUrl != null) {
- Log.i("ytDownloader", audioUrl)
- }else{Log.i("YT audio url is null", format.toString())}
-
- val file:File = video.download( format , outputDir)
-
- Log.i("YT File Path=> ", file.path)
-
- Log.i("ytDownloader", details?.title()?:"Error")
- binding.name.text = details?.title()
+ downloadTrack(sharedViewModel.ytDownloader,sharedViewModel.downloadManager,"${binding.name.text} ${if(binding.artist.text != "TextView" ){binding.artist.text}else{""}}")
}
- }
+
return binding.root
}
diff --git a/app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeConnector.kt b/app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeInterface.kt
similarity index 96%
rename from app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeConnector.kt
rename to app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeInterface.kt
index ba9b7112..1c4c76e3 100644
--- a/app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeConnector.kt
+++ b/app/src/main/java/com/shabinder/musicForEveryone/utils/YoutubeInterface.kt
@@ -7,7 +7,7 @@ import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.youtube.YouTube
import java.io.IOException
-object YoutubeConnector {
+object YoutubeInterface {
private var youtube: YouTube? = null
private var query:YouTube.Search.List? = null
var apiKey:String = "AIzaSyDuRmMA_2mF56BjlhhNpa0SIbjMgjjFaEI"
@@ -15,8 +15,7 @@ object YoutubeConnector {
fun youtubeConnector() {
youtube =
- YouTube.Builder(NetHttpTransport(), JacksonFactory(),
- HttpRequestInitializer { })
+ YouTube.Builder(NetHttpTransport(), JacksonFactory(), HttpRequestInitializer { })
.setApplicationName("Music For Everyone").build()
try {
query = youtube?.search()?.list("id,snippet")
diff --git a/build.gradle b/build.gradle
index 4eddd351..31b62629 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,7 +10,7 @@ buildscript {
}
dependencies {
- classpath "com.android.tools.build:gradle:4.0.0"
+ classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//safe-Args
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"