Last active
July 21, 2019 02:33
-
-
Save NonlinearFruit/581d01718aa3cdc8cefc80cd2c50f5a8 to your computer and use it in GitHub Desktop.
Retrospector Movie Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This plugin is only meant to handle the 'Movie' category. | |
It is not meant to for anything else. Assumptions: | |
- 'Year' factoid exists | |
- Movie episodes are of the form 'M1 Age of Ultron', 'P6 Return of the Jedi' etc | |
- Movies with season+episode contain the movie title in the season field 'M3 Return of the King' | |
- If there is a comma in the title, it is only followed by 'a', 'an' or 'the' | |
**/ | |
// 'Import' the necessary classes | |
var DataScraper = Java.type('retrospector.fxml.media.JsDataScraper'); | |
var Media = Java.type('retrospector.model.Media'); | |
var Factoid = Java.type('retrospector.model.Factoid'); | |
// Variables to set | |
var apiKey = '81703759'; | |
var baseUrl = 'http://www.omdbapi.com?apikey='+apiKey+'&r=xml&plot=full&type=movie'; | |
// Extend the abstract 'JsDataScraper' class and create an instance | |
var scraper = new DataScraper{ | |
// This is the method that will be called and given a media object | |
autocomplete: function(media) { | |
// Get values and remove ', The' and 'E1' stuff | |
var title = media.getTitle().replace(/,.*/g, "").trim(); | |
var season = media.getSeason().replace(/,.*/g, "").replace(/[A-Z]\d+/g, "").trim(); | |
var episode = media.getEpisode().replace(/,.*/g, "").replace(/[A-Z]\d+/g, "").trim(); | |
var category = media.getCategory(); | |
// Make the url | |
var url; | |
if (episode) | |
url = baseUrl + '&t=' + episode; | |
else if (season) | |
url = baseUrl + '&t=' + season; | |
else if (title) | |
url = baseUrl + '&t=' + title; | |
else | |
return media; | |
// Get some data! | |
var xml = DataScraper.getUrlContent(url); | |
var dom = DataScraper.convertStringToDocument(xml); | |
// Get the media | |
var movieElement = dom.getElementsByTagName('movie').item(0) | |
// Add description | |
var description = movieElement.getAttribute('plot'); | |
media.setDescription(description); | |
// Add year factoid | |
var year = movieElement.getAttribute('year'); | |
media.getFactoids().add(new Factoid('Year',year)); | |
return media; | |
} | |
}; | |
// 'Return' the scraper object | |
scraper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Retrospector is a desktop app for rating and reviewing media (movies, books, tv shows, etc)