Last active
July 21, 2019 02:34
-
-
Save NonlinearFruit/2fe45c07f6d6326b3c15ab312d4adc07 to your computer and use it in GitHub Desktop.
Retrospector Tv Series 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 'TV Series' category. | |
It is not meant to for anything else. Assumptions: | |
- 'Year' factoid exists | |
- Seasons are of the form 'S1', 'S2' | |
- Episodes are of the form 'E9', 'E10', 'E11 The Fall' | |
- Everything after a ',' can be ignored | |
- 'Article' is the default category | |
- Always have a title, season and episode | |
**/ | |
// '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 addEpisodeTitles = true; | |
var baseUrl = 'http://www.omdbapi.com?apikey='+apiKey+'&r=xml&plot=full'; | |
// 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 get season/episode #s | |
var title = media.getTitle().replace(/,.*/g, "").trim(); | |
var season = /[A-Z](\d+)/g.exec(media.getSeason())[1]; | |
var episode = /[A-Z](\d+)/g.exec(media.getEpisode())[1]; | |
var category = media.getCategory(); | |
// Make the url | |
var url = baseUrl + '&t=' + title + '&season=' + season + "&episode=" + episode | |
DataScraper.print("URL="+url); | |
// Get some data! | |
var xml = DataScraper.getUrlContent(url); | |
var dom = DataScraper.convertStringToDocument(xml); | |
DataScraper.print(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)); | |
// Add episode title | |
var episodeTitle = movieElement.getAttribute('title'); | |
media.setEpisode('E'+episode+' '+episodeTitle); | |
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)