com.moviejukebox.plugin.poster.ScopeDkPosterPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yamj Show documentation
Show all versions of yamj Show documentation
Static analysis of MovieJukebox project
/*
* Copyright (c) 2004-2012 YAMJ Members
* http://code.google.com/p/moviejukebox/people/list
*
* Web: http://code.google.com/p/moviejukebox/
*
* This software is licensed under a Creative Commons License
* See this page: http://code.google.com/p/moviejukebox/wiki/License
*
* For any reuse or distribution, you must make clear to others the
* license terms of this work.
*/
package com.moviejukebox.plugin.poster;
import com.moviejukebox.model.IImage;
import com.moviejukebox.model.Image;
import com.moviejukebox.model.Movie;
import com.moviejukebox.tools.HTMLTools;
import com.moviejukebox.tools.StringTools;
import com.moviejukebox.tools.WebBrowser;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.List;
import org.apache.log4j.Logger;
public class ScopeDkPosterPlugin extends AbstractMoviePosterPlugin {
private static final Logger logger = Logger.getLogger(ScopeDkPosterPlugin.class);
private WebBrowser webBrowser;
public ScopeDkPosterPlugin() {
super();
// Check to see if we are needed
if (!isNeeded()) {
return;
}
webBrowser = new WebBrowser();
}
@Override
public String getIdFromMovieInfo(String title, String year) {
String response = Movie.UNKNOWN;
try {
StringBuilder sb = new StringBuilder("http://www.scope.dk/sogning.php?sog=");// 9&type=film");
sb.append(URLEncoder.encode(title.replace(' ', '+'), "iso-8859-1"));
sb.append("&type=film");
String xml = webBrowser.request(sb.toString(), Charset.forName("ISO-8859-1"));
List tmp = HTMLTools.extractTags(xml, "", "
", "", " ", false);
for (int i = 0; i < tmp.size(); i++) {
String strRef = " -1 && endIndex > -1) {
// Take care of the year.
if (StringTools.isValidString(year)) {
// Found the same year. Ok
if (year.equalsIgnoreCase(tmp.get(i + 1).trim())) {
response = new String(tmp.get(i).substring(startIndex + strRef.length(), endIndex));
break;
}
} else {
// No year, so take the first one :(
response = new String(tmp.get(i).substring(startIndex + strRef.length(), endIndex));
break;
}
} else {
logger.warn("Not matching data for search film result : " + tmp.get(i));
}
i++; // Step of 2
}
} catch (Exception error) {
logger.error("Failed to retrieve Scope ID for movie : " + title);
}
return response;
}
@Override
public IImage getPosterUrl(String id) {
// ", "");
posterPageUrl = HTMLTools.extractTag(posterPageUrl, "");
posterPageUrl = new String(posterPageUrl.substring(posterPageUrl.indexOf("src=\"") + 5, posterPageUrl.indexOf("height") - 2));
if (StringTools.isValidString(posterPageUrl)) {
posterURL = posterPageUrl;
}
} catch (Exception e) {
logger.error("Failed retreiving ScopeDk url for movie : " + id);
logger.error("Error : " + e.getMessage());
}
}
if (!Movie.UNKNOWN.equalsIgnoreCase(posterURL)) {
return new Image(posterURL);
}
return Image.UNKNOWN;
}
@Override
public IImage getPosterUrl(String title, String year) {
return getPosterUrl(getIdFromMovieInfo(title, year));
}
@Override
public String getName() {
return "scopeDk";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy