mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 02:53:09 +01:00
refactoring VideoInfo & MediaFormat, part 2:
* fixed errors caused by moving media format code to MediaFormat enum
This commit is contained in:
parent
c87458590c
commit
2fc2fa56c3
@ -77,7 +77,7 @@ public class ActionBarHandler {
|
|||||||
int defaultResolutionPos = 0;
|
int defaultResolutionPos = 0;
|
||||||
|
|
||||||
for(int i = 0; i < videoStreams.length; i++) {
|
for(int i = 0; i < videoStreams.length; i++) {
|
||||||
itemArray[i] = VideoInfo.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
|
itemArray[i] = MediaFormat.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
|
||||||
if(defaultResolution.equals(videoStreams[i].resolution)) {
|
if(defaultResolution.equals(videoStreams[i].resolution)) {
|
||||||
defaultResolutionPos = i;
|
defaultResolutionPos = i;
|
||||||
}
|
}
|
||||||
@ -98,14 +98,14 @@ public class ActionBarHandler {
|
|||||||
.getString(activity.getString(R.string.defaultAudioFormatPreference), "webm");
|
.getString(activity.getString(R.string.defaultAudioFormatPreference), "webm");
|
||||||
if(preferedFormat.equals("webm")) {
|
if(preferedFormat.equals("webm")) {
|
||||||
for(VideoInfo.AudioStream s : audioStreams) {
|
for(VideoInfo.AudioStream s : audioStreams) {
|
||||||
if(s.format == VideoInfo.I_WEBMA) {
|
if(s.format == MediaFormat.WEBMA.id) {
|
||||||
audioStream = s;
|
audioStream = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(preferedFormat.equals("m4a")){
|
} else if(preferedFormat.equals("m4a")){
|
||||||
for(VideoInfo.AudioStream s : audioStreams) {
|
for(VideoInfo.AudioStream s : audioStreams) {
|
||||||
Log.d(TAG, VideoInfo.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
|
Log.d(TAG, MediaFormat.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
|
||||||
if(s.format == VideoInfo.I_M4A &&
|
if(s.format == MediaFormat.M4A.id &&
|
||||||
(audioStream == null || audioStream.bandwidth > s.bandwidth)) {
|
(audioStream == null || audioStream.bandwidth > s.bandwidth)) {
|
||||||
audioStream = s;
|
audioStream = s;
|
||||||
Log.d(TAG, "last choosen");
|
Log.d(TAG, "last choosen");
|
||||||
@ -196,7 +196,7 @@ public class ActionBarHandler {
|
|||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
|
||||||
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
|
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
|
||||||
VideoInfo.getMimeById(videoStreams[selectedStream].format));
|
MediaFormat.getMimeById(videoStreams[selectedStream].format));
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
|
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
|
||||||
intent.putExtra("title", videoTitle);
|
intent.putExtra("title", videoTitle);
|
||||||
|
|
||||||
@ -237,8 +237,8 @@ public class ActionBarHandler {
|
|||||||
public void downloadVideo() {
|
public void downloadVideo() {
|
||||||
Log.d(TAG, "bla");
|
Log.d(TAG, "bla");
|
||||||
if(!videoTitle.isEmpty()) {
|
if(!videoTitle.isEmpty()) {
|
||||||
String videoSuffix = "." + VideoInfo.getSuffixById(videoStreams[selectedStream].format);
|
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
|
||||||
String audioSuffix = "." + VideoInfo.getSuffixById(audioStream.format);
|
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
|
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
|
||||||
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
|
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
|
||||||
@ -297,7 +297,7 @@ public class ActionBarHandler {
|
|||||||
try {
|
try {
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.parse(audioStream.url),
|
intent.setDataAndType(Uri.parse(audioStream.url),
|
||||||
VideoInfo.getMimeById(audioStream.format));
|
MediaFormat.getMimeById(audioStream.format));
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
|
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
|
||||||
intent.putExtra("title", videoTitle);
|
intent.putExtra("title", videoTitle);
|
||||||
activity.startActivity(intent); // HERE !!!
|
activity.startActivity(intent); // HERE !!!
|
||||||
|
@ -3,7 +3,7 @@ package org.schabi.newpipe;
|
|||||||
/**
|
/**
|
||||||
* Created by scc on 08/11/15.
|
* Created by scc on 08/11/15.
|
||||||
*/
|
*/
|
||||||
public enum VideoFormat {
|
public enum MediaFormat {
|
||||||
// id name suffix mime type
|
// id name suffix mime type
|
||||||
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
||||||
v3GPP (0x1, "3GPP", "3gp", "video/3gpp"),
|
v3GPP (0x1, "3GPP", "3gp", "video/3gpp"),
|
||||||
@ -16,7 +16,7 @@ public enum VideoFormat {
|
|||||||
public final String suffix;
|
public final String suffix;
|
||||||
public final String mimeType;
|
public final String mimeType;
|
||||||
|
|
||||||
VideoFormat(int id, String name, String suffix, String mimeType) {
|
MediaFormat(int id, String name, String suffix, String mimeType) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
@ -24,21 +24,21 @@ public enum VideoFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getNameById(int ident) {
|
public static String getNameById(int ident) {
|
||||||
for (VideoFormat vf : VideoFormat.values()) {
|
for (MediaFormat vf : MediaFormat.values()) {
|
||||||
if(vf.id == ident) return vf.name;
|
if(vf.id == ident) return vf.name;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSuffixById(int ident) {
|
public static String getSuffixById(int ident) {
|
||||||
for (VideoFormat vf : VideoFormat.values()) {
|
for (MediaFormat vf : MediaFormat.values()) {
|
||||||
if(vf.id == ident) return vf.suffix;
|
if(vf.id == ident) return vf.suffix;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMimeById(int ident) {
|
public static String getMimeById(int ident) {
|
||||||
for (VideoFormat vf : VideoFormat.values()) {
|
for (MediaFormat vf : MediaFormat.values()) {
|
||||||
if(vf.id == ident) return vf.mimeType;
|
if(vf.id == ident) return vf.mimeType;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.youtube;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
@ -14,6 +13,7 @@ import org.mozilla.javascript.Function;
|
|||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.Extractor;
|
import org.schabi.newpipe.Extractor;
|
||||||
|
import org.schabi.newpipe.MediaFormat;
|
||||||
import org.schabi.newpipe.VideoInfo;
|
import org.schabi.newpipe.VideoInfo;
|
||||||
import org.schabi.newpipe.VideoInfoItem;
|
import org.schabi.newpipe.VideoInfoItem;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
@ -57,16 +57,16 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
public static int resolveFormat(int itag) {
|
public static int resolveFormat(int itag) {
|
||||||
switch(itag) {
|
switch(itag) {
|
||||||
// video
|
// video
|
||||||
case 17: return VideoInfo.I_3GPP;
|
case 17: return MediaFormat.v3GPP.id;
|
||||||
case 18: return VideoInfo.I_MPEG_4;
|
case 18: return MediaFormat.MPEG_4.id;
|
||||||
case 22: return VideoInfo.I_MPEG_4;
|
case 22: return MediaFormat.MPEG_4.id;
|
||||||
case 36: return VideoInfo.I_3GPP;
|
case 36: return MediaFormat.v3GPP.id;
|
||||||
case 37: return VideoInfo.I_MPEG_4;
|
case 37: return MediaFormat.MPEG_4.id;
|
||||||
case 38: return VideoInfo.I_MPEG_4;
|
case 38: return MediaFormat.MPEG_4.id;
|
||||||
case 43: return VideoInfo.I_WEBM;
|
case 43: return MediaFormat.WEBM.id;
|
||||||
case 44: return VideoInfo.I_WEBM;
|
case 44: return MediaFormat.WEBM.id;
|
||||||
case 45: return VideoInfo.I_WEBM;
|
case 45: return MediaFormat.WEBM.id;
|
||||||
case 46: return VideoInfo.I_WEBM;
|
case 46: return MediaFormat.WEBM.id;
|
||||||
default:
|
default:
|
||||||
//Log.i(TAG, "Itag " + Integer.toString(itag) + " not known or not supported.");
|
//Log.i(TAG, "Itag " + Integer.toString(itag) + " not known or not supported.");
|
||||||
return -1;
|
return -1;
|
||||||
@ -344,10 +344,10 @@ public class YoutubeExtractor implements Extractor {
|
|||||||
if(currentTagIsBaseUrl &&
|
if(currentTagIsBaseUrl &&
|
||||||
(currentMimeType.contains("audio"))) {
|
(currentMimeType.contains("audio"))) {
|
||||||
int format = -1;
|
int format = -1;
|
||||||
if(currentMimeType.equals(VideoInfo.M_WEBMA)) {
|
if(currentMimeType.equals(MediaFormat.WEBMA.mimeType)) {
|
||||||
format = VideoInfo.I_WEBMA;
|
format = MediaFormat.WEBMA.id;
|
||||||
} else if(currentMimeType.equals(VideoInfo.M_M4A)) {
|
} else if(currentMimeType.equals(MediaFormat.M4A.mimeType)) {
|
||||||
format = VideoInfo.I_M4A;
|
format = MediaFormat.M4A.id;
|
||||||
}
|
}
|
||||||
audioStreams.add(new VideoInfo.AudioStream(parser.getText(),
|
audioStreams.add(new VideoInfo.AudioStream(parser.getText(),
|
||||||
format, currentBandwidth, currentSamplingRate));
|
format, currentBandwidth, currentSamplingRate));
|
||||||
|
Loading…
Reference in New Issue
Block a user