org.tinymediamanager.scraper.http.Url.addHeader()方法的使用及代码示例

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

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

Url.addHeader介绍

[英]Adds the header.
[中]

代码示例

代码示例来源: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

/**
 * 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));
  }
 }
}

代码示例来源: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: 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.plugins/scraper-imdb

try {
 Url url = new Url(sb.toString());
 url.addHeader("Accept-Language", getAcceptLanguage(language, country));
 doc = Jsoup.parse(url.getInputStream(), "UTF-8", "");

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

&& StringUtils.isNotBlank((String) wantedEpisode.ids.get(providerInfo.getId()))) {
Url url = new Url(imdbSite.getSite() + "/title/" + wantedEpisode.ids.get(providerInfo.getId()) + "/fullcredits");
url.addHeader("Accept-Language", "en"); // force EN for parsing by HTMl texts
Document doc = Jsoup.parse(url.getInputStream(), imdbSite.getCharset().displayName(), "");

相关文章