2009-07-03 09:07:43 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.web;
|
|
|
|
|
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
import static java.util.Collections.*;
|
2009-11-02 18:25:04 -05:00
|
|
|
import static net.sourceforge.filebot.Settings.*;
|
2009-07-03 09:07:43 -04:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.util.List;
|
2009-07-13 09:02:04 -04:00
|
|
|
import java.util.Map;
|
2009-07-03 09:07:43 -04:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
import net.sourceforge.filebot.web.OpenSubtitlesSubtitleDescriptor.Property;
|
|
|
|
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.Query;
|
2009-07-18 18:06:32 -04:00
|
|
|
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.SubFile;
|
|
|
|
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.TryUploadResponse;
|
2009-07-13 09:02:04 -04:00
|
|
|
|
2012-10-19 15:18:47 -04:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
|
|
|
|
public class OpenSubtitlesXmlRpcTest {
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
private static OpenSubtitlesXmlRpc xmlrpc = new OpenSubtitlesXmlRpc(String.format("%s %s", getApplicationName(), getApplicationVersion()));
|
2009-07-03 09:07:43 -04:00
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@BeforeClass
|
|
|
|
public static void login() throws Exception {
|
|
|
|
// login manually
|
|
|
|
xmlrpc.loginAnonymous();
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@Test
|
|
|
|
public void search() throws Exception {
|
2011-09-22 08:55:04 -04:00
|
|
|
List<Movie> list = xmlrpc.searchMoviesOnIMDB("babylon 5");
|
2012-10-19 15:18:47 -04:00
|
|
|
Movie sample = list.get(0);
|
2009-07-03 09:07:43 -04:00
|
|
|
|
|
|
|
// check sample entry
|
2012-02-13 04:54:57 -05:00
|
|
|
assertEquals("Babylon 5", sample.getName());
|
2011-08-21 23:43:22 -04:00
|
|
|
assertEquals(1994, sample.getYear());
|
2009-07-03 09:07:43 -04:00
|
|
|
assertEquals(105946, sample.getImdbId());
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2011-11-10 22:35:50 -05:00
|
|
|
@Test(expected = IndexOutOfBoundsException.class)
|
|
|
|
public void searchOST() throws Exception {
|
|
|
|
List<Movie> list = xmlrpc.searchMoviesOnIMDB("Linkin.Park.New.Divide.1280-720p.Transformers.Revenge.of.the.Fallen.ost");
|
|
|
|
|
|
|
|
// seek to OST entry, expect to fail
|
|
|
|
for (int i = 0; !list.get(i).getName().contains("Linkin.Park"); i++);
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@Test
|
|
|
|
public void getSubtitleListEnglish() throws Exception {
|
|
|
|
List<OpenSubtitlesSubtitleDescriptor> list = xmlrpc.searchSubtitles(361256, "eng");
|
|
|
|
|
|
|
|
SubtitleDescriptor sample = list.get(0);
|
|
|
|
|
|
|
|
assertTrue(sample.getName().startsWith("Wonderfalls"));
|
|
|
|
assertEquals("English", sample.getLanguageName());
|
|
|
|
|
|
|
|
// check size
|
|
|
|
assertTrue(list.size() > 20);
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@Test
|
|
|
|
public void getSubtitleListAllLanguages() throws Exception {
|
|
|
|
List<OpenSubtitlesSubtitleDescriptor> list = xmlrpc.searchSubtitles(361256);
|
|
|
|
|
|
|
|
OpenSubtitlesSubtitleDescriptor sample = list.get(75);
|
|
|
|
|
2011-08-08 13:37:45 -04:00
|
|
|
assertEquals("Wonderfalls", sample.getProperty(Property.MovieName));
|
2009-07-13 09:02:04 -04:00
|
|
|
assertEquals("Hungarian", sample.getProperty(Property.LanguageName));
|
|
|
|
assertEquals("imdbid", sample.getProperty(Property.MatchedBy));
|
2009-07-03 09:07:43 -04:00
|
|
|
|
|
|
|
// check size
|
|
|
|
assertTrue(list.size() > 70);
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@Test
|
2009-07-13 09:02:04 -04:00
|
|
|
public void getSubtitleListMovieHash() throws Exception {
|
|
|
|
List<OpenSubtitlesSubtitleDescriptor> list = xmlrpc.searchSubtitles(singleton(Query.forHash("2bba5c34b007153b", 717565952, "eng")));
|
|
|
|
|
|
|
|
OpenSubtitlesSubtitleDescriptor sample = list.get(0);
|
|
|
|
|
|
|
|
assertEquals("firefly.s01e01.serenity.pilot.dvdrip.xvid.srt", sample.getProperty(Property.SubFileName));
|
|
|
|
assertEquals("English", sample.getProperty(Property.LanguageName));
|
|
|
|
assertEquals("moviehash", sample.getProperty(Property.MatchedBy));
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-18 18:06:32 -04:00
|
|
|
@Test
|
|
|
|
public void tryUploadSubtitles() throws Exception {
|
|
|
|
SubFile subtitle = new SubFile();
|
|
|
|
subtitle.setSubFileName("firefly.s01e01.serenity.pilot.dvdrip.xvid.srt");
|
|
|
|
subtitle.setSubHash("6d9c600fb8b07f87ffcf156e4ed308ca");
|
|
|
|
subtitle.setMovieFileName("firefly.s01e01.serenity.pilot.dvdrip.xvid.avi");
|
|
|
|
subtitle.setMovieHash("2bba5c34b007153b");
|
|
|
|
subtitle.setMovieByteSize(717565952);
|
|
|
|
|
|
|
|
TryUploadResponse response = xmlrpc.tryUploadSubtitles(subtitle);
|
|
|
|
|
|
|
|
assertFalse(response.isUploadRequired());
|
|
|
|
assertEquals("100705", response.getSubtitleData().get(Property.IDSubtitle));
|
|
|
|
assertEquals("eng", response.getSubtitleData().get(Property.SubLanguageID));
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
@Test
|
|
|
|
public void checkSubHash() throws Exception {
|
|
|
|
Map<String, Integer> subHashMap = xmlrpc.checkSubHash(singleton("e12715f466ee73c86694b7ab9f311285"));
|
|
|
|
|
|
|
|
assertEquals("247060", subHashMap.values().iterator().next().toString());
|
|
|
|
assertTrue(1 == subHashMap.size());
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
@Test
|
|
|
|
public void checkSubHashInvalid() throws Exception {
|
|
|
|
Map<String, Integer> subHashMap = xmlrpc.checkSubHash(singleton("0123456789abcdef0123456789abcdef"));
|
|
|
|
|
|
|
|
assertEquals("0", subHashMap.values().iterator().next().toString());
|
|
|
|
assertTrue(1 == subHashMap.size());
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
@Test
|
|
|
|
public void checkMovieHash() throws Exception {
|
2012-10-19 15:18:47 -04:00
|
|
|
Map<String, Movie> results = xmlrpc.checkMovieHash(singleton("d7aa0275cace4410"), 0);
|
2011-09-22 08:55:04 -04:00
|
|
|
Movie movie = results.get("d7aa0275cace4410");
|
2009-07-13 09:02:04 -04:00
|
|
|
|
2009-10-20 17:16:34 -04:00
|
|
|
assertEquals("Iron Man", movie.getName());
|
|
|
|
assertEquals(2008, movie.getYear());
|
|
|
|
assertEquals(371746, movie.getImdbId());
|
2009-07-13 09:02:04 -04:00
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
@Test
|
|
|
|
public void checkMovieHashInvalid() throws Exception {
|
2012-10-19 15:18:47 -04:00
|
|
|
Map<String, Movie> results = xmlrpc.checkMovieHash(singleton("0123456789abcdef"), 0);
|
2009-07-13 09:02:04 -04:00
|
|
|
|
|
|
|
// no movie info
|
2009-10-20 17:16:34 -04:00
|
|
|
assertTrue(results.isEmpty());
|
2009-07-13 09:02:04 -04:00
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-11-21 20:27:05 -05:00
|
|
|
@Test
|
|
|
|
public void getIMDBMovieDetails() throws Exception {
|
2011-09-22 08:55:04 -04:00
|
|
|
Movie movie = xmlrpc.getIMDBMovieDetails(371746);
|
2009-11-21 20:27:05 -05:00
|
|
|
|
|
|
|
assertEquals("Iron Man", movie.getName());
|
|
|
|
assertEquals(2008, movie.getYear());
|
|
|
|
assertEquals(371746, movie.getImdbId());
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-11-21 20:27:05 -05:00
|
|
|
@Test
|
|
|
|
public void getIMDBMovieDetailsInvalid() throws Exception {
|
2011-09-22 08:55:04 -04:00
|
|
|
Movie movie = xmlrpc.getIMDBMovieDetails(371746);
|
2009-11-21 20:27:05 -05:00
|
|
|
|
|
|
|
assertEquals("Iron Man", movie.getName());
|
|
|
|
assertEquals(2008, movie.getYear());
|
|
|
|
assertEquals(371746, movie.getImdbId());
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-13 09:02:04 -04:00
|
|
|
@Test
|
|
|
|
public void detectLanguage() throws Exception {
|
|
|
|
String text = "Only those that are prepared to fire should be fired at.";
|
|
|
|
|
2009-10-20 17:16:34 -04:00
|
|
|
List<String> languages = xmlrpc.detectLanguage(text.getBytes("UTF-8"));
|
2009-07-13 09:02:04 -04:00
|
|
|
|
|
|
|
assertEquals("eng", languages.get(0));
|
|
|
|
assertTrue(1 == languages.size());
|
2009-07-03 09:07:43 -04:00
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@Test
|
|
|
|
public void fetchSubtitle() throws Exception {
|
|
|
|
List<OpenSubtitlesSubtitleDescriptor> list = xmlrpc.searchSubtitles(361256, "eng");
|
|
|
|
|
|
|
|
// check format
|
|
|
|
assertEquals("srt", list.get(0).getType());
|
|
|
|
|
|
|
|
// fetch subtitle file
|
|
|
|
ByteBuffer data = list.get(0).fetch();
|
|
|
|
|
|
|
|
// check size
|
2011-01-07 06:02:11 -05:00
|
|
|
assertEquals(48550, data.remaining(), 0);
|
2009-07-03 09:07:43 -04:00
|
|
|
}
|
|
|
|
|
2011-12-25 04:07:55 -05:00
|
|
|
|
2009-07-03 09:07:43 -04:00
|
|
|
@AfterClass
|
|
|
|
public static void logout() throws Exception {
|
|
|
|
// logout manually
|
|
|
|
xmlrpc.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|