Skip to content

Commit

Permalink
Merge pull request #306 from idl0r/for-upstream
Browse files Browse the repository at this point in the history
Change handling of urls starting with "//" and allow ftp downloads
  • Loading branch information
nilsbraden committed Oct 25, 2015
2 parents fd7ee58 + 2c634b1 commit ac39698
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
Expand Down Expand Up @@ -189,18 +188,16 @@ protected Void doInBackground(URL... urls) {
File file;
try {
URL url = urls[0];
HttpURLConnection c = (HttpURLConnection) Controller.getInstance().openConnection(url);
URLConnection c;

c = Controller.getInstance().openConnection(url);

file = new File(folder, URLUtil.guessFileName(url.toString(), null, ".mp3"));
if (file.exists()) {
size = (int) file.length();
c.setRequestProperty("Range", "bytes=" + size + "-"); // try to resume downloads
}

c.setRequestMethod("GET");
c.setDoInput(true);
c.setDoOutput(true);

in = new BufferedInputStream(c.getInputStream());
fos = (size == 0) ? new FileOutputStream(file) : new FileOutputStream(file, true);
bout = new BufferedOutputStream(fos, BUFFER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ private static Set<String> findAllImageUrls(String html) {

while (m.find()) {
String url = m.group(1);
if (url.startsWith("http")) ret.add(url);

if (url.startsWith("http") || url.startsWith("ftp://")) ret.add(url);
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.MalformedJsonException;

import org.intellij.lang.annotations.RegExp;
import org.json.JSONException;
import org.json.JSONObject;
import org.ttrssreader.MyApplication;
Expand Down Expand Up @@ -49,6 +50,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

public abstract class JSONConnector {

Expand Down Expand Up @@ -422,6 +424,8 @@ private Set<String> parseAttachments(JsonReader reader) throws IOException {
switch (reader.nextName()) {
case CONTENT_URL:
attUrl = reader.nextString();
// Some URLs may start with // to indicate that both, http and https can be used
if (attUrl.startsWith("//")) attUrl = "https:" + attUrl;
break;
case ID:
attId = reader.nextString();
Expand Down Expand Up @@ -525,13 +529,17 @@ private boolean parseArticle(final Article a, final JsonReader reader, final Set
else a.feedId = reader.nextInt();
break;
case content:
a.content = reader.nextString();
a.content = reader.nextString().replaceAll("(<(?:img|video)[^>]+?src=[\"'])//([^\"']*)", "$1https://$2");
break;
case link:
a.url = reader.nextString();
// Some URLs may start with // to indicate that both, http and https can be used
if (a.url.startsWith("//")) a.url = "https:" + a.url;
break;
case comments:
a.commentUrl = reader.nextString();
// Some URLs may start with // to indicate that both, http and https can be used
if (a.commentUrl.startsWith("//")) a.commentUrl = "https:" + a.commentUrl;
break;
case attachments:
a.attachments = parseAttachments(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ public static long downloadToFile(String downloadUrl, File file, long maxSize, l
InputStream is = null;

try (FileOutputStream fos = new FileOutputStream(file)) {
// In case where http and https is supported we might get just // as URL prefix, so we use a secure default...
if(downloadUrl.startsWith("//"))
downloadUrl = "https:" + downloadUrl;

URL url = new URL(downloadUrl);
URLConnection connection = Controller.getInstance().openConnection(url);

Expand Down
2 changes: 1 addition & 1 deletion ttrssreader/src/main/java/org/ttrssreader/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class Utils {
* The Pattern to match image-urls inside HTML img-tags.
*/
public static final Pattern findImageUrlsPattern = Pattern
.compile("<img[^>]+?src=[\"']([^\"']*)", Pattern.CASE_INSENSITIVE);
.compile("<(?:img|video)[^>]+?src=[\"']([^\"']*)", Pattern.CASE_INSENSITIVE);

private static final int ID_RUNNING = 4564561;
private static final int ID_FINISHED = 7897891;
Expand Down

0 comments on commit ac39698

Please sign in to comment.