Fix parsing description
This commit is contained in:
parent
0fff03038e
commit
26fb44595f
|
@ -38,9 +38,17 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -180,19 +188,25 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
if (internUrl.startsWith("/redirect?")) {
|
if (internUrl.startsWith("/redirect?")) {
|
||||||
// q parameter can be the first parameter
|
// q parameter can be the first parameter
|
||||||
internUrl = internUrl.substring(10);
|
internUrl = internUrl.substring(10);
|
||||||
}
|
|
||||||
String[] params = internUrl.split("&");
|
String[] params = internUrl.split("&");
|
||||||
for (String param : params) {
|
for (String param : params) {
|
||||||
if (param.charAt(0) == 'q') {
|
if (param.split("=")[0].equals("q")) {
|
||||||
String url = java.net.URLDecoder.decode(param.substring(2), StandardCharsets.UTF_8.name());
|
String url = URLDecoder.decode(param.split("=")[1], StandardCharsets.UTF_8.name());
|
||||||
if (url != null && !url.isEmpty()) {
|
if (url != null && !url.isEmpty()) {
|
||||||
descriptionBuilder.append("<a href=\"").append(url).append("\">").append(text).append("</a>");
|
descriptionBuilder.append("<a href=\"").append(url).append("\">").append(text).append("</a>");
|
||||||
htmlConversionRequired = true;
|
htmlConversionRequired = true;
|
||||||
} else {
|
} else {
|
||||||
descriptionBuilder.append(text);
|
descriptionBuilder.append(text);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (internUrl.startsWith("http")) {
|
||||||
|
descriptionBuilder.append("<a href=\"").append(internUrl).append("\">").append(text).append("</a>");
|
||||||
|
htmlConversionRequired = true;
|
||||||
|
} else if (text != null) {
|
||||||
|
descriptionBuilder.append(text);
|
||||||
|
}
|
||||||
} else if (text != null) {
|
} else if (text != null) {
|
||||||
descriptionBuilder.append(text);
|
descriptionBuilder.append(text);
|
||||||
}
|
}
|
||||||
|
@ -203,11 +217,11 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
if (!description.isEmpty()) {
|
if (!description.isEmpty()) {
|
||||||
if (htmlConversionRequired) {
|
if (htmlConversionRequired) {
|
||||||
description = description.replaceAll("\\n", "<br>");
|
description = description.replaceAll("\\n", "<br>");
|
||||||
|
description = description.replaceAll(" ", " ");
|
||||||
return new Description(description, Description.HTML);
|
return new Description(description, Description.HTML);
|
||||||
}
|
}
|
||||||
return new Description(description, Description.PLAIN_TEXT);
|
return new Description(description, Description.PLAIN_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) { }
|
||||||
|
|
||||||
// raw non-html description
|
// raw non-html description
|
||||||
|
|
Loading…
Reference in New Issue