Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 540b59e1243dbc1068a55abf7b35b99ebe768980 @MartijnKaijser MartijnKaijser committed Oct 10, 2012
Showing with 847 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +282 −0 LICENSE.txt
  3. +5 −0 README.txt
  4. +17 −0 addon.xml
  5. +2 −0 changelog.txt
  6. +517 −0 default.py
  7. 0 resources/__init__.py
  8. +8 −0 resources/language/English/strings.xml
  9. +12 −0 resources/settings.xml
4 .gitignore
@@ -0,0 +1,4 @@
+*.pyo
+.project
+.pydevproject
+pysrc
282 LICENSE.txt
@@ -0,0 +1,282 @@
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+-------------------------------------------------------------------------
5 README.txt
@@ -0,0 +1,5 @@
+INFORMATION FOR SKINNERS
+------------------------
+
+http://wiki.xbmc.org/index.php?title=Add-on:Skin_Widgets
+
17 addon.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<addon id="service.skin.widgets" name="Skin Widgets" version="0.0.1" provider-name="Martijn">
+ <requires>
+ <import addon="xbmc.addon" version="11.9.7"/>
+ <import addon="xbmc.python" version="2.1"/>
+ <import addon="script.module.simplejson" version="2.0.10"/>
+ </requires>
+ <extension point="xbmc.python.script" library="default.py">
+ <provides>executable</provides>
+ </extension>
+ <extension point="xbmc.service" library="default.py" start="login"/>
+ <extension point="xbmc.addon.metadata">
+ <summary lang="en">Skin widgets</summary>
+ <description lang="en">Skin widgets</description>
+ <platform>all</platform>
+ </extension>
+</addon>
2 changelog.txt
@@ -0,0 +1,2 @@
+v12.0.0
+- Integrate Watchlist and RandomItems into one widget service
517 default.py
@@ -0,0 +1,517 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 Team-XBMC
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# This script is based on script.randomitems & script.wacthlist
+# Thanks to their original authors
+
+import os
+import sys
+import xbmc
+import xbmcgui
+import xbmcaddon
+import random
+import datetime
+import _strptime
+
+if sys.version_info < (2, 7):
+ import simplejson
+else:
+ import json as simplejson
+
+__addon__ = xbmcaddon.Addon()
+__addonversion__ = __addon__.getAddonInfo('version')
+__addonid__ = __addon__.getAddonInfo('id')
+__addonname__ = __addon__.getAddonInfo('name')
+
+def log(txt):
+ message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore'))
+ xbmc.log(msg=message, level=xbmc.LOGDEBUG)
+
+class Main:
+ def __init__(self):
+ self._parse_argv()
+ self._init_vars()
+ self._init_property()
+ # check how we were executed
+ if self.ALBUMID:
+ xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "albumid": %d } }, "id": 1 }' % int(self.ALBUMID))
+ else:
+ # clear our property, if another instance is already running it should stop now
+ self.WINDOW.clearProperty('SkinWidgets_Running')
+ a_total = datetime.datetime.now()
+ self._fetch_info_randomitems()
+ self._fetch_info_recommended()
+ b_total = datetime.datetime.now()
+ c_total = b_total - a_total
+ log('Total time needed for all queries: %s' % c_total)
+ # give a possible other instance some time to notice the empty property
+ self.WINDOW.setProperty('SkinWidgets_Running', 'true')
+ self._daemon()
+
+ def _init_vars(self):
+ self.WINDOW = xbmcgui.Window(10000)
+ self.Player = MyPlayer(action = self._update)
+ self.Monitor = MyMonitor(update_listitems = self._update, update_settings = self._init_property)
+ self.LIMIT = 20
+
+ def _init_property(self):
+ self.WINDOW.setProperty('SkinWidgets_Recommended', '%s' % __addon__.getSetting("recommended_enable"))
+ self.WINDOW.setProperty('SkinWidgets_RandomItems', '%s' % __addon__.getSetting("randomitems_enable"))
+
+ def _parse_argv( self ):
+ try:
+ params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( "&" ) )
+ except:
+ params = {}
+ self.ALBUMID = params.get( "albumid", "" )
+
+ def _fetch_info_recommended(self):
+ a = datetime.datetime.now()
+ '''
+ clear = ['recommendedMovie',
+ 'recommendedEpisode',
+ 'recommendedMusicVideo',
+ 'recommendedAlbum']
+ for item in clear:
+ self._clear_properties(item)
+ '''
+ if __addon__.getSetting("recommended_enable") == 'true':
+ self._fetch_movies('RecommendedMovie')
+ self._fetch_tvshows_recommended('RecommendedEpisode')
+ self._fetch_albums('RecommendedAlbum')
+ self._fetch_musicvideo('RecommendedMusicVideo')
+ b = datetime.datetime.now()
+ c = b - a
+ log('Total time needed to request recommended queries: %s' % c)
+
+ def _fetch_info_randomitems(self):
+ a = datetime.datetime.now()
+ '''
+ clear = ['RandomMovie',
+ 'RandomEpisode',
+ 'RandomMusicVideo',
+ 'RandomAlbum',
+ 'RandomArtist',
+ 'RandomSong',
+ 'RandomAddon']
+ for item in clear:
+ self._clear_properties(item)
+ '''
+ self.RANDOMITEMS_UNPLAYED = __addon__.getSetting("randomitems_unplayed") == 'true'
+ if __addon__.getSetting("randomitems_enable") == 'true':
+ self._fetch_movies('RandomMovie')
+ self._fetch_tvshows_randomitems('RandomEpisode')
+ self._fetch_musicvideo('RandomMusicVideo')
+ self._fetch_albums('RandomAlbum')
+ self._fetch_artist('RandomArtist')
+ self._fetch_song('RandomSong')
+ self._fetch_addon('RandomAddon')
+ b = datetime.datetime.now()
+ c = b - a
+ log('Total time needed to request random queries: %s' % c)
+
+ def _fetch_movies(self, request):
+ if request == 'recommendedMovie':
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "playcount", "year", "genre", "studio", "tagline", "plot", "runtime", "fanart", "thumbnail", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume"], "sort": { "order": "descending", "method": "lastplayed" }, "limits": {"end": %d}}, "id": 1}, "filter": {"field": "inprogress", "operator": "true", "value": ""}' %self.LIMIT)
+ elif self.RANDOMITEMS_UNPLAYED:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "playcount", "year", "genre", "studio", "tagline", "plot", "runtime", "fanart", "thumbnail", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume"], "sort": {"method": "random" }, "limits": {"end": %d} }, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}, "id": 1}' %self.LIMIT)
+ else:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "playcount", "year", "genre", "studio", "tagline", "plot", "runtime", "fanart", "thumbnail", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume"], "sort": {"method": "random" }, "limits": {"end": %d} }, "id": 1}' %self.LIMIT)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
+ json_response = simplejson.loads(json_query)
+ if json_response['result'].has_key('movies'):
+ self._clear_properties(request)
+ count = 0
+ for item in json_response['result']['movies']:
+ count += 1
+ if item['resume']['position'] > 0:
+ resume = "true"
+ percentage = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
+ else:
+ resume = "false"
+ percentage = '0%'
+ path = media_path(item['file'])
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
+ self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
+ self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
+ self.WINDOW.setProperty("%s.%d.Studio" % (request, count), item['studio'][0])
+ self.WINDOW.setProperty("%s.%d.Plot" % (request, count), item['plot'])
+ self.WINDOW.setProperty("%s.%d.PlotOutline" % (request, count), item['plotoutline'])
+ self.WINDOW.setProperty("%s.%d.Tagline" % (request, count), item['tagline'])
+ self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), item['runtime'])
+ self.WINDOW.setProperty("%s.%d.Rating" % (request, count), str(round(float(item['rating']),1)))
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Logo" % (request, count), xbmc.validatePath(os.path.join(path, 'logo.png')))
+ self.WINDOW.setProperty("%s.%d.Landscape" % (request, count), xbmc.validatePath(os.path.join(path, 'landscape.png')))
+ self.WINDOW.setProperty("%s.%d.Banner" % (request, count), xbmc.validatePath(os.path.join(path, 'banner.png')))
+ self.WINDOW.setProperty("%s.%d.Disc" % (request, count), xbmc.validatePath(os.path.join(path, 'disc.png')))
+ self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
+ self.WINDOW.setProperty("%s.%d.Percentage" % (request, count), percentage)
+ self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
+ self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
+
+ def _fetch_tvshows_recommended(self, request):
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "studio", "thumbnail", "file"], "sort": {"order": "descending", "method": "lastplayed"}, "filter": {"field": "inprogress", "operator": "true", "value": ""}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
+ json_response = simplejson.loads(json_query)
+ if json_response['result'].has_key('tvshows'):
+ self._clear_properties(request)
+ count = 0
+ for item in json_response['result']['tvshows']:
+ count += 1
+ json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "thumbnail", "fanart", "file", "lastplayed", "rating", "resume"], "sort": {"method": "episode"}, "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": {"end": 1}}, "id": 1}' %item['tvshowid'])
+ json_query2 = unicode(json_query2, 'utf-8', errors='ignore')
+ json_response2 = simplejson.loads(json_query2)
+ if json_response2.has_key('result') and json_response2['result'] != None and json_response2['result'].has_key('episodes'):
+ for item2 in json_response2['result']['episodes']:
+ episode = ("%.2d" % float(item2['episode']))
+ season = "%.2d" % float(item2['season'])
+ rating = str(round(float(item2['rating']),1))
+ episodeno = "s%se%s" %(season,episode)
+ seasonthumb = ''
+ if item2['resume']['position'] > 0:
+ resume = "true"
+ percentage = '%s%%'%int((float(item2['resume']['position']) / float(item2['resume']['total'])) * 100)
+ else:
+ resume = "false"
+ percentage = '0%'
+ path = media_path(item['file'])
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item2['title'])
+ self.WINDOW.setProperty("%s.%d.Episode" % (request, count), episode)
+ self.WINDOW.setProperty("%s.%d.EpisodeNo" % (request, count), episodeno)
+ self.WINDOW.setProperty("%s.%d.Season" % (request, count), season)
+ self.WINDOW.setProperty("%s.%d.Plot" % (request, count), item2['plot'])
+ self.WINDOW.setProperty("%s.%d.TVshowTitle" % (request, count), item2['showtitle'])
+ self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item2['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item2['fanart'])
+ self.WINDOW.setProperty("%s.%d.Poster" % (request, count), xbmc.validatePath(os.path.join(path, 'poster.jpg')))
+ self.WINDOW.setProperty("%s.%d.Banner" % (request, count), xbmc.validatePath(os.path.join(path, 'banner.jpg')))
+ self.WINDOW.setProperty("%s.%d.Logo" % (request, count), xbmc.validatePath(os.path.join(path, 'logo.png')))
+ self.WINDOW.setProperty("%s.%d.Clearart" % (request, count), xbmc.validatePath(os.path.join(path, 'clearart.png')))
+ self.WINDOW.setProperty("%s.%d.Studio" % (request, count), item['studio'][0])
+ self.WINDOW.setProperty("%s.%d.TvshowThumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.SeasonThumb" % (request, count), seasonthumb)
+ self.WINDOW.setProperty("%s.%d.IsResumable" % (request, count), resume)
+ self.WINDOW.setProperty("%s.%d.Percentage" % (request, count), percentage)
+ self.WINDOW.setProperty("%s.%d.File" % (request, count), item2['file'])
+ self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
+
+ def _fetch_tvshows_randomitems(self, request):
+ season_folders = __addon__.getSetting("randomitems_seasonfolders")
+ if self.RANDOMITEMS_UNPLAYED:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "properties": ["title", "playcount", "season", "episode", "showtitle", "plot", "fanart", "thumbnail", "file", "rating", "resume", "tvshowid"], "sort": {"method": "random" }, "limits": {"end": %d}, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"} }, "id": 1}' %self.LIMIT)
+ else:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "properties": ["title", "playcount", "season", "episode", "showtitle", "plot", "fanart", "thumbnail", "file", "rating", "resume", "tvshowid"], "sort": {"method": "random" }, "limits": {"end": %d} }, "id": 1}' %self.LIMIT)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
+ json_response = simplejson.loads(json_query)
+ if json_response['result'].has_key('episodes'):
+ self._clear_properties(request)
+ count = 0
+ for item in json_response['result']['episodes']:
+ count += 1
+ '''
+ # This part is commented out because it takes 1.5second extra on my system to request these which doubles the total time.
+ # Hence the ugly path hack that will require users to have season folders.
+ json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShowDetails", "params": {"properties": ["file", "studio"], "tvshowid":%s}, "id": 1}' %item['tvshowid'])
+ json_query2 = unicode(json_query2, 'utf-8', errors='ignore')
+ json_response2 = simplejson.loads(json_query2)
+ path = json_response2['result']['tvshowdetails']['file']
+ studio = json_response2['result']['tvshowdetails']['studio'][0]
+ '''
+ if season_folders == 'true':
+ path = os.path.split(media_path(item['file']))[0]
+ else:
+ path = media_path(item['file'])
+ episode = ("%.2d" % float(item['episode']))
+ season = "%.2d" % float(item['season'])
+ episodeno = "s%se%s" %(season,episode)
+ seasonthumb = ''
+ resumable = "True"
+ rating = str(round(float(item['rating']),1))
+ if item['resume']['position'] > 0:
+ resume = "true"
+ percentage = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
+ else:
+ resume = "false"
+ percentage = '0%'
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
+ self.WINDOW.setProperty("%s.%d.Episode" % (request, count), episode)
+ self.WINDOW.setProperty("%s.%d.EpisodeNo" % (request, count), episodeno)
+ self.WINDOW.setProperty("%s.%d.Season" % (request, count), season)
+ self.WINDOW.setProperty("%s.%d.Plot" % (request, count), item['plot'])
+ self.WINDOW.setProperty("%s.%d.TVshowTitle" % (request, count), item['showtitle'])
+ self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Poster" % (request, count), xbmc.validatePath(os.path.join(path, 'poster.jpg')))
+ self.WINDOW.setProperty("%s.%d.Banner" % (request, count), xbmc.validatePath(os.path.join(path, 'banner.jpg')))
+ self.WINDOW.setProperty("%s.%d.Logo" % (request, count), xbmc.validatePath(os.path.join(path, 'logo.png')))
+ self.WINDOW.setProperty("%s.%d.Clearart" % (request, count), xbmc.validatePath(os.path.join(path, 'clearart.png')))
+ # Requires extra JSON-RPC request, see commented out part
+ #self.WINDOW.setProperty("%s.%d.Studio" % (request, count), studio)
+ self.WINDOW.setProperty("%s.%d.TVShowThumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.SeasonThumb" % (request, count), seasonthumb)
+ self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
+ self.WINDOW.setProperty("%s.%d.Percentage" % (request, count), percentage)
+ self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
+ self.WINDOW.setProperty("%s.%d.Path" % (request, count), path) still need to look at this
+
+ def _fetch_seasonthumb(self, tvshowid, seasonnumber):
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season", "thumbnail"], "tvshowid":%s }, "id": 1}' % tvshowid)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
+ json_response = simplejson.loads(json_query)
+ if json_response['result'].has_key('seasons'):
+ for item in json_response['result']['seasons']:
+ season = "%.2d" % float(item['season'])
+ if season == seasonnumber:
+ thumbnail = item['thumbnail']
+ return thumbnail
+
+ def _fetch_musicvideo(self, request):
+ if request == 'RecommendedEpisode':
+ pass
+ elif self.RANDOMITEMS_UNPLAYED:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["title", "artist", "playcount", "year", "plot", "runtime", "fanart", "thumbnail", "file"], "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}, "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ else:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["title", "artist", "playcount", "year", "plot", "runtime", "fanart", "thumbnail", "file"], "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
+ json_response = simplejson.loads(json_query)
+ if json_response['result'].has_key('musicvideos'):
+ self._clear_properties(request)
+ count = 0
+ for item in json_response['result']['musicvideos']:
+ count += 1
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
+ self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
+ self.WINDOW.setProperty("%s.%d.Plot" % (request, count), item['plot'])
+ self.WINDOW.setProperty("%s.%d.RunningTime" % (request, count), item['runtime'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
+
+ def _fetch_albums(self, request):
+ if request == 'RecommendedAlbum':
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "description", "albumlabel", "artist", "genre", "year", "thumbnail", "fanart", "rating", "playcount"], "sort": {"order": "descending", "method": "playcount" }, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ elif self.RANDOMITEMS_UNPLAYED:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "description", "albumlabel", "artist", "genre", "year", "thumbnail", "fanart", "rating", "playcount"], "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}, "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ else:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["title", "description", "albumlabel", "artist", "genre", "year", "thumbnail", "fanart", "rating", "playcount"], "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ json_response = unicode(json_query, 'utf-8', errors='ignore')
+ jsonobject = simplejson.loads(json_response)
+ if jsonobject['result'].has_key('albums'):
+ self._clear_properties(request)
+ count = 0
+ for item in jsonobject['result']['albums']:
+ count += 1
+ rating = str(item['rating'])
+ if rating == '48':
+ rating = ''
+ path = 'XBMC.RunScript(' + __addonid__ + ',albumid=' + str(item.get('albumid')) + ')'
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
+ self.WINDOW.setProperty("%s.%d.Label" % (request, count), item['title']) #needs to be removed
+ self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
+ self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
+ self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
+ self.WINDOW.setProperty("%s.%d.RecordLabel" % (request, count), item['albumlabel'])
+ self.WINDOW.setProperty("%s.%d.Description" % (request, count), item['description'])
+ self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Play" % (request, count), path)
+
+ def _fetch_artist(self, request):
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": {"properties": ["genre", "description", "fanart", "thumbnail"], "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ json_response = unicode(json_query, 'utf-8', errors='ignore')
+ jsonobject = simplejson.loads(json_response)
+ if jsonobject['result'].has_key('artists'):
+ self._clear_properties(request)
+ count = 0
+ for item in jsonobject['result']['artists']:
+ count += 1
+ path = 'musicdb://2/' + str(item['artistid']) + '/'
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['label'])
+ self.WINDOW.setProperty("%s.%d.Genre" % (request, count), " / ".join(item['genre']))
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Description" % (request, count), item['description'])
+ self.WINDOW.setProperty("%s.%d.LibraryPath" % (request, count), path)
+
+ def _fetch_song(self, request):
+ if self.RANDOMITEMS_UNPLAYED == "True":
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": {"properties": ["title", "playcount", "artist", "album", "year", "file", "thumbnail", "fanart", "rating"], "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}, "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ else:
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": {"properties": ["title", "playcount", "artist", "album", "year", "file", "thumbnail", "fanart", "rating"], "sort": {"method": "random"}, "limits": {"end": %d}}, "id": 1}' %self.LIMIT)
+ json_response = unicode(json_query, 'utf-8', errors='ignore')
+ jsonobject = simplejson.loads(json_response)
+ if jsonobject['result'].has_key('songs'):
+ self._clear_properties(request)
+ count = 0
+ for item in jsonobject['result']['songs']:
+ count += 1
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
+ self.WINDOW.setProperty("%s.%d.Artist" % (request, count), " / ".join(item['artist']))
+ self.WINDOW.setProperty("%s.%d.Year" % (request, count), str(item['year']))
+ self.WINDOW.setProperty("%s.%d.Rating" % (request, count), str(int(item['rating'])-48))
+ self.WINDOW.setProperty("%s.%d.Album" % (request, count), item['album'])
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
+
+ def _fetch_addon(self, request):
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Addons.GetAddons", "params": {"properties": ["name", "author", "summary", "version", "fanart", "thumbnail"]}, "id": 1}')
+ json_response = unicode(json_query, 'utf-8', errors='ignore')
+ jsonobject = simplejson.loads(json_response)
+ if jsonobject['result'].has_key('addons'):
+ # find plugins and scripts
+ addonlist = []
+ for item in jsonobject['result']['addons']:
+ if item['type'] == 'xbmc.python.script' or item['type'] == 'xbmc.python.pluginsource':
+ addonlist.append(item)
+ # randomize the list
+ random.shuffle(addonlist)
+ self._clear_properties(request)
+ count = 0
+ for item in addonlist:
+ count += 1
+ self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['name'])
+ self.WINDOW.setProperty("%s.%d.Author" % (request, count), item['author'])
+ self.WINDOW.setProperty("%s.%d.Summary" % (request, count), item['summary'])
+ self.WINDOW.setProperty("%s.%d.Version" % (request, count), item['version'])
+ self.WINDOW.setProperty("%s.%d.Path" % (request, count), item['addonid'])
+ self.WINDOW.setProperty("%s.%d.Fanart" % (request, count), item['fanart'])
+ self.WINDOW.setProperty("%s.%d.Thumb" % (request, count), item['thumbnail'])
+ self.WINDOW.setProperty("%s.%d.Type" % (request, count), item['type'])
+ # stop if we've reached the number of items we need
+ if count == self.LIMIT:
+ break
+
+ def _daemon(self):
+ updatetime = int(__addon__.getSetting("randomitems_time").rstrip('0').rstrip('.')) * 60 # tijd in seconden
+ count = 0
+ while (not xbmc.abortRequested) and self.WINDOW.getProperty('SkinWidgets_Running') == 'true':
+ xbmc.sleep(1000)
+ count += 1
+ if count == updatetime:
+ self._fetch_info_randomitems()
+ count = 0 # reset counter
+
+ def _clear_properties(self, request):
+ count = 0
+ for count in range(int(self.LIMIT)):
+ count += 1
+ self.WINDOW.clearProperty("%s.%d.Titel" % (request, count))
+
+ def _update(self, type):
+ xbmc.sleep(500)
+ if type == 'movie':
+ self._fetch_movies('RecommendedMovie')
+ elif type == 'episode':
+ self._fetch_tvshows_recommended('RecommendedEpisode')
+ elif type == 'video':
+ self._fetch_movies('RecommendedMovie')
+ self._fetch_tvshows_recommended('RecommendedEpisode')
+ elif type == 'album':
+ self._fetch_albums('RecommendedAlbum')
+
+def media_path(path):
+ # Check for stacked movies
+ try:
+ path = os.path.split(path)[0].rsplit(' , ', 1)[1].replace(",,",",")
+ except:
+ path = os.path.split(path)[0]
+ # Fixes problems with rared movies and multipath
+ if path.startswith("rar://"):
+ path = [os.path.split(urllib.url2pathname(path.replace("rar://","")))[0]]
+ elif path.startswith("multipath://"):
+ temp_path = path.replace("multipath://","").split('%2f/')
+ path = []
+ for item in temp_path:
+ path.append(urllib.url2pathname(item))
+ else:
+ path = [path]
+ return path[0]
+
+class MyMonitor(xbmc.Monitor):
+ def __init__(self, *args, **kwargs):
+ xbmc.Monitor.__init__(self)
+ self.update_listitems = kwargs['update_listitems']
+ self.update_settings = kwargs['update_settings']
+
+ def onDatabaseUpdated(self, database):
+ self.update_listitems(database)
+
+ def onSettingsChanged(self):
+ self.update_settings()
+
+class MyPlayer(xbmc.Player):
+ def __init__(self, *args, **kwargs):
+ xbmc.Player.__init__(self)
+ self.action = kwargs[ "action" ]
+ self.substrings = [ '-trailer', 'http://' ]
+
+ def onPlayBackStarted(self):
+ xbmc.sleep(1000)
+ self.type = ""
+ # Set values based on the file content
+ if (self.isPlayingAudio()):
+ self.type = "album"
+ else:
+ if xbmc.getCondVisibility('VideoPlayer.Content(movies)'):
+ filename = ''
+ isMovie = True
+ try:
+ filename = self.getPlayingFile()
+ except:
+ pass
+ if filename != '':
+ for string in self.substrings:
+ if string in filename:
+ isMovie = False
+ break
+ if isMovie:
+ self.type = "movie"
+ elif xbmc.getCondVisibility('VideoPlayer.Content(episodes)'):
+ # Check for tv show title and season to make sure it's really an episode
+ if xbmc.getInfoLabel('VideoPlayer.Season') != "" and xbmc.getInfoLabel('VideoPlayer.TVShowTitle') != "":
+ self.type = "episode"
+
+ def onPlayBackEnded(self):
+ if self.type == 'movie':
+ self.action('movie')
+ elif self.type == 'episode':
+ self.action('episode')
+ elif self.type == 'album':
+ self.action('album')
+ self.type = ""
+
+
+ def onPlayBackStopped(self):
+ if self.type == 'movie':
+ self.action('movie')
+ elif self.type == 'episode':
+ self.action('episode')
+ elif self.type == 'album':
+ self.action('album')
+ self.type = ""
+
+if (__name__ == "__main__"):
+ log('script version %s started' % __addonversion__)
+ Main()
0 resources/__init__.py
No changes.
8 resources/language/English/strings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<strings>
+ <string id="32001">Recommended</string>
+ <string id="32002">Random Items</string>
+ <string id="32003">Only unplayed</string>
+ <string id="32004">Randomize time (minutes)</string>
+ <string id="32005">Use season folders</string>
+</strings>
12 resources/settings.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<settings>
+ <category label="Recommended">
+ <setting label="32001" type="bool" id="recommended_enable" default="true"/>
+ </category>
+ <category label="Randomitems">
+ <setting label="32002" type="bool" id="randomitems_enable" default="true"/>
+ <setting label="32003" type="bool" id="randomitems_unplayed" subsetting="true" default="true" enable="eq(-1,true)"/>
+ <setting label="32005" type="bool" id="randomitems_seasonfolders" subsetting="true" default="true" enable="eq(-2,true)"/>
+ <setting label="32004" type="slider" id="randomitems_time" subsetting="true" enable="eq(-3,true)" default="1" range="10,10,60" option="int"/>
+ </category>
+</settings>

0 comments on commit 540b59e

Please sign in to comment.
Something went wrong with that request. Please try again.