2013-01-22 03:14:21 -05:00
|
|
|
/****************************************************************************
|
|
|
|
* Pushover
|
|
|
|
* https://pushover.net
|
|
|
|
****************************************************************************/
|
|
|
|
def Pushover(user, token = 'wcckDz3oygHSU2SdIptvnHxJ92SQKK') {
|
|
|
|
new PushoverClient(user:user, token:token)
|
|
|
|
}
|
|
|
|
|
|
|
|
class PushoverClient {
|
|
|
|
def user
|
|
|
|
def token
|
|
|
|
|
|
|
|
def endpoint = new URL('https://api.pushover.net/1/messages.xml')
|
|
|
|
|
|
|
|
def send = { text, parameters = [:] ->
|
|
|
|
// inject default post parameters
|
|
|
|
parameters << [token:token, user:user, message:text as String]
|
|
|
|
|
|
|
|
// post and process response
|
|
|
|
endpoint.post(parameters).text.xml
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* MyEpisodes
|
|
|
|
* http://www.myepisodes.com
|
|
|
|
****************************************************************************/
|
2012-12-06 14:24:25 -05:00
|
|
|
@Grab(group='org.jsoup', module='jsoup', version='1.7.1')
|
|
|
|
import org.jsoup.Jsoup
|
|
|
|
import org.jsoup.Connection.Method
|
|
|
|
import net.sourceforge.filebot.Cache
|
|
|
|
|
|
|
|
def MyEpisodes(username, password) {
|
|
|
|
return new MyEpisodesScraper(username:username, password:password)
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyEpisodesScraper {
|
|
|
|
def username
|
|
|
|
def password
|
|
|
|
|
2013-03-18 01:23:41 -04:00
|
|
|
def cache = Cache.getCache('web-datasource-lv2')
|
2012-12-06 14:24:25 -05:00
|
|
|
def session = [:]
|
|
|
|
|
|
|
|
def login = {
|
|
|
|
def response = Jsoup.connect('http://www.myepisodes.com/login.php').data('username', username, 'password', password, 'action', 'Login', 'u', '').method(Method.POST).execute()
|
|
|
|
session << response.cookies()
|
|
|
|
return response.parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
def get = { url ->
|
|
|
|
if (session.isEmpty()) {
|
|
|
|
login()
|
|
|
|
}
|
|
|
|
|
|
|
|
def response = Jsoup.connect(url).cookies(session).method(Method.GET).execute()
|
|
|
|
session << response.cookies()
|
|
|
|
def html = response.parse()
|
|
|
|
|
|
|
|
if (html.select('#frmLogin')) {
|
|
|
|
session.clear()
|
|
|
|
throw new Exception('Login failed')
|
|
|
|
}
|
|
|
|
|
|
|
|
return html
|
|
|
|
}
|
|
|
|
|
|
|
|
def getShows = {
|
2012-12-07 05:04:29 -05:00
|
|
|
def shows = cache.get('MyEpisodes.Shows')
|
2012-12-06 14:24:25 -05:00
|
|
|
if (shows == null) {
|
|
|
|
shows = ['other', 'A'..'Z'].flatten().findResults{ section ->
|
|
|
|
get("http://myepisodes.com/shows.php?list=${section}").select('a').findResults{ a ->
|
|
|
|
try {
|
2012-12-07 05:04:29 -05:00
|
|
|
return [id:a.absUrl('href').match(/showid=(\d+)/).toInteger(), name:a.text().trim()]
|
2012-12-06 14:24:25 -05:00
|
|
|
} catch(e) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
2012-12-07 05:04:29 -05:00
|
|
|
}.flatten().sort{ it.name }
|
2012-12-06 14:24:25 -05:00
|
|
|
cache.put('MyEpisodes.Shows', shows)
|
|
|
|
}
|
|
|
|
return shows
|
|
|
|
}
|
|
|
|
|
|
|
|
def getShowList = {
|
|
|
|
get("http://www.myepisodes.com/shows.php?type=manage").select('option').findResults{ option ->
|
|
|
|
try {
|
2012-12-07 05:04:29 -05:00
|
|
|
return [id:option.attr('value').toInteger(), name:option.text().trim()]
|
2012-12-06 14:24:25 -05:00
|
|
|
} catch(e) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def addShow = { showid ->
|
2012-12-08 23:28:49 -05:00
|
|
|
get("http://www.myepisodes.com/views.php?type=manageshow&mode=add&showid=${showid}")
|
2012-12-06 14:24:25 -05:00
|
|
|
}
|
|
|
|
|
2013-04-16 13:30:51 -04:00
|
|
|
def update = { showid, season, episode, tick = 'acquired', value = '1' ->
|
2012-12-08 23:28:49 -05:00
|
|
|
get("http://www.myepisodes.com/myshows.php?action=Update&showid=${showid}&season=${season}&episode=${episode}&${tick}=${value}")
|
2012-12-06 14:24:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|