Skip to content

Commit

Permalink
Support multiple files per Episode (#191);
Browse files Browse the repository at this point in the history
Added 'Inspect files' to context menu;
Added 'unused' string-ids;
Updated changelog;
  • Loading branch information
bigretromike committed Feb 6, 2017
1 parent 7ca796b commit ec3b4ed
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 18 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ v2.1.0 ()
- Disable gzip on localhost (#161)
- Episodes sort if fixed for webinterface (#176)
- Proper handle error with network error (#187)
- Support multiple files per Episode (#191)
- Added 'Inspect files' context menu

v2.0.22 (02/02/2017)
- fix years/tags (sorry ;-) )
- fix grouped series
- moving to proper api url
- fixing missing subtitle stream index

v2.0.19 (18/01/2017)
- Adding "Trigger Voting after each episode"
Expand Down
59 changes: 47 additions & 12 deletions nakamori.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import datetime as datetime
import json
import os

import resources.lib.TagBlacklist as TagFilter
import resources.lib.util as util
Expand Down Expand Up @@ -393,6 +394,8 @@ def add_gui_item(url, details, extra_data, context=None, folder=True, index=0):

if __addon__.getSetting('context_show_play_no_watch') == 'true':
context.append(('Play (Do not Mark as Watched)', 'RunScript(plugin.video.nakamori, %s, %s&cmd=no_mark)' % (sys.argv[1], url_peep)))
if __addon__.getSetting('context_pick_file') == 'true':
context.append(('Inspect files', 'RunScript(plugin.video.nakamori, %s, %s&cmd=pickFile)' % (sys.argv[1], url_peep)))
if __addon__.getSetting('context_show_info') == 'true':
context.append(('More Info', 'Action(Info)'))

Expand Down Expand Up @@ -1421,11 +1424,10 @@ def build_network_menu():


# Other functions
def play_video(url, ep_id, raw_id, movie):
def play_video(ep_id, raw_id, movie):
"""
Plays a file or episode
Args:
url: location of the file
ep_id: episode id, if applicable for watched status and stream details
raw_id: file id, that is only used when ep_id = 0
movie: determinate if played object is movie or episode (ex.Trakt)
Expand All @@ -1450,9 +1452,8 @@ def play_video(url, ep_id, raw_id, movie):
'season': xbmc.getInfoLabel('ListItem.Season')
}

item = xbmcgui.ListItem(details.get('title', 'Unknown'), thumbnailImage=xbmc.getInfoLabel('ListItem.Thumb'), path=url)
item.setInfo(type='Video', infoLabels=details)
item.setProperty('IsPlayable', 'true')
file_url = ''

try:
if ep_id != "0":
episode_url = _server_ + "/api/ep?id=" + str(ep_id)
Expand All @@ -1461,14 +1462,23 @@ def play_video(url, ep_id, raw_id, movie):
if __addon__.getSetting("spamLog") == "true":
xbmc.log(html, xbmc.LOGWARNING)
episode_body = json.loads(html)
# extract extra data about file from episode
file_id = episode_body["files"][0]["id"]
if __addon__.getSetting("pick_file") == "true":
file_id = file_list_gui(episode_body)
else:
file_id = episode_body["files"][0]["id"]
else:
file_id = raw_id

if file_id is not None and file_id != 0:
file_url = _server_ + "/api/file?id=" + str(file_id)
file_body = json.loads(get_json(file_url))


file_url = file_body['url']

item = xbmcgui.ListItem(details.get('title', 'Unknown'), thumbnailImage=xbmc.getInfoLabel('ListItem.Thumb'), path=file_url)
item.setInfo(type='Video', infoLabels=details)
item.setProperty('IsPlayable', 'true')

# Information about streams inside video file
# Video
codecs = dict()
Expand All @@ -1479,18 +1489,18 @@ def play_video(url, ep_id, raw_id, movie):
item.addStreamInfo('audio', codecs["AudioStreams"])
item.addStreamInfo('subtitle', codecs["SubStreams"])
else:
# error
error("Unknown Stream Type Received!")
error("file_id not retrieved")
except Exception as exc:
error('Error getting episode info', str(exc))

player = xbmc.Player()

try:
player.play(item=url, listitem=item, windowed=False)
player.play(item=file_url, listitem=item, windowed=False)
xbmcplugin.setResolvedUrl(handle, True, item)
except:
pass

# wait for player (network issue etc)
xbmc.sleep(1000)
mark = float(__addon__.getSetting("watched_mark"))
Expand Down Expand Up @@ -1624,6 +1634,26 @@ def vote_episode(params):
xbmc.executebuiltin("XBMC.Notification(%s, %s %s, 7500, %s)" % ('Episode voting', 'You voted', vote_value, __addon__.getAddonInfo('icon')))


def file_list_gui(ep_body):
pick_filename = ['Cancel']
get_fileid = ['0']
if len(ep_body['files']) > 1:
for body in ep_body['files']:
filename = os.path.basename(body['filename'])
pick_filename.append(filename)
get_fileid.append(str(body['id']))
my_file = xbmcgui.Dialog().select('Files', pick_filename)
if my_file > 0:
return get_fileid[my_file]
else:
# cancel -1,0
return 0
elif len(ep_body['files']) == 1:
return ep_body['files'][0]['id']
else:
return 0


def watched_mark(params):
"""
Marks an episode, series, or group as either watched or unwatched
Expand Down Expand Up @@ -1787,6 +1817,11 @@ def remove_missing_files():
elif cmd == "no_mark":
__addon__.setSetting('no_mark', '1')
xbmc.executebuiltin('Action(Select)')
elif cmd == "pickFile":
xbmcgui.Dialog().ok("par", str(parameters))
if str(parameters['ep_id']) != "0":
ep_url = _server_ + "/api/ep?id=" + str(parameters['ep_id']) + "&level=2"
file_list_gui(json.loads(get_json(ep_url)))
elif cmd == 'rescan':
rescan_file(parameters, True)
elif cmd == 'rehash':
Expand All @@ -1799,7 +1834,7 @@ def remove_missing_files():
try:
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
ctl = win.getControl(win.getFocusId())
if play_video(parameters['file'], parameters['ep_id'], parameters['raw_id'] if 'raw_id' in parameters else "0", parameters['movie'] if 'movie' in parameters else 0) != 0:
if play_video(parameters['ep_id'], parameters['raw_id'] if 'raw_id' in parameters else "0", parameters['movie'] if 'movie' in parameters else 0) != 0:
# noinspection PyTypeChecker
ui_index = parameters.get('ui_index', '')
if ui_index != '':
Expand Down
39 changes: 33 additions & 6 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Kodi Media Center language file
# Addon Name: Nakamori
# Addon id: plugin.video.nakamoriplugin
# Addon id: plugin.video.nakamori
# Addon Provider: BigRetroMike
msgid ""
msgstr ""
"Project-Id-Version: Kodi Addons\n"
"Report-Msgid-Bugs-To: bigretromike at gmail dot com\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -56,10 +55,18 @@ msgctxt "#30011"
msgid "Shoko User"
msgstr ""

msgctxt "#30012"
msgid "Inspect files"
msgstr ""

msgctxt "#30013"
msgid "Use gzip"
msgstr ""

msgctxt "#30014"
msgid "Enable 'Pick file' on multi files episodes"
msgstr ""

msgctxt "#30015"
msgid "Login"
msgstr ""
Expand All @@ -76,6 +83,14 @@ msgctxt "#30018"
msgid "API Key"
msgstr ""

msgctxt "#30019"
msgid "UNUSED"
msgstr ""

msgctxt "#30020"
msgid "UNUSED"
msgstr ""

msgctxt "#30021"
msgid "Searching"
msgstr ""
Expand Down Expand Up @@ -104,6 +119,18 @@ msgctxt "#30027"
msgid "Max time to wait for buffer (in ms)"
msgstr ""

msgctxt "#30028"
msgid "UNUSED"
msgstr ""

msgctxt "#30029"
msgid "UNUSED"
msgstr ""

msgctxt "#30030"
msgid "UNUSED"
msgstr ""

msgctxt "#30031"
msgid "Community"
msgstr ""
Expand All @@ -116,10 +143,6 @@ msgctxt "#30033"
msgid "TAG results Max Limit"
msgstr ""

msgctxt "#30038"
msgid "Trakt support"
msgstr ""

msgctxt "#30034"
msgid "(WIP)Series Vote after completing it"
msgstr ""
Expand All @@ -136,6 +159,10 @@ msgctxt "#30037"
msgid "Enable Trakt Scrobble Notification"
msgstr ""

msgctxt "#30038"
msgid "Trakt support"
msgstr ""

msgctxt "#30039"
msgid "Show -continue-"
msgstr ""
Expand Down
2 changes: 2 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
<setting label="30060" type="bool" id="context_show_vote_Series" default="true" />
<setting label="30061" type="bool" id="context_show_play_no_watch" default="true" />
<setting label="30062" type="bool" id="context_krypton_watched" default="true" />
<setting label="30012" type="bool" id="context_pick_file" default="true" />
</category>
<category label="30023">
<setting label="30007" type="lsep"/>
<setting label="30025" type="bool" id="watchedbox" default="true"/>
<setting label="30024" type="number" id="watched_mark" default="80"/>
<setting label="30055" type="number" id="refresh_wait" default="1000"/>
<setting label="30005" type="bool" id="syncwatched" default="true"/>
<setting label="30014" type="bool" id="pick_file" default="true"/>
<setting label="30026" type="lsep"/>
<setting label="30027" type="number" id="player_sleep" default="5000"/>
</category>
Expand Down

0 comments on commit ec3b4ed

Please sign in to comment.