Skip to content

Commit d0877c3

Browse files
author
chschtsch
committed
tryna merge dem files
2 parents c589b03 + 596443b commit d0877c3

11 files changed

Lines changed: 328 additions & 320 deletions

app/src/main/java/org/schabi/newpipe/ActionBarHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
7777
int defaultResolutionPos = 0;
7878

7979
for(int i = 0; i < videoStreams.length; i++) {
80-
itemArray[i] = VideoInfo.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
80+
itemArray[i] = MediaFormat.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
8181
if(defaultResolution.equals(videoStreams[i].resolution)) {
8282
defaultResolutionPos = i;
8383
}
@@ -98,14 +98,14 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
9898
.getString(activity.getString(R.string.defaultAudioFormatPreference), "webm");
9999
if(preferedFormat.equals("webm")) {
100100
for(VideoInfo.AudioStream s : audioStreams) {
101-
if(s.format == VideoInfo.I_WEBMA) {
101+
if(s.format == MediaFormat.WEBMA.id) {
102102
audioStream = s;
103103
}
104104
}
105105
} else if(preferedFormat.equals("m4a")){
106106
for(VideoInfo.AudioStream s : audioStreams) {
107-
Log.d(TAG, VideoInfo.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
108-
if(s.format == VideoInfo.I_M4A &&
107+
Log.d(TAG, MediaFormat.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
108+
if(s.format == MediaFormat.M4A.id &&
109109
(audioStream == null || audioStream.bandwidth > s.bandwidth)) {
110110
audioStream = s;
111111
Log.d(TAG, "last choosen");
@@ -196,7 +196,7 @@ public void playVideo() {
196196
intent.setAction(Intent.ACTION_VIEW);
197197

198198
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
199-
VideoInfo.getMimeById(videoStreams[selectedStream].format));
199+
MediaFormat.getMimeById(videoStreams[selectedStream].format));
200200
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
201201
intent.putExtra("title", videoTitle);
202202

@@ -237,8 +237,8 @@ public void onClick(DialogInterface dialog, int which) {
237237
public void downloadVideo() {
238238
Log.d(TAG, "bla");
239239
if(!videoTitle.isEmpty()) {
240-
String videoSuffix = "." + VideoInfo.getSuffixById(videoStreams[selectedStream].format);
241-
String audioSuffix = "." + VideoInfo.getSuffixById(audioStream.format);
240+
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
241+
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
242242
Bundle args = new Bundle();
243243
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
244244
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
@@ -297,7 +297,7 @@ public void playAudio() {
297297
try {
298298
intent.setAction(Intent.ACTION_VIEW);
299299
intent.setDataAndType(Uri.parse(audioStream.url),
300-
VideoInfo.getMimeById(audioStream.format));
300+
MediaFormat.getMimeById(audioStream.format));
301301
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
302302
intent.putExtra("title", videoTitle);
303303
activity.startActivity(intent); // HERE !!!

app/src/main/java/org/schabi/newpipe/Downloader.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe;
22

33
import java.io.BufferedReader;
4+
import java.io.IOException;
45
import java.io.InputStreamReader;
56
import java.net.HttpURLConnection;
67
import java.net.URL;
@@ -29,12 +30,25 @@
2930
public class Downloader {
3031

3132
private static final String USER_AGENT = "Mozilla/5.0";
32-
public static String download(String siteUrl) {
3333

34-
StringBuffer response = new StringBuffer();
34+
public static String download(String siteUrl, String language) {
35+
String ret = "";
3536
try {
3637
URL url = new URL(siteUrl);
3738
HttpURLConnection con = (HttpURLConnection) url.openConnection();
39+
con.setRequestProperty("Accept-Language", language);
40+
ret = dl(con);
41+
}
42+
catch(Exception e) {
43+
e.printStackTrace();
44+
}
45+
return ret;
46+
}
47+
48+
private static String dl(HttpURLConnection con) {
49+
StringBuffer response = new StringBuffer();
50+
51+
try {
3852
con.setRequestMethod("GET");
3953
con.setRequestProperty("User-Agent", USER_AGENT);
4054

@@ -57,4 +71,20 @@ public static String download(String siteUrl) {
5771
}
5872
return response.toString();
5973
}
74+
75+
76+
public static String download(String siteUrl) {
77+
String ret = "";
78+
79+
try {
80+
URL url = new URL(siteUrl);
81+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
82+
ret = dl(con);
83+
}
84+
catch(Exception e) {
85+
e.printStackTrace();
86+
}
87+
88+
return ret;
89+
}
6090
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.schabi.newpipe;
2+
3+
/**
4+
* Created by Adam Howard on 08/11/15.
5+
*
6+
* Copyright (c) Christian Schabesberger <chris.schabesberger@mailbox.org>
7+
* and Adam Howard <achdisposable1@gmail.com> 2015
8+
*
9+
* VideoListAdapter.java is part of NewPipe.
10+
*
11+
* NewPipe is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* NewPipe is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
public enum MediaFormat {
25+
// id name suffix mime type
26+
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
27+
v3GPP (0x1, "3GPP", "3gp", "video/3gpp"),
28+
WEBM (0x2, "WebM", "webm", "video/webm"),
29+
M4A (0x3, "m4a", "m4a", "audio/mp4"),
30+
WEBMA (0x4, "WebM", "webm", "audio/webm");
31+
32+
public final int id;
33+
public final String name;
34+
public final String suffix;
35+
public final String mimeType;
36+
37+
MediaFormat(int id, String name, String suffix, String mimeType) {
38+
this.id = id;
39+
this.name = name;
40+
this.suffix = suffix;
41+
this.mimeType = mimeType;
42+
}
43+
44+
public static String getNameById(int ident) {
45+
for (MediaFormat vf : MediaFormat.values()) {
46+
if(vf.id == ident) return vf.name;
47+
}
48+
return "";
49+
}
50+
51+
public static String getSuffixById(int ident) {
52+
for (MediaFormat vf : MediaFormat.values()) {
53+
if(vf.id == ident) return vf.suffix;
54+
}
55+
return "";
56+
}
57+
58+
public static String getMimeById(int ident) {
59+
for (MediaFormat vf : MediaFormat.values()) {
60+
if(vf.id == ident) return vf.mimeType;
61+
}
62+
return "";
63+
}
64+
}
Lines changed: 27 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.schabi.newpipe;
22

3+
import android.graphics.Bitmap;
4+
import android.util.Log;
5+
import java.util.Vector;
6+
37
/**
48
* Created by Christian Schabesberger on 26.08.15.
59
*
@@ -20,82 +24,36 @@
2024
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2125
*/
2226

23-
import android.graphics.Bitmap;
24-
import android.util.Log;
25-
26-
import java.util.Vector;
2727

2828
public class VideoInfo {
29+
public String id = "";
30+
public String title = "";
31+
public String uploader = "";
32+
public String thumbnail_url = "";
33+
public Bitmap thumbnail = null;
34+
public String webpage_url = "";
35+
public String upload_date = "";
36+
public String view_count = "";
2937

30-
private static final String TAG = VideoInfo.class.toString();
31-
32-
// format identifier
33-
public static final int I_MPEG_4 = 0x0;
34-
public static final int I_3GPP = 0x1;
35-
public static final int I_WEBM = 0x2;
36-
public static final int I_M4A = 0x3;
37-
public static final int I_WEBMA = 0x4;
38-
39-
// format name
40-
public static final String F_MPEG_4 = "MPEG-4";
41-
public static final String F_3GPP = "3GPP";
42-
public static final String F_WEBM = "WebM";
43-
public static final String F_M4A = "m4a";
44-
public static final String F_WEBMA = "WebM";
45-
46-
// file suffix
47-
public static final String C_MPEG_4 = "mp4";
48-
public static final String C_3GPP = "3gp";
49-
public static final String C_WEBM = "webm";
50-
public static final String C_M4A = "m4a";
51-
public static final String C_WEBMA = "webm";
38+
public String uploader_thumbnail_url = "";
39+
public Bitmap uploader_thumbnail = null;
40+
public String description = "";
41+
public int duration = -1;
42+
public int age_limit = 0;
43+
public String like_count = "";
44+
public String dislike_count = "";
45+
public String average_rating = "";
46+
public VideoStream[] videoStreams = null;
47+
public AudioStream[] audioStreams = null;
48+
public VideoInfoItem nextVideo = null;
49+
public VideoInfoItem[] relatedVideos = null;
50+
public int videoAvailableStatus = VIDEO_AVAILABLE;
5251

53-
// mimeType
54-
public static final String M_MPEG_4 = "video/mp4";
55-
public static final String M_3GPP = "video/3gpp";
56-
public static final String M_WEBM = "video/webm";
57-
public static final String M_M4A = "audio/mp4";
58-
public static final String M_WEBMA = "audio/webm";
52+
private static final String TAG = VideoInfo.class.toString();
5953

6054
public static final int VIDEO_AVAILABLE = 0x00;
6155
public static final int VIDEO_UNAVAILABLE = 0x01;
62-
public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation; sound pretty draconian
63-
64-
public static String getNameById(int id) {
65-
switch(id) {
66-
case I_MPEG_4: return F_MPEG_4;
67-
case I_3GPP: return F_3GPP;
68-
case I_WEBM: return F_WEBM;
69-
case I_M4A: return F_M4A;
70-
case I_WEBMA: return F_WEBMA;
71-
default: formatNotKnown(id);
72-
}
73-
return "";
74-
}
75-
76-
public static String getSuffixById(int id) {
77-
switch(id) {
78-
case I_MPEG_4: return C_MPEG_4;
79-
case I_3GPP: return C_3GPP;
80-
case I_WEBM: return C_WEBM;
81-
case I_M4A: return C_M4A;
82-
case I_WEBMA: return C_WEBMA;
83-
default: formatNotKnown(id);
84-
}
85-
return "";
86-
}
87-
88-
public static String getMimeById(int id) {
89-
switch(id) {
90-
case I_MPEG_4: return M_MPEG_4;
91-
case I_3GPP: return M_3GPP;
92-
case I_WEBM: return M_WEBM;
93-
case I_M4A: return M_M4A;
94-
case I_WEBMA: return M_WEBMA;
95-
default: formatNotKnown(id);
96-
}
97-
return "";
98-
}
56+
public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation
9957

10058
public static class VideoStream {
10159
public VideoStream(String url, int format, String res) {
@@ -123,25 +81,4 @@ public AudioStream(String url, int format, int bandwidth, int samplingRate) {
12381

12482
}
12583

126-
public String id = "";
127-
public String uploader = "";
128-
public String upload_date = "";
129-
public String uploader_thumbnail_url = "";
130-
public Bitmap uploader_thumbnail = null;
131-
public String title = "";
132-
public String thumbnail_url = "";
133-
public Bitmap thumbnail = null;
134-
public String description = "";
135-
public int duration = -1;
136-
public int age_limit = 0;
137-
public String webpage_url = "";
138-
public String view_count = "";
139-
public String like_count = "";
140-
public String dislike_count = "";
141-
public String average_rating = "";
142-
public VideoStream[] videoStreams = null;
143-
public AudioStream[] audioStreams = null;
144-
public VideoInfoItem nextVideo = null;
145-
public VideoInfoItem[] relatedVideos = null;
146-
public int videoAvailableStatus = VIDEO_AVAILABLE;
14784
}

app/src/main/java/org/schabi/newpipe/VideoInfoItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ public class VideoInfoItem implements Parcelable {
2828
public String id = "";
2929
public String title = "";
3030
public String uploader = "";
31-
public String duration = "";
3231
public String thumbnail_url = "";
3332
public Bitmap thumbnail = null;
3433
public String webpage_url = "";
3534
public String upload_date = "";
3635
public String view_count = "";
3736

37+
public String duration = "";
38+
3839
protected VideoInfoItem(Parcel in) {
3940
id = in.readString();
4041
title = in.readString();

app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ void terminate() {
9393
public void run() {
9494
try {
9595
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
96-
String contentCountryKey = getContext().getString(R.string.contentCountry);
97-
String contentCountry = sp.getString(contentCountryKey, "");
98-
SearchEngine.Result result = engine.search(query, page, contentCountry);
99-
Log.i(TAG, "countryCode passed:\""+contentCountry+"\"");
96+
String searchLanguageKey = getContext().getString(R.string.searchLanguage);
97+
String searchLanguage = sp.getString(searchLanguageKey, "en");
98+
SearchEngine.Result result = engine.search(query, page, searchLanguage);
99+
Log.i(TAG, "language code passed:\""+searchLanguage+"\"");
100100
if(run) {
101101
h.post(new ResultRunnable(result, requestId));
102102
}

0 commit comments

Comments
 (0)