Porting "Mark as Played"

I’m running Plex via a freenas (aka truenas) plugin. Having a heck of time upgrading the plugin to the latest version. So my solution was to install a separate instance of the plugin and then re-building the libraries.

All good so far. Now in the web gui I have two servers showing “old” and “new”. The libraries are re-built now, so basically each library duplicated. The problem is on the “new” server, everything is indicated as “Unplayed” (as expected).

Is there a config file or such that I can copy over somehow to indicated the Played status on my new server? Will be a heck of job to go through every show and movie manually!

You can try Move Viewstate/Ratings from One Install to Another | Plex Support

But this must be done before anything is played on the new server. Otherwise you may see negative play counts and other weird behavior.
And it will only work for “matchable” items.

Thanks for your response!
Might be beyond my technical abilities. Any idea how to do this within the freenas/truenas environment?

Sorry, no. I have no experience whatsoever with this platform.

OK, thanks. No other responses, so I guess it’s the end of the road for me.

Do you have any programming experience?

Minimal. Have written some Python code and some basic SQL queries. I guess I was hoping for a backup/restore config file option.

As long as you only need to backup/restore one user writing the code in python to copy the data to a new server is trivial.

Yes, just one user. I’m game to try, but would need a nudge in the right direction.

make sure the plexapi package is installed

from plexapi.server import PlexServer
from plexapi.myplex import MyPlexAccount
def main():
  account = MyPlexAccount('<username>', '<password>')
  plex = account.resource('<servername>').connect()
  seen = get_lines(u'seen.txt')

  places = ['TV'] # library name
  for place in places:
    tv_shows = plex.library.section(place)
    for show in tv_shows.all():
      episodes = None
      error_count = 0
      while not episodes:
        try:
          episodes = show.episodes()
        except:
          error_count +=1
          pass
        if error_count > 10:
          episodes = show.episodes()
        time.sleep(2)
      for video in episodes:
        for part in video.iterParts():
          filename = part.file
        ###################################
        ### section for logging history ###
        ###################################
        if video.isWatched:
          log(u'%s\n' % filename,u'seen.txt')
        ###################################
        ### section for restoring status ###
        ###################################
        if filename in seen:
          video.markWatched()

def log(text,file):
  f3 = codecs.open(file, 'a', 'utf-8')
  f3.write(text)
  f3.close()
  
def get_lines(file):
  # try:
    f = codecs.open(file,'r', 'utf-8')
    names = f.read().split('\n')
    f.close()
    f = True
    while f:
      try:
        names.remove('')
      except:
        f = False
        pass
  # except:
    # names = []
    return names
if __name__ == '__main__':
  main()

Should get you close enough to fix just need a bit of tweaking

Wow, great, thanks!
I’m assuming I run this within the Plex jail somehow?

I just have a plex.py that I have on my computer along with the Python install, and I pip install the plexapi package

The complication for me is that my Plex is running via a plug in in a jail on my freenas server. Need to figure out how to execute the .py in that environment

No you dont, that python file interacts with the PlexAPI and can be ran on any computer, it does not need ran on the same host as the server.

Right, got it! Thanks so much, I’m on it!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.