mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	fixed download location
This commit is contained in:
		| @@ -57,7 +57,7 @@ public class App extends Application { | |||||||
|     /** |     /** | ||||||
|      * Set the proxy settings based on whether Tor should be enabled or not. |      * Set the proxy settings based on whether Tor should be enabled or not. | ||||||
|      */ |      */ | ||||||
|     static void configureTor(boolean enabled) { |     public static void configureTor(boolean enabled) { | ||||||
|         useTor = enabled; |         useTor = enabled; | ||||||
|         if (useTor) { |         if (useTor) { | ||||||
|             NetCipher.useTor(); |             NetCipher.useTor(); | ||||||
| @@ -66,13 +66,13 @@ public class App extends Application { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static void checkStartTor(Context context) { |     public static void checkStartTor(Context context) { | ||||||
|         if (useTor) { |         if (useTor) { | ||||||
|             OrbotHelper.requestStartTor(context); |             OrbotHelper.requestStartTor(context); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static boolean isUsingTor() { |     public static boolean isUsingTor() { | ||||||
|         return useTor; |         return useTor; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -25,7 +25,6 @@ import android.content.SharedPreferences; | |||||||
| import android.os.Environment; | import android.os.Environment; | ||||||
| import android.preference.PreferenceManager; | import android.preference.PreferenceManager; | ||||||
| import android.support.annotation.NonNull; | import android.support.annotation.NonNull; | ||||||
| import android.util.Log; |  | ||||||
|  |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
|  |  | ||||||
| @@ -43,10 +42,6 @@ public class NewPipeSettings { | |||||||
|         getAudioDownloadFolder(context); |         getAudioDownloadFolder(context); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static File getDownloadFolder() { |  | ||||||
|         return getFolder(Environment.DIRECTORY_DOWNLOADS); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static File getVideoDownloadFolder(Context context) { |     public static File getVideoDownloadFolder(Context context) { | ||||||
|         return getFolder(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES); |         return getFolder(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -48,6 +48,7 @@ import java.util.ArrayList; | |||||||
| import java.util.Vector; | import java.util.Vector; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | import org.schabi.newpipe.download.DownloadDialog; | ||||||
| import org.schabi.newpipe.extractor.AudioStream; | import org.schabi.newpipe.extractor.AudioStream; | ||||||
| import org.schabi.newpipe.extractor.MediaFormat; | import org.schabi.newpipe.extractor.MediaFormat; | ||||||
| import org.schabi.newpipe.extractor.ParsingException; | import org.schabi.newpipe.extractor.ParsingException; | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe; | package org.schabi.newpipe.download; | ||||||
| 
 | 
 | ||||||
| import android.Manifest; | import android.Manifest; | ||||||
| import android.app.Dialog; | import android.app.Dialog; | ||||||
| @@ -16,6 +16,10 @@ import android.support.v7.app.AlertDialog; | |||||||
| import android.util.Log; | import android.util.Log; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
|  | import org.schabi.newpipe.App; | ||||||
|  | import org.schabi.newpipe.NewPipeSettings; | ||||||
|  | import org.schabi.newpipe.R; | ||||||
|  | 
 | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @@ -71,7 +75,8 @@ public class DownloadDialog extends DialogFragment { | |||||||
|                         case 0:     // Video |                         case 0:     // Video | ||||||
|                             download(arguments.getString(VIDEO_URL), |                             download(arguments.getString(VIDEO_URL), | ||||||
|                                     title, |                                     title, | ||||||
|                                     arguments.getString(FILE_SUFFIX_VIDEO), context); |                                     arguments.getString(FILE_SUFFIX_VIDEO), | ||||||
|  |                                     NewPipeSettings.getVideoDownloadFolder(context),context); | ||||||
|                             break; |                             break; | ||||||
|                         default: |                         default: | ||||||
|                             Log.d(TAG, "lolz"); |                             Log.d(TAG, "lolz"); | ||||||
| @@ -89,7 +94,8 @@ public class DownloadDialog extends DialogFragment { | |||||||
|                         case 0:     // Audio |                         case 0:     // Audio | ||||||
|                             download(arguments.getString(AUDIO_URL), |                             download(arguments.getString(AUDIO_URL), | ||||||
|                                     title, |                                     title, | ||||||
|                                     arguments.getString(FILE_SUFFIX_AUDIO), context); |                                     arguments.getString(FILE_SUFFIX_AUDIO), | ||||||
|  |                                     NewPipeSettings.getAudioDownloadFolder(context),context); | ||||||
|                             break; |                             break; | ||||||
|                         default: |                         default: | ||||||
|                             Log.d(TAG, "lolz"); |                             Log.d(TAG, "lolz"); | ||||||
| @@ -107,12 +113,14 @@ public class DownloadDialog extends DialogFragment { | |||||||
|                         case 0:     // Video |                         case 0:     // Video | ||||||
|                             download(arguments.getString(VIDEO_URL), |                             download(arguments.getString(VIDEO_URL), | ||||||
|                                     title, |                                     title, | ||||||
|                                     arguments.getString(FILE_SUFFIX_VIDEO), context); |                                     arguments.getString(FILE_SUFFIX_VIDEO), | ||||||
|  |                                     NewPipeSettings.getVideoDownloadFolder(context), context); | ||||||
|                             break; |                             break; | ||||||
|                         case 1: |                         case 1: | ||||||
|                             download(arguments.getString(AUDIO_URL), |                             download(arguments.getString(AUDIO_URL), | ||||||
|                                     title, |                                     title, | ||||||
|                                     arguments.getString(FILE_SUFFIX_AUDIO), context); |                                     arguments.getString(FILE_SUFFIX_AUDIO), | ||||||
|  |                                     NewPipeSettings.getAudioDownloadFolder(context), context); | ||||||
|                             break; |                             break; | ||||||
|                         default: |                         default: | ||||||
|                             Log.d(TAG, "lolz"); |                             Log.d(TAG, "lolz"); | ||||||
| @@ -141,8 +149,8 @@ public class DownloadDialog extends DialogFragment { | |||||||
|         return nameToTest; |         return nameToTest; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void download(String url, String title, String fileSuffix, Context context) { |     private void download(String url, String title, | ||||||
|         File downloadDir = NewPipeSettings.getDownloadFolder(); |                           String fileSuffix, File downloadDir, Context context) { | ||||||
| 
 | 
 | ||||||
|         if(!downloadDir.exists()) { |         if(!downloadDir.exists()) { | ||||||
|             //attempt to create directory |             //attempt to create directory | ||||||
| @@ -162,6 +170,8 @@ public class DownloadDialog extends DialogFragment { | |||||||
|         File saveFilePath = new File(downloadDir,createFileName(title) + fileSuffix); |         File saveFilePath = new File(downloadDir,createFileName(title) + fileSuffix); | ||||||
| 
 | 
 | ||||||
|         long id = 0; |         long id = 0; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         if (App.isUsingTor()) { |         if (App.isUsingTor()) { | ||||||
|             // if using Tor, do not use DownloadManager because the proxy cannot be set |             // if using Tor, do not use DownloadManager because the proxy cannot be set | ||||||
|             FileDownloader.downloadFile(getContext(), url, saveFilePath, title); |             FileDownloader.downloadFile(getContext(), url, saveFilePath, title); | ||||||
| @@ -1,26 +1,21 @@ | |||||||
| package org.schabi.newpipe; | package org.schabi.newpipe.download; | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| import android.app.NotificationManager; | import android.app.NotificationManager; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.SharedPreferences; |  | ||||||
| import android.graphics.drawable.BitmapDrawable; | import android.graphics.drawable.BitmapDrawable; | ||||||
| import android.graphics.drawable.Drawable; | import android.graphics.drawable.Drawable; | ||||||
| import android.os.AsyncTask; | import android.os.AsyncTask; | ||||||
| import android.preference.PreferenceManager; |  | ||||||
| import android.support.v4.app.NotificationCompat; | import android.support.v4.app.NotificationCompat; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
| 
 | 
 | ||||||
|  | import org.schabi.newpipe.R; | ||||||
|  | 
 | ||||||
| import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||||
| import java.io.BufferedReader; |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.io.InputStreamReader; |  | ||||||
| import java.net.HttpURLConnection; | import java.net.HttpURLConnection; | ||||||
| import java.net.URL; |  | ||||||
| import java.net.UnknownHostException; |  | ||||||
| 
 | 
 | ||||||
| import javax.net.ssl.HttpsURLConnection; | import javax.net.ssl.HttpsURLConnection; | ||||||
| 
 | 
 | ||||||
| @@ -46,6 +41,8 @@ import info.guardianproject.netcipher.NetCipher; | |||||||
|  * along with NewPipe.  If not, see <http://www.gnu.org/licenses/>. |  * along with NewPipe.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | // TODO: FOR HEVEN SAKE !!! DO NOT SIMPLY USE ASYNCTASK. MAKE THIS A PROPER SERVICE !!! | ||||||
| public class FileDownloader extends AsyncTask<Void, Integer, Void> { | public class FileDownloader extends AsyncTask<Void, Integer, Void> { | ||||||
|     public static final String TAG = "FileDownloader"; |     public static final String TAG = "FileDownloader"; | ||||||
| 
 | 
 | ||||||
| @@ -165,5 +162,4 @@ public class FileDownloader extends AsyncTask<Void, Integer, Void> { | |||||||
|         super.onPostExecute(aVoid); |         super.onPostExecute(aVoid); | ||||||
|         nm.cancel(notifyId); |         nm.cancel(notifyId); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger