本文整理了Java中org.tinymediamanager.scraper.http.Url
类的一些代码示例,展示了Url
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Url
类的具体详情如下:
包路径:org.tinymediamanager.scraper.http.Url
类名称:Url
[英]The Class Url. Used to make simple, blocking URL requests. The request is temporarily streamed into a ByteArrayInputStream, before the InputStream is passed to the caller.
[中]类Url。用于生成简单的阻止URL请求。在将InputStream传递给调用者之前,请求会暂时流式传输到ByteArrayInputStream中。
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url jsPlayer = new Url("https:" + matcher.group(1).replaceAll("\\\\", ""));
StringWriter writer = new StringWriter();
IOUtils.copy(jsPlayer.getInputStream(), writer, "UTF-8");
playerJavascript = writer.toString();
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* Download an Url to a file via NIO FileChannel (synchron)
*
* @param file
* @return successful or not
*/
public boolean download(Path file) {
return download(file.toFile());
}
代码示例来源:origin: org.tinymediamanager.plugins/scraper-imdb
@Override
public Document call() throws Exception {
doc = null;
try {
Url url = new Url(this.url);
url.addHeader("Accept-Language", getAcceptLanguage(language, country));
doc = Jsoup.parse(url.getInputStream(), imdbSite.getCharset().displayName(), "");
}
catch (Exception e) {
getLogger().debug("tried to fetch imdb page " + url, e);
}
return doc;
}
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
@Override
protected BufferedImage doInBackground() throws Exception {
try {
Url url = new Url(imageUrl);
return ImageCache.createImage(url.getBytesWithRetry(5));
}
catch (Exception e) {
LOGGER.warn("fetch image: " + e.getMessage());
return null;
}
}
代码示例来源:origin: org.tinymediamanager/api-scraper
counter++;
try {
is = getInputStream();
if (is != null || (is == null && getStatusCode() > 0 && getStatusCode() < 500)) {
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* Gets the bytes.
*
* @return the bytes
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public byte[] getBytes() throws IOException, InterruptedException {
InputStream is = getInputStream();
byte[] bytes = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
return bytes;
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url upd = new Url(uu + "digest.txt?z=" + System.currentTimeMillis()); // cache bust
LOGGER.trace("Checking " + uu);
remoteDigest = IOUtils.toString(upd.getInputStream(), "UTF-8");
if (remoteDigest != null && remoteDigest.contains("tmm.jar")) {
remoteDigest = remoteDigest.trim();
LOGGER.info("Update needed...");
Url gd = new Url(remoteUrl + "getdown.txt");
String remoteGD = IOUtils.toString(gd.getInputStream(), "UTF-8");
if (remoteGD.contains("forceUpdate")) {
forceUpdate = true;
Url upd = new Url(remoteUrl + "changelog.txt");
changelog = IOUtils.toString(upd.getInputStream(), "UTF-8");
return true;
fallback += "/getdown.txt";
Url upd = new Url(fallback);
InputStream is = upd.getInputStream();
if (is == null) {
throw new Exception("Server returned " + upd.getStatusCode() + "\nIf this error persists, please check forum!");
代码示例来源:origin: tinyMediaManager/tinyMediaManager
try {
String providedFiletype = FilenameUtils.getExtension(urlAsString);
Url url = new Url(urlAsString);
Path file = folder.resolve("fanart" + i + "." + providedFiletype);
LOGGER.debug("writing extrafanart " + file.getFileName());
is = url.getInputStreamWithRetry(5);
if (is == null) {
throw new FileNotFoundException("Error accessing url: " + url.getStatusLine());
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url url = new Url(urlToArtwork);
InputStream is = url.getInputStream();
if (url.isFault()) {
return;
代码示例来源:origin: org.tinymediamanager.plugins/scraper-ofdb
try {
url = new Url(searchString);
InputStream in = url.getInputStream();
Document doc = Jsoup.parse(in, "UTF-8", "");
in.close();
url = new Url(BASE_URL + "/" + StrgUtils.substr(filme.first().toString(), "href=\\\"(.*?)\\\""));
in = url.getInputStream();
doc = Jsoup.parse(in, "UTF-8", "");
in.close();
LOGGER.error("Error parsing {}", url.toString());
代码示例来源:origin: org.tinymediamanager.plugins/scraper-animated
Url u = new Url(BASE_URL + "movies.json");
u.download(JSON_FILE);
b = readJsonFile();
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url url = new Url(imageUrl);
originalImage = createImage(url.getBytes());
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* Instantiates a new url / httpclient with default user-agent.
*
* @param url
* the url
*/
public Url(String url) throws MalformedURLException {
if (client == null) {
client = TmmHttpClient.getHttpClient();
}
this.url = url;
if (url.contains("|")) {
splitHeadersFromUrl();
}
// morph to URI to check syntax of the url
try {
uri = morphStringToUri(url);
}
catch (URISyntaxException e) {
throw new MalformedURLException(url);
}
// default user agent
addHeader(USER_AGENT, UrlUtil.generateUA());
}
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* set a specified User-Agent
*
* @param userAgent
* the user agent to be set
*/
public void setUserAgent(String userAgent) {
addHeader(USER_AGENT, userAgent);
}
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* Gets the bytes with the given amount of retries
*
* @param retries
* the amount of retries (>0)
* @return the bytes or an empty array
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public byte[] getBytesWithRetry(int retries) throws IOException {
InputStream is = getInputStreamWithRetry(retries);
if (is != null) {
byte[] bytes = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
return bytes;
}
return new byte[0];
}
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* Download an Url to a file via NIO FileChannel (synchron)
*
* @param file
* @return successful or not
*/
public boolean download(File file) {
try {
InputStream is = getInputStream();
if (is == null) {
return false;
}
ReadableByteChannel rbc = Channels.newChannel(is);
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
return true;
}
catch (IOException e) {
LOGGER.error("Error downloading " + this.url);
}
catch (InterruptedException ignored) {
if (call != null) {
call.cancel();
}
}
return false;
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url url1 = new Url(url);
is = url1.getInputStreamWithRetry(5);
throw new FileNotFoundException("Error accessing url: " + url1.getStatusLine());
代码示例来源:origin: tinyMediaManager/tinyMediaManager
@Override
protected BufferedImage doInBackground() throws Exception {
try {
Url url = new Url(imageUrl);
return Scalr.resize(ImageCache.createImage(url.getBytesWithRetry(5)), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, newSize.width,
newSize.height,
Scalr.OP_ANTIALIAS);
}
catch (Exception e) {
imageUrl = "";
return null;
}
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
Url u = new Url(url);
boolean ok = u.download(cachedFile);
if (ok) {
LOGGER.trace("cached url successfully :) " + url);
代码示例来源:origin: org.tinymediamanager/api-scraper
/**
* pipe could be delimiter for header values (like seen in Kodi)<br>
* http://www.asdfcom/page?what=do|Referer=http://my.site.com<br>
* http://de.clip-1.filmtrailer.com/2845_14749_a_4.flv?log_var=67|491100001-1|-<br>
* split away from url, and add as header
*
*/
protected void splitHeadersFromUrl() {
Pattern p = Pattern.compile(".*\\|(.*?)=(.*?)$");
Matcher m = p.matcher(this.url);
if (m.find()) {
if (KNOWN_HEADERS.contains(m.group(1).toLowerCase(Locale.ROOT))) {
// ok, url might have a pipe, but we now have a recognized header - set it
this.url = this.url.substring(0, m.start(1) - 1); // -1 is pipe char
addHeader(m.group(1), m.group(2));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!