Advertisement
Guest User

Plex duration check

a guest
Jan 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. from plexapi.server import PlexServer
  2.  
  3. plex = PlexServer("http://localhost:32400", "you API token") #set API token and change server IP if needed
  4. y = 0
  5.  
  6. def time(seconds):
  7.     m, s = divmod(seconds / 1000, 60)
  8.     h, m = divmod(m, 60)
  9.     d, h = divmod(h, 24)
  10.     return("%d days : %d hours : %d minutes : %d seconds" % (d, h, m, s))
  11.    
  12. def calcTV(library):
  13.     t = 0
  14.     global y
  15.     for m in plex.library.section(library).all():
  16.         for x in m.episodes():
  17.             if type(x.duration) is int:
  18.                 t += x.duration
  19.     y += t
  20.     return time(t) + " in %s" % (library)
  21.    
  22. def calcMusic(library):
  23.     t = 0
  24.     global y
  25.     for m in plex.library.section(library).all():
  26.         for x in m.tracks():
  27.             if type(x.duration) is int:
  28.                 t += x.duration
  29.     y += t
  30.     return time(t) + " in %s" % (library)
  31.  
  32. def calcMovie(library):
  33.     t = 0
  34.     global y
  35.     for m in plex.library.section(library).all():
  36.         if type(m.duration) is int:
  37.                 t += m.duration
  38.     y += t
  39.     return time(t) + " in %s" % (library)
  40.  
  41. print(calcMusic("Music")) #change string to your music library name
  42. print(calcMovie("Films")) #change string to your Movie library name
  43. print(calcTV("TV")) #change string to your TV library name
  44. print(time(y) + " in total")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement