Base Implementation: Parse the upload date of StreamInfoItems

In the format '2 days ago' (in English) on a YouTube channel page.
(Parser extensible to other pages.)
This commit is contained in:
wojcik-online
2019-10-02 02:02:01 -03:00
committed by Mauricio Colli
parent 514ed7bdc1
commit 180836c180
16 changed files with 316 additions and 44 deletions

View File

@@ -41,6 +41,7 @@ import static java.util.Collections.singletonList;
public class Downloader implements org.schabi.newpipe.extractor.Downloader {
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
private static final String DEFAULT_HTTP_ACCEPT_LANGUAGE = "en";
private static String mCookies = "";
private static Downloader instance = null;
@@ -171,6 +172,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
URL url = new URL(siteUrl);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// HttpsURLConnection con = NetCipher.getHttpsURLConnection(url);
con.setRequestProperty("Accept-Language", DEFAULT_HTTP_ACCEPT_LANGUAGE);
return dl(con);
}

View File

@@ -4,6 +4,7 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.Calendar;
import java.util.List;
import static org.junit.Assert.*;
@@ -27,6 +28,14 @@ public final class DefaultTests {
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
final String textualUploadDate = streamInfoItem.getTextualUploadDate();
if (textualUploadDate != null && !textualUploadDate.isEmpty()) {
final Calendar uploadDate = streamInfoItem.getUploadDate();
assertNotNull("No parsed upload date", uploadDate);
assertTrue("Upload date not in the past", uploadDate.before(Calendar.getInstance()));
}
}
}
}