mirror of https://github.com/readrops/Readrops.git
Fix rss url parsing bug
This commit is contained in:
parent
f014284316
commit
d4e546b6c1
|
@ -71,7 +71,7 @@ public class RSSQuery {
|
|||
if (type == RSSType.RSS_UNKNOWN) {
|
||||
RSSType contentType = getContentRSSType(response.body().string());
|
||||
return contentType != RSSType.RSS_UNKNOWN;
|
||||
} else return type != null;
|
||||
} else return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
@ -103,17 +103,16 @@ public class RSSQuery {
|
|||
switch (header) {
|
||||
case LibUtils.RSS_DEFAULT_CONTENT_TYPE:
|
||||
return RSSType.RSS_2;
|
||||
case LibUtils.RSS_TEXT_CONTENT_TYPE:
|
||||
case LibUtils.HTML_CONTENT_TYPE:
|
||||
case LibUtils.RSS_APPLICATION_CONTENT_TYPE:
|
||||
return RSSType.RSS_UNKNOWN;
|
||||
case LibUtils.ATOM_CONTENT_TYPE:
|
||||
return RSSType.RSS_ATOM;
|
||||
case LibUtils.JSON_CONTENT_TYPE:
|
||||
return RSSType.RSS_JSON;
|
||||
case LibUtils.RSS_TEXT_CONTENT_TYPE:
|
||||
case LibUtils.HTML_CONTENT_TYPE:
|
||||
case LibUtils.RSS_APPLICATION_CONTENT_TYPE:
|
||||
default:
|
||||
Log.d(TAG, "bad content type : " + contentType);
|
||||
return null;
|
||||
return RSSType.RSS_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.jsoup.select.Elements;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -33,25 +34,30 @@ public final class HtmlParser {
|
|||
* @param url url to request
|
||||
* @return a list of rss urls with their title
|
||||
*/
|
||||
public static List<ParsingResult> getFeedLink(String url) throws Exception {
|
||||
public static List<ParsingResult> getFeedLink(String url) {
|
||||
List<ParsingResult> results = new ArrayList<>();
|
||||
|
||||
Document document = Jsoup.parse(getHTMLHeadFromUrl(url), url);
|
||||
String head = getHTMLHeadFromUrl(url);
|
||||
if (head != null) {
|
||||
Document document = Jsoup.parse(head, url);
|
||||
|
||||
Elements elements = document.select("link");
|
||||
Elements elements = document.select("link");
|
||||
|
||||
for (Element element : elements) {
|
||||
String type = element.attributes().get("type");
|
||||
for (Element element : elements) {
|
||||
String type = element.attributes().get("type");
|
||||
|
||||
if (isTypeRssFeed(type)) {
|
||||
String feedUrl = element.absUrl("href");
|
||||
String label = element.attributes().get("title");
|
||||
if (isTypeRssFeed(type)) {
|
||||
String feedUrl = element.absUrl("href");
|
||||
String label = element.attributes().get("title");
|
||||
|
||||
results.add(new ParsingResult(feedUrl, label));
|
||||
results.add(new ParsingResult(feedUrl, label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
return results;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isTypeRssFeed(String type) {
|
||||
|
|
|
@ -54,8 +54,9 @@ public class AddFeedsViewModel extends AndroidViewModel {
|
|||
ParsingResult parsingResult = new ParsingResult(url, null);
|
||||
results.add(parsingResult);
|
||||
|
||||
} else
|
||||
} else {
|
||||
results.addAll(HtmlParser.getFeedLink(url));
|
||||
}
|
||||
|
||||
emitter.onSuccess(results);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue