本文整理了Java中org.loklak.harvester.YoutubeScraper
类的一些代码示例,展示了YoutubeScraper
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YoutubeScraper
类的具体详情如下:
包路径:org.loklak.harvester.YoutubeScraper
类名称:YoutubeScraper
暂无
代码示例来源:origin: loklak/loklak_server
public Post parseVideo(InputStream is, String type, String url) {
Post json = new Post();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
json = this.parseVideo(reader, type, url);
reader.close();
} catch (IOException e) {
DAO.severe("Connection error for query = " + this.query);
}
return json;
}
代码示例来源:origin: loklak/loklak_server
@Override
public Post getDataFromConnection() throws IOException {
String url = this.prepareSearchUrl(this.type);
return getDataFromConnection(url, this.type);
}
代码示例来源:origin: loklak/loklak_server
protected void setParam() {
String type = this.getExtraValue("type");
this.query = this.getExtraValue("query");
//TODO: Add scraper for search and user
type = "url";
if ("".equals(type)) {
type = "search";
} else if ("url".equals(type)) {
if (this.query.contains("youtube.com/results")) {
this.type = "search";
} else if (this.query.contains("youtube.com/watch")) {
this.type = "video";
this.query = this.query.substring(this.query.length() - 11);
} else if (this.query.contains("youtube.com/channel")) {
this.type = "user";
this.query = this.query.substring(this.query.length() - 24);
} else if (this.query.contains("youtu.be")) {
this.query = this.query.substring(this.query.length() - 11);
}
}
this.setExtraValue("query", this.query);
}
代码示例来源:origin: loklak/loklak_server
String tag = parseTag(input, p);
if (tag == null) continue;
if (tag.startsWith("<a ")) {
tag = parseTag(tag, 0);
addRDF(new String[]{"youtube", "category", tag}, json);
} else {
addRDF(new String[]{"youtube", "license", tag}, json);
String[] token = parseItemprop(input, p, new String[]{"href", "content"}, "");
if (token == null) continue;
int q = itemType.indexOf("//");
String predicate = itemProp + "_" + token[1];
String object = token[2];
addRDF(new String[]{subject, predicate, object}, json);
continue;
for (String tag : html_tags) {
if ((p = input.indexOf("<" + tag)) >= 0) {
addRDF(new String[]{"html", tag, parseTag(input, p)}, json);
continue tags;
for (String subject : microformat_vocabularies) {
if ((p = input.indexOf("property=\"" + subject + ":")) >= 0) {
addRDF(parseMicroformat(input, "property", p), json);
continue vocs;
addRDF(parseMicroformat(input, "name", p), json);
continue vocs;
代码示例来源:origin: loklak/loklak_server
/**
* When try parse video from input stream should check that video parsed.
*
* @throws IOException if some problem with open stream for reading data.
*/
@Test
public void parseFromInputStreamTest() throws IOException {
YoutubeScraper ytubeScrape = new YoutubeScraper();
String url = "https://www.youtube.com/watch?v=KVGRN7Z7T1A";
InputStream fis = null;
try {
fis = new URL(url).openStream();
Post video = ytubeScrape.parseVideo(fis, "url", url);
DAO.log(video.toString());
assertThat(video.get("html_title").toString(), is("[\"Iggy Azalea - Team (Explicit) - YouTube\"]"));
} catch (IOException e) {
DAO.log("YoutubeScraperTest.parseFromInputStreamTest() failed to connect to network. url:" + url);
}
}
代码示例来源:origin: loklak/loklak_server
@Override
protected Post scrape(BufferedReader br, String type, String url) {
Post out = new Post(true);
PostTimeline postList = new PostTimeline(this.order);
switch (type) {
case "user":
//TODO: Add scraper
break;
case "video":
postList.addPost(this.parseVideo(br, type, url));
this.putData(out, "videos", postList);
break;
case "search":
//TODO: Add scraper
break;
default:
break;
}
return out;
}
代码示例来源:origin: loklak/loklak_server
@Test
public void apiPathTest() {
YoutubeScraper ytubeScrape = new YoutubeScraper();
assertEquals("/api/youtubescraper.json", ytubeScrape.getAPIPath());
}
代码示例来源:origin: loklak/loklak_server
scraperObj = new YoutubeScraper(inputMap);
scraperObjList.add(scraperObj);
代码示例来源:origin: loklak/loklak_server
/**
* When try parse video from buffered reader should check that method return valid json.
*
* @throws IOException if some error happened with open stream for reading data.
*/
@Test
public void parseFromBufferedReaderTest() throws IOException {
YoutubeScraper ytubeScrape = new YoutubeScraper();
String url = "https://www.youtube.com/watch?v=KVGRN7Z7T1A";
String postType = "video";
String postScraper = "youtube";
try {
//Check Network issue
BufferedReader br = new BufferedReader(new InputStreamReader((new URL(url)).openStream(), StandardCharsets.UTF_8));
Post video = ytubeScrape.parseVideo(br, "url", "https://www.youtube.com/watch?v=KVGRN7Z7T1A");
DAO.log(video.toString());
assertThat(video.get("html_title").toString(), is("[\"Iggy Azalea - Team (Explicit) - YouTube\"]"));
assertThat(video.get("post_type"), is(postType));
assertThat(video.get("post_scraper"), is(postScraper));
} catch (IOException e) {
DAO.log("YoutubeScraperTest.parseFromBufferedReaderTest()() failed to connect to network. url:" + url);
}
}
}
代码示例来源:origin: loklak/loklak_server
public Post parseVideo(File file, String type, String url) {
Post json = new Post();
try {
FileInputStream fis = new FileInputStream(file);
json = this.parseVideo(fis, type, url);
fis.close();
} catch (FileNotFoundException e) {
DAO.severe(e);
} catch (IOException e) {
DAO.severe("Connection error for query = " + this.query);
}
return json;
}
内容来源于网络,如有侵权,请联系作者删除!