Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.35 KB | None | 0 0
  1. package eu.aei.launcher.services;
  2.  
  3. import android.app.Service;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.os.AsyncTask;
  8. import android.os.IBinder;
  9. import android.preference.PreferenceManager;
  10. import android.support.annotation.Nullable;
  11. import android.util.Log;
  12. import eu.aei.digisender.launcher.R;
  13. import eu.aei.launcher.util.Tools;
  14. import java.io.BufferedInputStream;
  15. import java.io.File;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import java.net.URL;
  19. import java.util.Locale;
  20.  
  21. public class YoutubeDataService extends Service {
  22. private String YouTubeKey = "AIzaSyDmUBFDDPYfi-11DAt1vQ6ygPapAXzlEos";
  23. private String YouTubeURL = "https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&regionCode=";
  24. private Context mContext;
  25. private SharedPreferences mSharedPref;
  26. private AsyncTask mSyncRequestYouTube;
  27.  
  28. class DownloadTask extends AsyncTask<String, String, String> {
  29. String fileOutputName;
  30. String fileOutputNameTemp;
  31.  
  32. DownloadTask() {
  33. }
  34.  
  35. /* Access modifiers changed, original: protected|varargs */
  36. public String doInBackground(String... strArr) {
  37. try {
  38. Log.d("Preference", strArr[0]);
  39. URL url = new URL(strArr[0]);
  40. int contentLength = url.openConnection().getContentLength();
  41. this.fileOutputName = strArr[1];
  42. StringBuilder stringBuilder = new StringBuilder();
  43. stringBuilder.append(Tools.randomString(5));
  44. stringBuilder.append(".tmp");
  45. this.fileOutputNameTemp = stringBuilder.toString();
  46. BufferedInputStream bufferedInputStream = new BufferedInputStream(url.openStream(), 8192);
  47. StringBuilder stringBuilder2 = new StringBuilder();
  48. stringBuilder2.append(YoutubeDataService.this.getFilesDir().getPath());
  49. stringBuilder2.append(this.fileOutputNameTemp);
  50. FileOutputStream fileOutputStream = new FileOutputStream(stringBuilder2.toString());
  51. byte[] bArr = new byte[1024];
  52. long j = 0;
  53. while (true) {
  54. int read = bufferedInputStream.read(bArr);
  55. if (read == -1) {
  56. break;
  57. }
  58. j += (long) read;
  59. String[] strArr2 = new String[1];
  60. StringBuilder stringBuilder3 = new StringBuilder();
  61. stringBuilder3.append("");
  62. stringBuilder3.append((int) ((100 * j) / ((long) contentLength)));
  63. strArr2[0] = stringBuilder3.toString();
  64. publishProgress(strArr2);
  65. fileOutputStream.write(bArr, 0, read);
  66. }
  67. fileOutputStream.flush();
  68. fileOutputStream.close();
  69. bufferedInputStream.close();
  70. } catch (IOException unused) {
  71. }
  72. return null;
  73. }
  74.  
  75. /* Access modifiers changed, original: protected */
  76. public void onPostExecute(String str) {
  77. StringBuilder stringBuilder = new StringBuilder();
  78. stringBuilder.append(YoutubeDataService.this.getFilesDir().getPath());
  79. stringBuilder.append(this.fileOutputNameTemp);
  80. File file = new File(stringBuilder.toString());
  81. StringBuilder stringBuilder2 = new StringBuilder();
  82. stringBuilder2.append(YoutubeDataService.this.getFilesDir().getPath());
  83. stringBuilder2.append(this.fileOutputName);
  84. File file2 = new File(stringBuilder2.toString());
  85. if (file.exists()) {
  86. Tools.RenameFile(file, file2);
  87. }
  88. Tools.createRefreshBroadcast(YoutubeDataService.this.mContext);
  89. Log.d("", "REFRESH YOUTUBE SERVICE ");
  90. }
  91.  
  92. /* Access modifiers changed, original: protected */
  93. public void onPreExecute() {
  94. super.onPreExecute();
  95. }
  96. }
  97.  
  98. @Nullable
  99. public IBinder onBind(Intent intent) {
  100. return null;
  101. }
  102.  
  103. public int onStartCommand(Intent intent, int i, int i2) {
  104. String stringBuilder;
  105. String stringBuilder2;
  106. this.mContext = this;
  107. PreferenceManager.setDefaultValues(this.mContext, R.xml.pref_content, false);
  108. this.mSharedPref = PreferenceManager.getDefaultSharedPreferences(this.mContext);
  109. StringBuilder stringBuilder3;
  110. if (this.mSharedPref.getString("pref_content_type", "0").equals("0")) {
  111. stringBuilder3 = new StringBuilder();
  112. stringBuilder3.append("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&regionCode=");
  113. stringBuilder3.append(Locale.getDefault().getCountry());
  114. stringBuilder3.append("&maxResults=20&key=AIzaSyDmUBFDDPYfi-11DAt1vQ6ygPapAXzlEos");
  115. stringBuilder = stringBuilder3.toString();
  116. } else {
  117. stringBuilder3 = new StringBuilder();
  118. stringBuilder3.append("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&regionCode=");
  119. stringBuilder3.append(Locale.getDefault().getCountry());
  120. stringBuilder3.append("&maxResults=20&key=AIzaSyDmUBFDDPYfi-11DAt1vQ6ygPapAXzlEos&videoCategoryId=");
  121. stringBuilder3.append(this.mSharedPref.getString("pref_content_type", "0"));
  122. stringBuilder = stringBuilder3.toString();
  123. }
  124. StringBuilder stringBuilder4;
  125. if (this.mSharedPref.getString("pref_content_type2", "24").equals("0")) {
  126. stringBuilder4 = new StringBuilder();
  127. stringBuilder4.append("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&regionCode=");
  128. stringBuilder4.append(Locale.getDefault().getCountry());
  129. stringBuilder4.append("&maxResults=20&key=AIzaSyDmUBFDDPYfi-11DAt1vQ6ygPapAXzlEos");
  130. stringBuilder2 = stringBuilder4.toString();
  131. } else {
  132. stringBuilder4 = new StringBuilder();
  133. stringBuilder4.append("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&regionCode=");
  134. stringBuilder4.append(Locale.getDefault().getCountry());
  135. stringBuilder4.append("&maxResults=20&key=AIzaSyDmUBFDDPYfi-11DAt1vQ6ygPapAXzlEos&videoCategoryId=");
  136. stringBuilder4.append(this.mSharedPref.getString("pref_content_type2", "24"));
  137. stringBuilder2 = stringBuilder4.toString();
  138. }
  139. StringBuilder stringBuilder5 = new StringBuilder();
  140. stringBuilder5.append("YOUTUBE SERVICE ");
  141. stringBuilder5.append(this.mSharedPref.getString("pref_content_type2", "24"));
  142. Log.d("", stringBuilder5.toString());
  143. Tools.incrementBroadcastCount(this.mContext);
  144. Tools.incrementBroadcastCount(this.mContext);
  145. this.mSyncRequestYouTube = new DownloadTask().execute(new String[]{stringBuilder, "/youtube.json"});
  146. this.mSyncRequestYouTube = new DownloadTask().execute(new String[]{stringBuilder2, "/youtube2.json"});
  147. return 1;
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement