Skip to content

Instantly share code, notes, and snippets.

@NonlinearFruit
Last active July 21, 2019 02:33
Show Gist options
  • Save NonlinearFruit/581d01718aa3cdc8cefc80cd2c50f5a8 to your computer and use it in GitHub Desktop.
Save NonlinearFruit/581d01718aa3cdc8cefc80cd2c50f5a8 to your computer and use it in GitHub Desktop.
Retrospector Movie Plugin
/**
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;
@NonlinearFruit
Copy link
Author

NonlinearFruit commented Dec 6, 2017

Retrospector is a desktop app for rating and reviewing media (movies, books, tv shows, etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment