Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************
- *
- *
- *
- *
- *
- ************************************************/
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import game.scraper.searchResult;
- import game.scraper.gameInformation;
- import static jdk.nashorn.internal.objects.NativeString.trim;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class ServiceProvider {
- public static String pluginName = "MobyGames";
- public static String authorName = "SthrnFriedChkn";
- public static String pluginVers = "1.0.0.0";
- public static String GetPluginName() {
- // Return the name of the plugin to the system
- return pluginName;
- }
- public static String GetAuthorName() {
- // Return the name of the author to the system
- return authorName;
- }
- public static String GetPluginVersion() {
- // Return the version of the plugin to the system
- return pluginVers;
- }
- public static void main(String[] args) throws IOException {
- // Returns basic usage information to the system.
- System.out.println(pluginName + " scraper, v" + pluginVers + " (C)opyright 2015, " + authorName);
- }
- public static List<String> getSupportedSystems() {
- // Compile and return a list of supported systems.
- List<String> supportedSystems = new ArrayList();
- supportedSystems.add("All Platforms");
- supportedSystems.add("3DO");
- supportedSystems.add("Acorn 32-bit");
- supportedSystems.add("Amiga");
- supportedSystems.add("Amiga CD32");
- supportedSystems.add("Amstrad CPC");
- supportedSystems.add("Amstrad PCW");
- supportedSystems.add("Android");
- supportedSystems.add("Apple II");
- supportedSystems.add("Apple IIgs");
- supportedSystems.add("Arcade");
- supportedSystems.add("Atari 2600");
- supportedSystems.add("Atari 5200");
- supportedSystems.add("Atari 7800");
- supportedSystems.add("Atari 8-bit");
- supportedSystems.add("Atari ST");
- supportedSystems.add("Atom");
- supportedSystems.add("bada");
- supportedSystems.add("Bally Astrocade");
- supportedSystems.add("BBC Micro");
- supportedSystems.add("BlackBerry");
- supportedSystems.add("BREW");
- supportedSystems.add("Browser");
- supportedSystems.add("Camputers Lynx");
- supportedSystems.add("Casio Loopy");
- supportedSystems.add("Casio PV-1000");
- supportedSystems.add("CD-i");
- supportedSystems.add("CDTV");
- supportedSystems.add("Channel F");
- supportedSystems.add("Coleco Adam");
- supportedSystems.add("ColecoVision");
- supportedSystems.add("Commodore 128");
- supportedSystems.add("Commodore 16, Plus/4");
- supportedSystems.add("Commodore 64");
- supportedSystems.add("Commodore PET/CBM");
- supportedSystems.add("DoJa");
- supportedSystems.add("DOS");
- supportedSystems.add("Dragon 32/64");
- supportedSystems.add("Dreamcast");
- supportedSystems.add("Electron");
- supportedSystems.add("Epoch Cassette Vision");
- supportedSystems.add("Epoch Game Pocket Computer");
- supportedSystems.add("ExEn");
- supportedSystems.add("Fire OS");
- supportedSystems.add("FM-7");
- supportedSystems.add("FM Towns");
- supportedSystems.add("Game Boy");
- supportedSystems.add("Game Boy Advance");
- supportedSystems.add("Game Boy Color");
- supportedSystems.add("Game.Com");
- supportedSystems.add("GameCube");
- supportedSystems.add("Game Gear");
- supportedSystems.add("GameStick");
- supportedSystems.add("Game Wave");
- supportedSystems.add("Genesis");
- supportedSystems.add("Gizmondo");
- supportedSystems.add("GP2X");
- supportedSystems.add("GP2X Wiz");
- supportedSystems.add("GP32");
- supportedSystems.add("Intellivision");
- supportedSystems.add("iPad");
- supportedSystems.add("iPhone");
- supportedSystems.add("iPod Classic");
- supportedSystems.add("J2ME");
- supportedSystems.add("Jaguar");
- supportedSystems.add("Jupiter Ace");
- supportedSystems.add("Kindle Classic");
- supportedSystems.add("Linux");
- supportedSystems.add("Lynx");
- supportedSystems.add("Macintosh");
- supportedSystems.add("Maemo");
- supportedSystems.add("Mattel Aquarius");
- supportedSystems.add("MeeGo");
- supportedSystems.add("Memotech MTX");
- supportedSystems.add("Microvision");
- supportedSystems.add("Mophun");
- supportedSystems.add("MSX");
- supportedSystems.add("Neo Geo");
- supportedSystems.add("Neo Geo CD");
- supportedSystems.add("Neo Geo Pocket");
- supportedSystems.add("Neo Geo Pocket Color");
- supportedSystems.add("NES");
- supportedSystems.add("N-Gage");
- supportedSystems.add("N-Gage (service)");
- supportedSystems.add("Nintendo 3DS");
- supportedSystems.add("Nintendo 64");
- supportedSystems.add("Nintendo DS");
- supportedSystems.add("Nintendo DSi");
- supportedSystems.add("Nuon");
- supportedSystems.add("Odyssey");
- supportedSystems.add("Odyssey 2");
- supportedSystems.add("Oric");
- supportedSystems.add("OS/2");
- supportedSystems.add("Ouya");
- supportedSystems.add("Palm OS");
- supportedSystems.add("PC-6001");
- supportedSystems.add("PC-88");
- supportedSystems.add("PC-98");
- supportedSystems.add("PC Booter");
- supportedSystems.add("PC-FX");
- supportedSystems.add("Philips VG 5000");
- supportedSystems.add("Pippin");
- supportedSystems.add("Playdia");
- supportedSystems.add("PlayStation");
- supportedSystems.add("PlayStation 2");
- supportedSystems.add("PlayStation 3");
- supportedSystems.add("PlayStation 4");
- supportedSystems.add("Pokémon Mini");
- supportedSystems.add("PSP");
- supportedSystems.add("PS Vita");
- supportedSystems.add("RCA Studio II");
- supportedSystems.add("SAM Coupé");
- supportedSystems.add("SEGA 32X");
- supportedSystems.add("SEGA CD");
- supportedSystems.add("SEGA Master System");
- supportedSystems.add("SEGA Pico");
- supportedSystems.add("SEGA Saturn");
- supportedSystems.add("SG-1000");
- supportedSystems.add("Sharp X1");
- supportedSystems.add("Sharp X68000");
- supportedSystems.add("Sinclair QL");
- supportedSystems.add("SNES");
- supportedSystems.add("Sord M5");
- supportedSystems.add("Spectravideo");
- supportedSystems.add("Super A'can");
- supportedSystems.add("SuperGrafx");
- supportedSystems.add("Supervision");
- supportedSystems.add("Symbian");
- supportedSystems.add("Tatung Einstein");
- supportedSystems.add("Thomson MO");
- supportedSystems.add("Thomson TO");
- supportedSystems.add("TI-99/4A");
- supportedSystems.add("Tomy Tutor");
- supportedSystems.add("TRS-80");
- supportedSystems.add("TRS-80 CoCo");
- supportedSystems.add("TurboGrafx-16");
- supportedSystems.add("TurboGrafx CD");
- supportedSystems.add("Vectrex");
- supportedSystems.add("VIC-20");
- supportedSystems.add("Videopac+ G7400");
- supportedSystems.add("Virtual Boy");
- supportedSystems.add("V.Smile");
- supportedSystems.add("webOS");
- supportedSystems.add("Wii");
- supportedSystems.add("Wii U");
- supportedSystems.add("Windows");
- supportedSystems.add("Windows 3.x");
- supportedSystems.add("Windows Mobile");
- supportedSystems.add("Windows Phone");
- supportedSystems.add("WonderSwan");
- supportedSystems.add("WonderSwan Color");
- supportedSystems.add("Xbox");
- supportedSystems.add("Xbox 360");
- supportedSystems.add("Xbox One");
- supportedSystems.add("Zeebo");
- supportedSystems.add("Zodiac");
- supportedSystems.add("ZX80");
- supportedSystems.add("ZX81");
- supportedSystems.add("ZX Spectrum");
- return supportedSystems;
- }
- public static class GetGame {
- public static void main(String[] args) throws IOException {
- /* This code is executed whenever the system queries the script. */
- System.out.println(pluginName + " scraper, v" + pluginVers + " (C)opyright 2015, " + authorName);
- }
- /******************************************************************************************
- * getInfo() will return a gameInformation object back to the calling object. All you needed
- * to do is pass getInfo() an URL where the game information is stored on mobygames.com.
- *
- * gameInformation fields:
- *
- * publishedBy = the name of the company whom published the game.
- * developedBy = the name of the developing company.
- * releaseDate = the release date of the game.
- * gameGenre = the genre of the game (if applicable).
- * gamePerspective = the perspective in which the game is played (if applicable).
- * gameScore = the user rating of the game (not the moby score (which is useless)).
- * gameScreenshots = a List<String> of screenshot URL's gathered by the scraper.
- * gameOtherArtwork = a List<String> of other artwork URL's gathered by the scraper.
- ******************************************************************************************/
- public static gameInformation getInfo(String queryUrl) {
- // Declare the screenshot URL & artwork URL (appended to original URL).
- String screenshotUrl = queryUrl + "/screenshots";
- String artworkUrl = queryUrl + "/";
- gameInformation returnInformation = new gameInformation();
- try {
- // Connnect to the site using a Mozilla/5 based client.
- Document generalInfo = Jsoup.connect(queryUrl).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();
- Elements div = generalInfo.select("#coreGameRelease div");
- // Begin the extraction of the basic elements.
- int countBase = 0;
- for (Element qt : div) {
- if (countBase == 1) {
- returnInformation.publishedBy = qt.text();
- }
- if (countBase == 3) {
- returnInformation.developedBy = qt.text();
- }
- if (countBase == 5) {
- returnInformation.releaseDate = qt.text();
- }
- countBase++;
- }
- Elements genre = generalInfo.select("#coreGameGenre div div");
- // Begin the extraction of genre & perspective.
- int genreBase = 0;
- for (Element qt : genre) {
- if (genreBase == 1) {
- returnInformation.gameGenre = qt.text();
- }
- if (genreBase == 3) {
- returnInformation.gamePerspective = qt.text();
- }
- genreBase++;
- }
- // Extract the games user score rating.
- returnInformation.gameScore = generalInfo.select(".fr.scoreBoxMed.scoreHi").first().text();
- // Get the uncut wrapper text which contains the description and alot of other
- // useless information.
- String rawDescription = generalInfo.select("#wrapper").first().text();
- // Setup our regex patters.
- String pattern1 = "Description";
- String pattern2 = "[edit description | view history]";
- Pattern p = Pattern.compile(Pattern.quote(pattern1) + "(.*?)" + Pattern.quote(pattern2));
- Matcher m = p.matcher(rawDescription);
- // Begin using regex to extract the full description.
- while (m.find()) {
- returnInformation.gameDescription = m.group(1);
- }
- // Connnect to the screenshot site using a Mozilla/5 based client.
- Document imageInfo = Jsoup.connect(screenshotUrl).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();
- Elements rows = imageInfo.select(".row img");
- // Begin the extraction of image URL's
- for (Element image : rows) {
- returnInformation.gameScreenshots.add(image.attr("abs:src"));
- }
- // Remove the first and last index from the array (they are MobyGames.com logos).
- returnInformation.gameScreenshots.remove(0);
- returnInformation.gameScreenshots.remove(returnInformation.gameScreenshots.size() -1);
- }catch(IOException e) {
- e.printStackTrace();
- }
- // Last but not least return the object to the
- // calling system.
- return returnInformation;
- }
- }
- public static class SearchGames {
- /******************************************************************************************
- * SearchGames will return a list of all available games found
- * using the scraper SearchGames method. Each searchResults
- * contain two parameters used to identify the game being searched
- * for:
- *
- * searchGame.gameName = The name given by the search provider.
- * searchGame.defaultLink = The default link to the game as given by the provider.
- * searchGame.gameSystem = A list containing the system name (to the left) and the
- * URL (to the right), this list is parsed using an '|' as a separator
- * (ie SNES|http://www.mobygames.com/game/snes/super-mario-world).
- *
- * The above values will return all the information needed to pull a game
- * and pass it to the processor class when called.
- ******************************************************************************************/
- public static void main(String[] args) throws IOException {
- /* This code is executed whenever the system queries the script. */
- System.out.println(pluginName + " scraper, v" + pluginVers + " (C)opyright 2015, " + authorName);
- }
- // returnSystem() returns the numerical value associated with
- // each system.
- public static String returnSystem(String inputId) {
- switch(inputId) {
- case "All Platforms": return "-1";
- case "3D0": return "35";
- case "Acorn 32-bit": return "117";
- case "Amiga": return "19";
- case "Amiga CD32": return "56";
- case "Amstrad CPC": return "60";
- case "Amstrad PCW": return "136";
- case "Android": return "91";
- case "Apple II": return "31";
- case "Apple IIgs": return "51";
- case "Arcade": return "143";
- case "Atari 2600": return "28";
- case "Atari 5200": return "33";
- case "Atari 7800": return "34";
- case "Atari 8-bit": return "39";
- case "Atari ST": return "24";
- case "Atom": return "129";
- case "bada": return "99";
- case "Bally Astrocade": return "160";
- case "BBC Micro": return "92";
- case "BlackBerry": return "90";
- case "BREW": return "63";
- case "Browser": return "84";
- case "Camputers Lynx": return "154";
- case "Casio Loopy": return "124";
- case "Casio PV-1000": return "125";
- case "CD-i": return "73";
- case "CDTV": return "83";
- case "Channel F": return "76";
- case "Coleco Adam": return "156";
- case "ColecoVision": return "29";
- case "Commodore 128": return "61";
- case "Commodore 16, Plus/4": return "115";
- case "Commodore 64": return "27";
- case "Commodore PET/CBM": return "77";
- case "DoJa": return "72";
- case "DOS": return "2";
- case "Dragon 32/64": return "79";
- case "Dreamcast": return "8";
- case "Electron": return "93";
- case "Epoch Cassette Vision": return "137";
- case "Epoch Game Pocket Computer": return "139";
- case "Epoch Super Cassette Vision": return "138";
- case "ExEn": return "70";
- case "Fire OS": return "159";
- case "FM-7": return "126";
- case "FM Towns": return "102";
- case "Game Boy": return "10";
- case "Game Boy Advance": return "12";
- case "Game Boy Color": return "11";
- case "Game.com": return "50";
- case "GameCube": return "14";
- case "GameStick": return "155";
- case "Game Wave": return "104";
- case "Genesis": return "16";
- case "Gizmondo": return "55";
- case "GP2X": return "122";
- case "GP2X Wiz": return "123";
- case "GP32": return "108";
- case "Intellivision": return "30";
- case "iPad": return "96";
- case "iPhone": return "86";
- case "iPod Classic": return "80";
- case "J2ME": return "64";
- case "Jaguar": return "17";
- case "Jupiter Ace": return "153";
- case "Kindle Classic": return "145";
- case "Linux": return "1";
- case "Lynx": return "18";
- case "Macintosh": return "74";
- case "Maemo": return "157";
- case "Mattel Aquarius": return "135";
- case "MeeGo": return "158";
- case "Memotech MTX": return "148";
- case "Microvision": return "97";
- case "Mophun": return "71";
- case "MSX": return "57";
- case "Neo Geo": return "36";
- case "Neo Geo CD": return "36";
- case "Neo Geo Pocket": return "52";
- case "Neo Geo Pocket Color": return "53";
- case "NES": return "22";
- case "N-Gage": return "32";
- case "N-Gage (service)": return "89";
- case "Nintendo 3DS": return "101";
- case "Nintendo 64": return "9";
- case "Nintendo DS": return "44";
- case "Nintendo DSi": return "87";
- case "Nuon": return "116";
- case "Odyssey": return "75";
- case "Odyssey 2": return "78";
- case "Oric": return "111";
- case "OS/2": return "146";
- case "Ouya": return "144";
- case "Palm OS": return "65";
- case "PC-6001": return "149";
- case "PC-88": return "94";
- case "PC-98": return "95";
- case "PC Booter": return "4";
- case "PC-FX": return "59";
- case "Philips VG 5000": return "133";
- case "Pippin": return "112";
- case "Playdia": return "107";
- case "PlayStation": return "6";
- case "PlayStation 2": return "7";
- case "PlayStation 3": return "81";
- case "PlayStation 4": return "141";
- case "Pokémon Mini": return "152";
- case "PSP": return "46";
- case "PS Vita": return "105";
- case "RCA Studio II": return "113";
- case "SAM Coupé": return "120";
- case "SEGA 32X": return "21";
- case "SEGA CD": return "20";
- case "SEGA Master System": return "26";
- case "SEGA Pico": return "103";
- case "SEGA Saturn": return "23";
- case "SG-1000": return "114";
- case "Sharp X1": return "121";
- case "Sharp X68000": return "106";
- case "Sinclair QL": return "131";
- case "SNES": return "15";
- case "Sord M5": return "134";
- case "Spectravideo": return "85";
- case "Super A'can": return "110";
- case "SuperGrafx": return "127";
- case "Supervision": return "109";
- case "Symbian": return "67";
- case "Tatung Einstein": return "150";
- case "Thomson MO": return "147";
- case "Thomson TO": return "130";
- case "TI-99/4A": return "47";
- case "Tomy Tutor": return "151";
- case "TRS-80": return "58";
- case "TRS-80 CoCo": return "62";
- case "TurboGrafx-16": return "40";
- case "TurboGrafx CD": return "45";
- case "Vectrex": return "37";
- case "VIC-20": return "43";
- case "Videopac+ G7400": return "128";
- case "Virtual Boy": return "38";
- case "V.Smile": return "42";
- case "webOS": return "100";
- case "Wii": return "132";
- case "Wii U": return "132";
- case "Windows": return "3";
- case "Windows 3.x": return "5";
- case "Windows Mobile": return "66";
- case "Windows Phone": return "98";
- case "WonderSwan": return "48";
- case "WonderSwan Color": return "49";
- case "Xbox": return "13";
- case "Xbox 360": return "69";
- case "Xbox One": return "142";
- case "Zeebo": return "88";
- case "Zodiac": return "68";
- case "ZX80": return "118";
- case "ZX81": return "119";
- case "ZX Spectrum": return "41";
- default: return "-1";
- }
- }
- public static List<searchResult> doSearch(String[] args) {
- String gameName = args[0];
- String systemName = args[1];
- List<searchResult> searchResults = new ArrayList<searchResult>();
- try {
- Document doc = Jsoup.connect("http://www.mobygames.com/search/quick?q=" + gameName + "&p=" + returnSystem(systemName) + "&search=Go&sFilter=1&sG=on").userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();
- Elements div = doc.select(".searchResult");
- for (Element qt : div) {
- searchResult gameResult = new searchResult();
- Element vr = qt.select(".searchTitle a").first();
- gameResult.gameName = vr.text();
- gameResult.defaultLink = vr.attr("abs:href");
- if ("-1".equals(returnSystem(systemName))) {
- Elements systems = qt.select(".searchDetails a");
- for (Element rt : systems) {
- gameResult.gameSystem.add(rt.text() + "|" + rt.attr("abs:href"));
- }
- }else {
- gameResult.gameSystem.add(systemName);
- }
- searchResults.add(gameResult);
- }
- }catch(IOException e) {
- e.printStackTrace();
- }
- return searchResults;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement