reformated code
This commit is contained in:
@@ -28,16 +28,16 @@ import java.util.Objects;
|
||||
public class VideoDownloader{
|
||||
private static final int action_id = 1488;
|
||||
|
||||
public static boolean onClick(int id, VideoFile video, Context ctx) {
|
||||
if (id == action_id) {
|
||||
public static boolean onClick(int id, VideoFile video, Context ctx){
|
||||
if(id == action_id){
|
||||
downloadVideo(video, ctx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void injectAction(ArrayList<MenuBottomSheetAction> list, VideoFile video) {
|
||||
if (!video.U && !video.I1()) {
|
||||
public static void injectAction(ArrayList<MenuBottomSheetAction> list, VideoFile video){
|
||||
if(!video.U && !video.I1()){
|
||||
MenuBottomSheetAction downloadAction = new MenuBottomSheetAction(
|
||||
action_id,
|
||||
com.vtosters.lite.R.drawable.ic_download_outline_24,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package ru.vtosters.lite.downloaders.music;
|
||||
|
||||
public interface Callback {
|
||||
public interface Callback{
|
||||
void onProgress(int progress);
|
||||
|
||||
void onSuccess();
|
||||
|
||||
void onFailure();
|
||||
|
||||
void onSizeReceived(long size, long header);
|
||||
}
|
||||
|
||||
@@ -12,27 +12,27 @@ import java.util.List;
|
||||
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import ru.vtosters.lite.utils.StreamUtils;
|
||||
import ru.vtosters.lite.music.TransportStream;
|
||||
import ru.vtosters.lite.music.VKM3UParser;
|
||||
import ru.vtosters.lite.utils.StreamUtils;
|
||||
|
||||
public class M3UDownloader {
|
||||
|
||||
private String mURL;
|
||||
private File mOutDir;
|
||||
private Callback mCallback;
|
||||
|
||||
public M3UDownloader(String url, File outDir, Callback callback) {
|
||||
public class M3UDownloader{
|
||||
|
||||
private final String mURL;
|
||||
private final File mOutDir;
|
||||
private final Callback mCallback;
|
||||
|
||||
public M3UDownloader(String url, File outDir, Callback callback){
|
||||
mURL = url;
|
||||
mOutDir = outDir;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
|
||||
public void execute(){
|
||||
VKM3UParser parser = new VKM3UParser(mURL);
|
||||
List<TransportStream> tses = parser.getTransportStreams();
|
||||
mCallback.onProgress(5);
|
||||
for (TransportStream ts : tses) {
|
||||
for(TransportStream ts : tses) {
|
||||
String tsURL = parser.getBaseUrl() + ts.getName();
|
||||
Log.d("M3UDownloader", "Downloading " + tsURL);
|
||||
try {
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
package ru.vtosters.lite.music;
|
||||
|
||||
public class TransportStream {
|
||||
public class TransportStream{
|
||||
|
||||
public static final String METHOD_NONE = "NONE";
|
||||
public static final String METHOD_AES128 = "AES-128";
|
||||
|
||||
private String mMethod;
|
||||
private final String mMethod;
|
||||
private String mName;
|
||||
private String mKeyURL;
|
||||
|
||||
public TransportStream() {
|
||||
public TransportStream(){
|
||||
this.mMethod = METHOD_NONE;
|
||||
}
|
||||
|
||||
public TransportStream(String method, String keyURL) {
|
||||
public TransportStream(String method, String keyURL){
|
||||
this.mMethod = method;
|
||||
this.mKeyURL = keyURL;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
public String getMethod(){
|
||||
return mMethod;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getName(){
|
||||
return mName;
|
||||
}
|
||||
|
||||
public String getKeyURL() {
|
||||
public void setName(String name){
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String getKeyURL(){
|
||||
return mKeyURL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class VKM3UParser {
|
||||
public class VKM3UParser{
|
||||
private final String mData;
|
||||
private final List<TransportStream> mTransportStreams = new ArrayList<>();
|
||||
|
||||
@@ -13,23 +13,23 @@ public class VKM3UParser {
|
||||
private int mHeapSize = 0;
|
||||
private String mBaseURL;
|
||||
|
||||
public VKM3UParser(String data) {
|
||||
public VKM3UParser(String data){
|
||||
mData = data;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
private void init(){
|
||||
int i = 0;
|
||||
Scanner scanner = new Scanner(mData);
|
||||
while (scanner.hasNext()) {
|
||||
while(scanner.hasNext()) {
|
||||
String line = scanner.nextLine();
|
||||
mHeapSize += line.getBytes().length;
|
||||
if (line.startsWith("#EXT-X-TARGETDURATION")) {
|
||||
if(line.startsWith("#EXT-X-TARGETDURATION")){
|
||||
mDuration = Integer.parseInt(getDirectiveValue(line));
|
||||
} else if (line.startsWith("#EXT-X-KEY")) {
|
||||
} else if(line.startsWith("#EXT-X-KEY")){
|
||||
String base = getDirectiveValue(line);
|
||||
final TransportStream ts;
|
||||
if (!base.startsWith("METHOD=NONE")) {
|
||||
if(!base.startsWith("METHOD=NONE")){
|
||||
String keyURL = base.substring(base.indexOf("\"") + 1, base.lastIndexOf("\""));
|
||||
mBaseURL = keyURL.substring(0, keyURL.lastIndexOf("/") + 1);
|
||||
ts = new TransportStream(TransportStream.METHOD_AES128, keyURL);
|
||||
@@ -37,29 +37,29 @@ public class VKM3UParser {
|
||||
ts = new TransportStream();
|
||||
}
|
||||
mTransportStreams.add(ts);
|
||||
} else if (line.startsWith("#EXTINF")) {
|
||||
if (mTransportStreams.size() == i)
|
||||
} else if(line.startsWith("#EXTINF")){
|
||||
if(mTransportStreams.size() == i)
|
||||
mTransportStreams.add(new TransportStream());
|
||||
} else if (line.endsWith(".ts") || line.endsWith(".tp") || line.endsWith(".mpeg-ts") || line.endsWith(".m2ts")) {
|
||||
} else if(line.endsWith(".ts") || line.endsWith(".tp") || line.endsWith(".mpeg-ts") || line.endsWith(".m2ts")){
|
||||
mTransportStreams.get(i).setName(line);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDirectiveValue(String directive) {
|
||||
private String getDirectiveValue(String directive){
|
||||
return directive.substring(directive.indexOf(":") + 1);
|
||||
}
|
||||
|
||||
public int getHeapSize() {
|
||||
public int getHeapSize(){
|
||||
return mHeapSize;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
public String getBaseUrl(){
|
||||
return mBaseURL;
|
||||
}
|
||||
|
||||
public List<TransportStream> getTransportStreams() {
|
||||
public List<TransportStream> getTransportStreams(){
|
||||
return mTransportStreams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,9 +184,9 @@ public class Globals{
|
||||
InputStream is = conn.getInputStream();
|
||||
Bitmap bmp = BitmapFactory.decodeStream(is);
|
||||
|
||||
bmp = rounded? getBitmapClippedCircle(bmp) : bmp; // rounding
|
||||
bmp = rounded ? getBitmapClippedCircle(bmp) : bmp; // rounding
|
||||
|
||||
bmp = scaled? createScaledBitmap(bmp, convertDpToPixel(256), convertDpToPixel(256), true) : bmp; // scaling
|
||||
bmp = scaled ? createScaledBitmap(bmp, convertDpToPixel(256), convertDpToPixel(256), true) : bmp; // scaling
|
||||
|
||||
return new BitmapDrawable(getResources(), bmp); // return our drawable
|
||||
} catch (Exception e) {
|
||||
@@ -401,4 +401,14 @@ public class Globals{
|
||||
int centerHeight = height / 2;
|
||||
return new float[]{centerWidth, centerHeight};
|
||||
}
|
||||
|
||||
int[] toIntArray(List<Integer> list){
|
||||
int[] ret = new int[list.size()];
|
||||
int i = 0;
|
||||
for(Integer e : list) {
|
||||
/*if (e < 2000000000)*/
|
||||
ret[i++] = e;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
public class Multithreading{
|
||||
private static final Handler ui = new Handler(Looper.getMainLooper());
|
||||
|
||||
public static void runOnUi(Runnable run){
|
||||
ui.post(run);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user