Skip to content

Commit

Permalink
Lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
frdfsnlght committed Dec 19, 2014
1 parent c69c0a4 commit 9058a80
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 41 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Addon for SickRage.

## Features
- Manage shows (add/delete, review seasons/episodes)
- Change episode status
- View upcoming episodes
- View download history
- View backlog
- View failed downloads
- View/delete failed downloads
- Customizable date/time format

## Screenshots
Expand All @@ -19,4 +20,7 @@ Addon for SickRage.
[Backlog](http://imgur.com/zeyxAYe)

## Install
Coming soon.
- Download the latest release file
- Save it where Kodi/XBMC can read it
- Install add on from zip file in Kodi/XBMC

4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

* wait for delete failed API
* submit issue: sb.searchtvdb and sb.searchtvrage both search all indexers

4 changes: 1 addition & 3 deletions addon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import resources.lib.util as util

# wrap this in a try/catch to catch broken API calls (can't connect, timeout, etc)

try:
if 'vf' in util.pluginArgs:
vf = util.pluginArgs['vf']
Expand Down Expand Up @@ -36,7 +34,7 @@
import resources.lib.showAdd as showAdd
showAdd.action()
else:
util.log('invalid folder "' + vf + '"')
util.log('invalid action "' + action + '"')
else:
import resources.lib.main as main
main.menu()
Expand Down
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.program.sickrage"
name="SickRage"
version="1.0.0"
version="1.0.1"
provider-name="frdfsnlght">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
Expand Down
Binary file added resources/icons/quality.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/wanted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions resources/lib/episodeStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import xbmc
import xbmcgui

import util as util

showId = util.pluginArgs[0]
season = util.pluginArgs[1]
episode = util.pluginArgs[2]
currentStatus = util.pluginArgs[3].lower()

statuses = ['wanted', 'skipped', 'archived', 'ignored', 'failed']
statusList = []
for status in statuses:
statusList.append(('* ' if status == currentStatus else '') + status.title())
dialog = xbmcgui.Dialog()
statusIndex = dialog.select('Episode Status', statusList)
if not statusIndex == -1:
status = statuses[statusIndex]
if not status == currentStatus:
result = util.api.doEpisodeSetStatus(showId, season, episode, status)
if result['result'] == 'success':
xbmc.executebuiltin('Container.Refresh')

4 changes: 2 additions & 2 deletions resources/lib/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def menu():
thumbnailImage = thumbnailImage
)
listItem.addContextMenuItems([
('Set Episode Status', util.getContextCommand('episodeStatus', [showId, season, episodeNum])),
('Set Episode Status', util.getContextCommand('episodeStatus', [showId, season, episodeNum, episode['status']])),
('Set Season Status', util.getContextCommand('seasonStatus', [showId, season])),
('Manual Search', util.getContextCommand('episodeSearch', [showId, season, episodeNum])),
('Refresh list', util.getContextCommand('refresh'))
], True)
xbmcplugin.addDirectoryItem(
handle = util.pluginId,
url = '',
url = None,
listitem = listItem,
isFolder = False
)
Expand Down
1 change: 1 addition & 0 deletions resources/lib/failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def menu():
label = str(release['release'])
)
listItem.addContextMenuItems([
#('Delete', util.getContextCommand('failedDelete', [release['release']])),
('Refresh list', util.getContextCommand('refresh'))
], True)
xbmcplugin.addDirectoryItem(
Expand Down
14 changes: 14 additions & 0 deletions resources/lib/failedDelete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import xbmc
import xbmcgui

import util as util

dialog = xbmcgui.Dialog()
if dialog.yesno('Delete Failed Download', 'Delete this failed download?'):
# need API for failed deletion
release = util.pluginArgs[0]
util.log('TODO: delete ' + release)
#result = util.api.doDeleteFailed(release)
#if result['result'] == 'success':
#xbmc.executebuiltin('Container.Refresh')

26 changes: 20 additions & 6 deletions resources/lib/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import xbmcplugin
import xbmcgui
import urllib

import resources.lib.util as util

def menu():
util.xbmcAddDirectory('Shows', 'shows')
util.xbmcAddDirectory('Upcoming', 'upcoming')
util.xbmcAddDirectory('History', 'history')
util.xbmcAddDirectory('Backlog', 'backlog')
util.xbmcAddDirectory('Failed Downloads', 'failed')
util.xbmcEndDirectory()

def addDirectory(label, vf, params = {}):
params['vf'] = vf
url = util.pluginURL + '?' + urllib.urlencode(params)
listItem = xbmcgui.ListItem(label)
xbmcplugin.addDirectoryItem(
handle = util.pluginId,
url = url,
listitem = listItem,
isFolder = True
)

addDirectory('Shows', 'shows')
addDirectory('Upcoming', 'upcoming')
addDirectory('History', 'history')
addDirectory('Backlog', 'backlog')
addDirectory('Failed Downloads', 'failed')
xbmcplugin.endOfDirectory(util.pluginId)

20 changes: 20 additions & 0 deletions resources/lib/seasonStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import xbmc
import xbmcgui

import util as util

showId = util.pluginArgs[0]
season = util.pluginArgs[1]

statuses = ['wanted', 'skipped', 'archived', 'ignored', 'failed']
statusList = []
for status in statuses:
statusList.append(status.title())
dialog = xbmcgui.Dialog()
statusIndex = dialog.select('Season Status', statusList)
if not statusIndex == -1:
status = statuses[statusIndex]
result = util.api.doEpisodeSetStatus(showId, season, None, status)
if result['result'] == 'success':
xbmc.executebuiltin('Container.Refresh')

41 changes: 36 additions & 5 deletions resources/lib/showAdd.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
import xbmc
import xbmcgui

from operator import itemgetter

import util as util

def action():

# Search for a name
# Get the name

keyboard = xbmc.Keyboard('', 'Search for...', False)
keyboard.doModal()
if not keyboard.isConfirmed():
return
searchName = keyboard.getText()

matches = util.api.doSearch(searchName)
# Get indexer to use

indexers = ['All Indexers', 'theTVDB', 'TVRage']
dialog = xbmcgui.Dialog()
indexerIndex = dialog.select('Indexer to Search', indexers)
if indexerIndex == -1:
return

# Do the search

matches = util.api.doSearch(searchName, indexerIndex)
if not matches:
util.message('Search Results', 'No matching shows found.')
return

matchList = []
for show in matches:
matchList.append(show['name'] + ' - ' + util.formatDate(show['first_aired']))
if not indexerIndex == 0:
if not show['indexer'] == indexerIndex:
continue
indexer = ''
else:
if 'tvdbid' in show:
indexer = 'theTVDB'
elif 'tvrageid' in show:
indexer = 'TVRage'
else:
indexer = 'Unknown'
matchList.append(show['name'] + ' - ' + util.formatDate(show['first_aired']) + ' ' + indexer)
dialog = xbmcgui.Dialog()
matchIndex = dialog.select('Search Results', matchList)
if matchIndex == -1:
Expand Down Expand Up @@ -102,7 +125,15 @@ def action():

# Add the show!

result = util.api.doAddNewShow(show['tvdbid'], location, status, flattenFolders, anime, sceneNumbered, quality)
if 'tvdbid' in show:
indexerid = show['tvdbid']
indexer = 'tvdb'
elif 'tvrageid' in show:
indexerid = show['tvrageid']
indexer = 'tvrage'
else:
indexerid = None
result = util.api.doAddNewShow(indexerid, indexer, location, status, flattenFolders, anime, sceneNumbered, quality)
if result['result'] == 'success':
util.message('Add Show', 'The show has been added.', 'It may take a moment before it appears in the list.')
xbmc.executebuiltin('Container.Refresh')
Expand Down
3 changes: 3 additions & 0 deletions resources/lib/shows.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def menu():
label = 'Add show...',
thumbnailImage = util.getIcon('showAdd')
)
listItem.addContextMenuItems([
('Refresh list', util.getContextCommand('refresh'))
], True)
xbmcplugin.addDirectoryItem(
handle = util.pluginId,
url = url,
Expand Down
26 changes: 21 additions & 5 deletions resources/lib/sickrage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import util as util

socket.setdefaulttimeout(float(util.plugin.getSetting('timeout')))
socket.setdefaulttimeout(40)

class API:

Expand Down Expand Up @@ -79,8 +79,15 @@ def getFailed(self, params = {}):
def doForceSearch(self):
return self.request('sb.forcesearch')

def doSearch(self, name):
result = self.request('sb.searchtvdb', {'name': name})
def doSearch(self, name, indexer):
if indexer == 0:
result = self.request('sb.searchindexers', {'name': name})
elif indexer == 1:
result = self.request('sb.searchtvdb', {'name': name})
elif indexer == 2:
result = self.request('sb.searchtvrage', {'name': name})
else:
return []
return result['data']['results']

def getRootDirs(self):
Expand All @@ -91,14 +98,23 @@ def getDefaults(self):
result = self.request('sb.getdefaults')
return result['data']

def doAddNewShow(self, id, location, status, flattenFolders, anime, sceneNumbered, quality):
def doAddNewShow(self, id, indexer, location, status, flattenFolders, anime, sceneNumbered, quality):
return self.request('show.addnew', {
'tvdbid': id,
'indexerid': id,
indexer + 'id': id,
'location': location,
'status': status,
'flatten_folders': 0 if flattenFolders else 1,
'anime': 1 if anime else 0,
'scene': 1 if sceneNumbered else 0,
'initial': quality
})

def doEpisodeSetStatus(self, id, season, episode, status):
return self.request('episode.setstatus', {
'indexerid': id,
'season': season,
'episode': episode,
'status': status
})

35 changes: 18 additions & 17 deletions resources/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,9 @@ def getActionURL(action, params = {}):
url = pluginURL + '?' + urllib.urlencode(params)
return url

def xbmcAddDirectory(label, vf, params = {}):
params['vf'] = vf
url = pluginURL + '?' + urllib.urlencode(params)
listItem = xbmcgui.ListItem(label)
xbmcplugin.addDirectoryItem(handle = pluginId, url = url, listitem = listItem, isFolder = True)

def xbmcEndDirectory():
xbmcplugin.endOfDirectory(pluginId)

def getArguments():
if len(sys.argv) < 3:
def getKWArguments(argv):
if not argv:
return {}
argv = sys.argv[2]
if argv.startswith('?'):
argv = argv[1:]
#log('argv is now ' + argv)
Expand Down Expand Up @@ -121,15 +111,26 @@ def formatEpisodeName(show):
out = out + ' - ' + show['ep_name']
return out

log(sys.argv)

def isInt(s):
try:
int(s)
return True
except ValueError:
return False

pluginURL = sys.argv[0]
pluginId = int(sys.argv[1])
pluginArgs = getArguments()
if pluginURL.endswith('.py'):
pluginId = None
pluginArgs = sys.argv[1:]
else:
pluginId = int(sys.argv[1])
pluginArgs = getKWArguments(sys.argv[2])

api = sickrage.API()
iconDir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'icons')

log(sys.argv)
#log('iconDir: ' + iconDir)
#log('pluginURL: ' + pluginURL)
#log('pluginId: ' + str(pluginId))
#log(pluginArgs)
log(pluginArgs)

0 comments on commit 9058a80

Please sign in to comment.