org.tinymediamanager.scraper.http.Url类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.tinymediamanager.scraper.http.Url类的一些代码示例,展示了Url类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Url类的具体详情如下:
包路径:org.tinymediamanager.scraper.http.Url
类名称: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

  1. Url jsPlayer = new Url("https:" + matcher.group(1).replaceAll("\\\\", ""));
  2. StringWriter writer = new StringWriter();
  3. IOUtils.copy(jsPlayer.getInputStream(), writer, "UTF-8");
  4. playerJavascript = writer.toString();

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * Download an Url to a file via NIO FileChannel (synchron)
  3. *
  4. * @param file
  5. * @return successful or not
  6. */
  7. public boolean download(Path file) {
  8. return download(file.toFile());
  9. }

代码示例来源:origin: org.tinymediamanager.plugins/scraper-imdb

  1. @Override
  2. public Document call() throws Exception {
  3. doc = null;
  4. try {
  5. Url url = new Url(this.url);
  6. url.addHeader("Accept-Language", getAcceptLanguage(language, country));
  7. doc = Jsoup.parse(url.getInputStream(), imdbSite.getCharset().displayName(), "");
  8. }
  9. catch (Exception e) {
  10. getLogger().debug("tried to fetch imdb page " + url, e);
  11. }
  12. return doc;
  13. }
  14. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. @Override
  2. protected BufferedImage doInBackground() throws Exception {
  3. try {
  4. Url url = new Url(imageUrl);
  5. return ImageCache.createImage(url.getBytesWithRetry(5));
  6. }
  7. catch (Exception e) {
  8. LOGGER.warn("fetch image: " + e.getMessage());
  9. return null;
  10. }
  11. }

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. counter++;
  2. try {
  3. is = getInputStream();
  4. if (is != null || (is == null && getStatusCode() > 0 && getStatusCode() < 500)) {

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * Gets the bytes.
  3. *
  4. * @return the bytes
  5. * @throws IOException
  6. * Signals that an I/O exception has occurred.
  7. */
  8. public byte[] getBytes() throws IOException, InterruptedException {
  9. InputStream is = getInputStream();
  10. byte[] bytes = IOUtils.toByteArray(is);
  11. IOUtils.closeQuietly(is);
  12. return bytes;
  13. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. Url upd = new Url(uu + "digest.txt?z=" + System.currentTimeMillis()); // cache bust
  2. LOGGER.trace("Checking " + uu);
  3. remoteDigest = IOUtils.toString(upd.getInputStream(), "UTF-8");
  4. if (remoteDigest != null && remoteDigest.contains("tmm.jar")) {
  5. remoteDigest = remoteDigest.trim();
  6. LOGGER.info("Update needed...");
  7. Url gd = new Url(remoteUrl + "getdown.txt");
  8. String remoteGD = IOUtils.toString(gd.getInputStream(), "UTF-8");
  9. if (remoteGD.contains("forceUpdate")) {
  10. forceUpdate = true;
  11. Url upd = new Url(remoteUrl + "changelog.txt");
  12. changelog = IOUtils.toString(upd.getInputStream(), "UTF-8");
  13. return true;
  14. fallback += "/getdown.txt";
  15. Url upd = new Url(fallback);
  16. InputStream is = upd.getInputStream();
  17. if (is == null) {
  18. throw new Exception("Server returned " + upd.getStatusCode() + "\nIf this error persists, please check forum!");

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. try {
  2. String providedFiletype = FilenameUtils.getExtension(urlAsString);
  3. Url url = new Url(urlAsString);
  4. Path file = folder.resolve("fanart" + i + "." + providedFiletype);
  5. LOGGER.debug("writing extrafanart " + file.getFileName());
  6. is = url.getInputStreamWithRetry(5);
  7. if (is == null) {
  8. throw new FileNotFoundException("Error accessing url: " + url.getStatusLine());

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. Url url = new Url(urlToArtwork);
  2. InputStream is = url.getInputStream();
  3. if (url.isFault()) {
  4. return;

代码示例来源:origin: org.tinymediamanager.plugins/scraper-ofdb

  1. try {
  2. url = new Url(searchString);
  3. InputStream in = url.getInputStream();
  4. Document doc = Jsoup.parse(in, "UTF-8", "");
  5. in.close();
  6. url = new Url(BASE_URL + "/" + StrgUtils.substr(filme.first().toString(), "href=\\\"(.*?)\\\""));
  7. in = url.getInputStream();
  8. doc = Jsoup.parse(in, "UTF-8", "");
  9. in.close();
  10. LOGGER.error("Error parsing {}", url.toString());

代码示例来源:origin: org.tinymediamanager.plugins/scraper-animated

  1. Url u = new Url(BASE_URL + "movies.json");
  2. u.download(JSON_FILE);
  3. b = readJsonFile();

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. Url url = new Url(imageUrl);
  2. originalImage = createImage(url.getBytes());

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * Instantiates a new url / httpclient with default user-agent.
  3. *
  4. * @param url
  5. * the url
  6. */
  7. public Url(String url) throws MalformedURLException {
  8. if (client == null) {
  9. client = TmmHttpClient.getHttpClient();
  10. }
  11. this.url = url;
  12. if (url.contains("|")) {
  13. splitHeadersFromUrl();
  14. }
  15. // morph to URI to check syntax of the url
  16. try {
  17. uri = morphStringToUri(url);
  18. }
  19. catch (URISyntaxException e) {
  20. throw new MalformedURLException(url);
  21. }
  22. // default user agent
  23. addHeader(USER_AGENT, UrlUtil.generateUA());
  24. }

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * set a specified User-Agent
  3. *
  4. * @param userAgent
  5. * the user agent to be set
  6. */
  7. public void setUserAgent(String userAgent) {
  8. addHeader(USER_AGENT, userAgent);
  9. }

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * Gets the bytes with the given amount of retries
  3. *
  4. * @param retries
  5. * the amount of retries (>0)
  6. * @return the bytes or an empty array
  7. * @throws IOException
  8. * Signals that an I/O exception has occurred.
  9. */
  10. public byte[] getBytesWithRetry(int retries) throws IOException {
  11. InputStream is = getInputStreamWithRetry(retries);
  12. if (is != null) {
  13. byte[] bytes = IOUtils.toByteArray(is);
  14. IOUtils.closeQuietly(is);
  15. return bytes;
  16. }
  17. return new byte[0];
  18. }

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * Download an Url to a file via NIO FileChannel (synchron)
  3. *
  4. * @param file
  5. * @return successful or not
  6. */
  7. public boolean download(File file) {
  8. try {
  9. InputStream is = getInputStream();
  10. if (is == null) {
  11. return false;
  12. }
  13. ReadableByteChannel rbc = Channels.newChannel(is);
  14. FileOutputStream fos = new FileOutputStream(file);
  15. fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
  16. fos.close();
  17. return true;
  18. }
  19. catch (IOException e) {
  20. LOGGER.error("Error downloading " + this.url);
  21. }
  22. catch (InterruptedException ignored) {
  23. if (call != null) {
  24. call.cancel();
  25. }
  26. }
  27. return false;
  28. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. Url url1 = new Url(url);
  2. is = url1.getInputStreamWithRetry(5);
  3. throw new FileNotFoundException("Error accessing url: " + url1.getStatusLine());

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. @Override
  2. protected BufferedImage doInBackground() throws Exception {
  3. try {
  4. Url url = new Url(imageUrl);
  5. return Scalr.resize(ImageCache.createImage(url.getBytesWithRetry(5)), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, newSize.width,
  6. newSize.height,
  7. Scalr.OP_ANTIALIAS);
  8. }
  9. catch (Exception e) {
  10. imageUrl = "";
  11. return null;
  12. }
  13. }

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. Url u = new Url(url);
  2. boolean ok = u.download(cachedFile);
  3. if (ok) {
  4. LOGGER.trace("cached url successfully :) " + url);

代码示例来源:origin: org.tinymediamanager/api-scraper

  1. /**
  2. * pipe could be delimiter for header values (like seen in Kodi)<br>
  3. * http://www.asdfcom/page?what=do|Referer=http://my.site.com<br>
  4. * http://de.clip-1.filmtrailer.com/2845_14749_a_4.flv?log_var=67|491100001-1|-<br>
  5. * split away from url, and add as header
  6. *
  7. */
  8. protected void splitHeadersFromUrl() {
  9. Pattern p = Pattern.compile(".*\\|(.*?)=(.*?)$");
  10. Matcher m = p.matcher(this.url);
  11. if (m.find()) {
  12. if (KNOWN_HEADERS.contains(m.group(1).toLowerCase(Locale.ROOT))) {
  13. // ok, url might have a pipe, but we now have a recognized header - set it
  14. this.url = this.url.substring(0, m.start(1) - 1); // -1 is pipe char
  15. addHeader(m.group(1), m.group(2));
  16. }
  17. }
  18. }

相关文章