Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
B0pol committed Jun 22, 2020
1 parent 1cfff9c commit 81eff6a
Show file tree
Hide file tree
Showing 5 changed files with 1,116 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.localization.DateWrapper;

import javax.annotation.Nonnull;
import java.util.Calendar;
import java.util.Date;

Expand Down Expand Up @@ -76,4 +77,14 @@ public static DateWrapper getUploadDateFromEpochTime(final long epochTime) {
calendar.setTime(new Date(epochTime * 1000)); // * 1000 because it's second-based, not millisecond based
return new DateWrapper(calendar);
}

public static String getUid(@Nonnull String id) {
if (id.startsWith("user/")) {
id = id.substring(5);
} else if (id.startsWith("channel/")) {
id = id.substring(8);
}

return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonWriter;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.services.youtube.invidious.InvidiousParsingHelper;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
Expand All @@ -17,6 +17,8 @@
import javax.annotation.Nonnull;
import java.io.IOException;

import static org.schabi.newpipe.extractor.services.youtube.invidious.InvidiousParsingHelper.getUid;

/*
* Copyright (C) 2020 Team NewPipe <tnp@newpipe.schabi.org>
* InvidiousChannelExtractor.java is part of NewPipe Extractor.
Expand Down Expand Up @@ -66,22 +68,22 @@ public long getSubscriberCount() {
}

@Override
public String getDescription() throws ParsingException {
public String getDescription() {
return json.getString("description");
}

@Override
public String getParentChannelName() throws ParsingException {
public String getParentChannelName() {
return null;
}

@Override
public String getParentChannelUrl() throws ParsingException {
public String getParentChannelUrl() {
return null;
}

@Override
public String getParentChannelAvatarUrl() throws ParsingException {
public String getParentChannelAvatarUrl() {
return null;
}

Expand Down Expand Up @@ -110,7 +112,7 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException,

@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
final String apiUrl = baseUrl + "/api/v1/channels/" + getId()
final String apiUrl = baseUrl + "/api/v1/channels/" + getUid(getId())
+ "?fields=author,description,subCount,authorThumbnails,authorBanners,authorId"
+ "&region=" + getExtractorContentCountry().getCountryCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.utils.Utils;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -61,17 +60,7 @@ public long getDuration() {

@Override
public long getViewCount() {
final Number viewCount = json.getNumber("viewCountText");
if (viewCount != null) {
return viewCount.longValue();
}

final String viewCountText = json.getString("viewCountText");
try {
return Utils.mixedNumberWordToLong(viewCountText);
} catch (ParsingException e) {
return -1;
}
return json.getLong("viewCount", -1);
}

@Override
Expand All @@ -82,7 +71,7 @@ public String getUploaderName() {
@Override
public String getUploaderUrl() {
final String url = json.getString("authorUrl");
return url != null ? url : baseUrl + "/channel/" + json.getString("authorId");
return url != null ? baseUrl + url : baseUrl + "/channel/" + json.getString("authorId");
}

@Nullable
Expand Down Expand Up @@ -119,6 +108,6 @@ public String getUrl() throws ParsingException {

@Override
public String getThumbnailUrl() {
return json.getArray("videoThumbnails").getObject(0).getString("url");
return baseUrl + json.getArray("videoThumbnails").getObject(0).getString("url");
}
}
Loading

0 comments on commit 81eff6a

Please sign in to comment.