mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-22 21:55:54 +00:00
ExtractorPDFContext, ExtractorYoutubeDL: use addOutlink() helper method
This commit is contained in:
@@ -137,14 +137,7 @@ public class ExtractorPDFContent extends ContentExtractor {
|
||||
}
|
||||
|
||||
for (String uri: uris) {
|
||||
try {
|
||||
LinkContext lc = LinkContext.NAVLINK_MISC;
|
||||
Hop hop = Hop.NAVLINK;
|
||||
CrawlURI out = curi.createCrawlURI(uri, lc, hop);
|
||||
curi.getOutLinks().add(out);
|
||||
} catch (URIException e1) {
|
||||
logUriError(e1, curi.getUURI(), uri);
|
||||
}
|
||||
addOutlink(curi, uri, LinkContext.NAVLINK_MISC, Hop.NAVLINK);
|
||||
}
|
||||
|
||||
numberOfLinksExtracted.addAndGet(uris.size());
|
||||
|
||||
@@ -227,14 +227,7 @@ public class ExtractorYoutubeDL extends Extractor
|
||||
}
|
||||
|
||||
for (String pageUrl: results.pageUrls) {
|
||||
try {
|
||||
UURI dest = UURIFactory.getInstance(uri.getUURI(), pageUrl);
|
||||
CrawlURI link = uri.createCrawlURI(dest, LinkContext.NAVLINK_MISC,
|
||||
Hop.NAVLINK);
|
||||
uri.getOutLinks().add(link);
|
||||
} catch (URIException e1) {
|
||||
logUriError(e1, uri.getUURI(), pageUrl);
|
||||
}
|
||||
addOutlink(uri, pageUrl, LinkContext.NAVLINK_MISC, Hop.NAVLINK);
|
||||
}
|
||||
|
||||
if (results.videoUrls.size() > 0) {
|
||||
@@ -246,26 +239,21 @@ public class ExtractorYoutubeDL extends Extractor
|
||||
}
|
||||
|
||||
protected void addVideoOutlink(CrawlURI uri, String videoUrl, int playlistIndex, int nEntries) {
|
||||
try {
|
||||
UURI dest = UURIFactory.getInstance(uri.getUURI(), videoUrl);
|
||||
CrawlURI link = uri.createCrawlURI(dest, LinkContext.EMBED_MISC,
|
||||
Hop.EMBED);
|
||||
|
||||
// annotation
|
||||
String annotation = "youtube-dl:" + (playlistIndex + 1) + "/" + nEntries;
|
||||
link.getAnnotations().add(annotation);
|
||||
|
||||
// save info unambiguously identifying containing page capture
|
||||
link.getData().put(YDL_CONTAINING_PAGE_URI, uri.toString());
|
||||
link.getData().put(YDL_CONTAINING_PAGE_TIMESTAMP,
|
||||
ArchiveUtils.get17DigitDate(uri.getFetchBeginTime()));
|
||||
link.getData().put(YDL_CONTAINING_PAGE_DIGEST,
|
||||
uri.getContentDigestSchemeString());
|
||||
|
||||
uri.getOutLinks().add(link);
|
||||
} catch (URIException e) {
|
||||
logUriError(e, uri.getUURI(), videoUrl);
|
||||
CrawlURI link = addOutlink(uri, videoUrl, LinkContext.EMBED_MISC, Hop.EMBED);
|
||||
if (link == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// annotation
|
||||
String annotation = "youtube-dl:" + (playlistIndex + 1) + "/" + nEntries;
|
||||
link.getAnnotations().add(annotation);
|
||||
|
||||
// save info unambiguously identifying containing page capture
|
||||
link.getData().put(YDL_CONTAINING_PAGE_URI, uri.toString());
|
||||
link.getData().put(YDL_CONTAINING_PAGE_TIMESTAMP,
|
||||
ArchiveUtils.get17DigitDate(uri.getFetchBeginTime()));
|
||||
link.getData().put(YDL_CONTAINING_PAGE_DIGEST,
|
||||
uri.getContentDigestSchemeString());
|
||||
}
|
||||
|
||||
protected String findYdlAnnotation(CrawlURI uri) {
|
||||
|
||||
@@ -134,19 +134,18 @@ public abstract class Extractor extends Processor {
|
||||
|
||||
/**
|
||||
* Create and add a 'Link' to the CrawlURI with given URI/context/hop-type
|
||||
* @param curi
|
||||
* @param uri
|
||||
* @param context
|
||||
* @param hop
|
||||
* @return the new outlink or null if it was not valid
|
||||
*/
|
||||
protected void addOutlink(CrawlURI curi, String uri, LinkContext context,
|
||||
protected CrawlURI addOutlink(CrawlURI curi, String uri, LinkContext context,
|
||||
Hop hop) {
|
||||
try {
|
||||
UURI dest = UURIFactory.getInstance(curi.getUURI(), uri);
|
||||
CrawlURI link = curi.createCrawlURI(dest, context, hop);
|
||||
curi.getOutLinks().add(link);
|
||||
return link;
|
||||
} catch (URIException e) {
|
||||
logUriError(e, curi.getUURI(), uri);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user