party-upload: more python3 compat
[clinton/unknownlamer-kodi-addons.git] / party-upload / partyparty.py
index 98d8f9f..c8ce3f0 100644 (file)
@@ -26,6 +26,7 @@ import random
 import re
 import subprocess
 import urllib
+import urllib.parse
 from kodijson import Kodi
 from yattag import Doc
 import youtube_dl
@@ -37,7 +38,7 @@ def connect (_kodi):
     kodi = _kodi
     return kodi
 
-SONG_PROPERTIES = ['album', 'artist', 'albumartist', 'dateadded', 'userrating', 'displayartist']
+SONG_PROPERTIES = ['album', 'artist', 'albumartist', 'title', 'dateadded', 'userrating', 'displayartist']
 PAGE_SELF = os.environ['SCRIPT_NAME'] if 'SCRIPT_NAME' in os.environ else ''
 
 class Song:
@@ -83,7 +84,10 @@ class Song:
       else:
          self.rating = -1 # might be better to use None here
 
-      self.label = song['label']
+      if 'title' in song and len(song['title']) > 0:
+          self.label = song['title']
+      else:
+          self.label = song['label']
 
 def songs(items):
    '''Convert list of Kodi Items into Song instances'''
@@ -298,7 +302,7 @@ class PartyManager:
         if divisor is None:
             divisor = self.DEFAULT_QUEUE_DIVISOR
         totalitems = kodi.Playlist.GetItems (playlistid=0)['result']['limits']['total']
-        playpos = random.randint (1, totalitems / divisor + 1)
+        playpos = random.randint (1, int(totalitems / divisor + 1))
         print_escaped (kodi.Playlist.Insert (playlistid=0, item=item, position=playpos))
         print ('<p style="font-size: x-large">Your song is number {0} in the queue ({1} songs in playlist).</p>'.format (playpos, totalitems+1))
         return (playpos, totalitems+1)