Skip to content

Commit a8691fc

Browse files
fix: some devices can not extract any av video (BiliBili)
1 parent 0fe1b20 commit a8691fc

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/bilibili/extractors/BilibiliRelatedInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public BilibiliRelatedInfoItemExtractor(final JsonObject json, String id, String
3333
this.pic = pic;
3434
this.p = p;
3535
}
36-
public BilibiliRelatedInfoItemExtractor(final JsonObject json){
36+
public BilibiliRelatedInfoItemExtractor(final JsonObject json) throws ParsingException {
3737
item = json;
3838
type = "related";
3939
id = item.getString("bvid").equals("")? new utils().av2bv(item.getLong("aid")):item.getString("bvid");

extractor/src/main/java/org/schabi/newpipe/extractor/services/bilibili/utils.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.schabi.newpipe.extractor.services.bilibili;
22

3+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
4+
5+
import java.text.ParseException;
36
import java.util.HashMap;
47
import java.util.Map;
58
import java.util.Optional;
@@ -22,16 +25,27 @@ public Long bv2av(String bv){
2225
}
2326
return (r - add) ^ xor;
2427
}
25-
public String av2bv(Long x){
28+
public String av2bv(Long x) throws ParsingException {
29+
String result = av2bvImpl(x, false);
30+
return result.contains(" ")?av2bvImpl(x, true):result;
31+
}
32+
/*
33+
for unknown reason, some devices resolve the index as index - 1
34+
flag is set to true that case
35+
*/
36+
private String av2bvImpl(Long x, boolean flag) throws ParsingException {
2637
x = (x^xor) + add;
2738
String[] r = "BV1 4 1 7 ".split("");
2839
for(int i=0;i<6;i++){
29-
r[s[i]] = String.valueOf(table.charAt((int) ((x / Math.pow(58, i)) % 58)));
40+
r[s[i] + (flag?1:0)] = String.valueOf(table.charAt((int) ((x / Math.pow(58, i)) % 58)));
3041
}
3142
String result = "";
3243
for(String i: r){
3344
result += i;
3445
}
46+
if(flag && result.contains(" ")){
47+
throw new ParsingException(String.format("Failed to convert av to bv. av number: %s", x));
48+
}
3549
return result;
3650
}
3751
public static String getUrl(String url, String id){

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ private static StreamInfo extractImportantData(@Nonnull final StreamExtractor ex
121121
|| isNullOrEmpty(id)
122122
|| name == null /* but it can be empty of course */
123123
|| ageLimit == -1) {
124-
throw new ExtractionException("Some important stream information was not given.");
124+
throw new ExtractionException(String.format("Some important stream information was not given. " +
125+
"streamType: %s, url: %s, id: %s, name: %s, ageLimit: %d", streamType, url, id, name, ageLimit));
125126
}
126127

127128
return new StreamInfo(extractor.getServiceId(), url, extractor.getOriginalUrl(),

0 commit comments

Comments
 (0)