Jump to content

Plex Migrations Scripts


CloudWing93
Go to solution Solved by lionn1,

Recommended Posts

CloudWing93

I spent lots of  time looking for a script that would migrate user watched history from plex to emby without luck so I decided to just write one myself. This project contains a few python scripts that will help you migrate some of the data from your plex server to you emby server. The scripts match using IMDB, TVDB , and TMDB.  Right now there are two main scripts.

The first one is named metadata-migration.py . It will migrate the following data:

  • Posters
  • Title
  • Original Title
  • Sort Title
  • Parental Rating
  • Labels/Tags

 

The second one is named watched-history-migration.py . This script can migrate watched history for any user but there is a caveat. You have to be able to get that user's plex token. Checkout the readme in the project repository for more details. It will migrate the following data:

  • Watched History


https://gitlab.com/CloudWing93/plex-to-emby-migration

Edited by CloudWing93
Updated with most recent changes.
  • Thanks 3
Link to comment
Share on other sites

  • 1 year later...

I've been running plex for 9+ years and we're finally looking to make the move to Emby. Issue is trakt is taking forever or erroring out. This is our last resort but I'm getting the error below. Thoughts?

image.png.21dbc9d9ad3fbb20e3e029a7c0b1bae8.png

* Serving Flask app "main.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.

Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
192.168.2.140 - - [22/Dec/2021 13:10:39] "[32mGET / HTTP/1.1[0m" 302 -
192.168.2.140 - - [22/Dec/2021 13:10:42] "[37mGET /auth HTTP/1.1[0m" 200 -
192.168.2.140 - - [22/Dec/2021 13:10:43] "[33mGET /favicon.ico HTTP/1.1[0m" 404 -
192.168.2.140 - - [22/Dec/2021 13:10:52] "[37mGET /close HTTP/1.1[0m" 200 -
[2021-12-22 13:11:09,198] ERROR in app: Exception on /migrate [POST]

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/app/main.py", line 81, in migrate
migration.migrateWatchedHistory("", plexAuthToken, request.form["username"])
File "/app/migration.py", line 23, in migrateWatchedHistory
plex_server = account.resource('Jedi Archives').connect()
File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 208, in resource
raise NotFound('Unable to find resource %s' % name)
plexapi.exceptions.NotFound: Unable to find resource Jedi Archives
192.168.2.140 - - [22/Dec/2021 13:11:09] "[35m[1mPOST /migrate?plexPinId=111&plexPinCode=222&plexClientId=333&plexToken=444 HTTP/1.1[0m" 500 -

 

image.png

Link to comment
Share on other sites

CloudWing93

@capodac Try this branch:
https://gitlab.com/CloudWing93/plex-to-emby-migration/-/tree/cli

Plex changed the way you get their auth tokens and by the time it quit working I had already moved my users over so I kinda abandoned the GUI. I made some quick changes this morning to set it up to use a CLI with arguments and added support for multiple libraries. You'd have to run the python script manually.  Let me know if you have any questions.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, CloudWing93 said:

@capodac Try this branch:
https://gitlab.com/CloudWing93/plex-to-emby-migration/-/tree/cli

Plex changed the way you get their auth tokens and by the time it quit working I had already moved my users over so I kinda abandoned the GUI. I made some quick changes this morning to set it up to use a CLI with arguments and added support for multiple libraries. You'd have to run the python script manually.  Let me know if you have any questions.

Gangster and clutch for the new year. I'll play around with it and report back. Much appreciated!

Link to comment
Share on other sites

  • 1 month later...
CloudWing93
55 minutes ago, Tangsgod said:

That is a really nice feature!

And what about to migrate posters?  :D

I can probably add functionality for that for series and movie posters. For collections and season posters I'd have to take a look at the plex api to see how difficult it would be.

Link to comment
Share on other sites

Tangsgod
2 minutes ago, CloudWing93 said:

I can probably add functionality for that for series and movie posters. For collections and season posters I'd have to take a look at the plex api to see how difficult it would be.

That would be great! 
I see more and more people leaving Plex to Emby, but the most difficult part of the migration is coming back to default posters, specially when you spent hours and hours to changed them and customizing them!

Link to comment
Share on other sites

CloudWing93

I just took a quick look at it and I think I can get a easy script for poster migration working within the next day or so. I'll let you know when it's ready if you want to test it out for me.

  • Like 2
Link to comment
Share on other sites

Tangsgod
17 minutes ago, CloudWing93 said:

I just took a quick look at it and I think I can get a easy script for poster migration working within the next day or so. I'll let you know when it's ready if you want to test it out for me.

Yes, I'll be glad to test it with you!
I have 6000 movies and 1000 series poster to migrate, so for testing usage I'll prepare 2 little librairies (1 for movies and 1 for series) ready for tests!
I'm really anthousistic, thank you!

Link to comment
Share on other sites

Tangsgod
13 hours ago, CloudWing93 said:

@Tangsgod I added a script to the repository called poster-migration.py that should migrate all the posters.
https://gitlab.com/CloudWing93/plex-to-emby-migration

All right, here is what I have done so far:

- I created 2 differents librairies for tests usage with only 4 movies and 2 tv shows:
          - "TEST FILMS POSTER EXPORT"
          - "TEST SERIE POSTER EXPORT"

They are both created in Plex and in Emby with the same librairie name (I don't know if it important)

- I installed Python 3.10,  Notepad++ and plexapi 

Here is what it looks like in the scripts:

parser = argparse.ArgumentParser(description="plex to emby migration.")
parser.add_argument('--embyUrl', type=str, help='http://localhost:8096/.')
parser.add_argument('--embyApiKey', type=str, help='***********************')
parser.add_argument('--plexUrl', type=str, help='http://localhost:32400/')
parser.add_argument('--plexAuthToken', type=str, help='******************')
parser.add_argument('--plexServerName', type=str, help='PLEXFLIX 2 : Le Retour')
parser.add_argument('--plexMovieLibraries', type=str, help='"TEST FILMS POSTER EXPORT"')
parser.add_argument('--plexSeriesLibraries', type=str, help='"TEST SERIE POSTER EXPORT"')

Then when I run the script it gives me this information:

C:\Users\Tangs\Desktop\plex-to-emby-migration-master>poster-migration.py
Getting Library Items. This can take a while.
Traceback (most recent call last):
  File "C:\Users\Tangs\Desktop\plex-to-emby-migration-master\poster-migration.py", line 128, in <module>
    emby_server = emby(opts.embyUrl.rstrip('/'), opts.embyApiKey, VERIFY_SSL)
AttributeError: 'NoneType' object has no attribute 'rstrip'

Could you guide me from here? This is my first step into scripts,  so sorry if I did some mistakes

Edited by Tangsgod
Hid tokens
Link to comment
Share on other sites

CloudWing93
1 hour ago, Tangsgod said:

Here is what it looks like in the scripts:

parser = argparse.ArgumentParser(description="plex to emby migration.")
parser.add_argument('--embyUrl', type=str, help='http://localhost:8096/.')
parser.add_argument('--embyApiKey', type=str, help='XXXXXXXXXXXX')
parser.add_argument('--plexUrl', type=str, help='http://localhost:32400/')
parser.add_argument('--plexAuthToken', type=str, help='XXXXXXXXXXXX')
parser.add_argument('--plexServerName', type=str, help='PLEXFLIX 2 : Le Retour')
parser.add_argument('--plexMovieLibraries', type=str, help='"TEST FILMS POSTER EXPORT"')
parser.add_argument('--plexSeriesLibraries', type=str, help='"TEST SERIE POSTER EXPORT"')

 

 

You almost there. The script was actually written so you didn't need to edit the file. All you should have to do is open a powershell window and copy and paste the following command and then change the values to what they need to be for your server:

python poster-migration.py --plexUrl localhost:32400 --plexAuthToken xxxxx --plexServerName SomeFriendlyName --plexMovieLibraries "Movies" --plexSeriesLibraries "TV Shows" --embyUrl "localhost:8096/emby/" --embyApiKey xxxxx


If you aren't comfortable trying to run the script with arguments above I also created an edited version that has a section at the top for you to edit and set the values you need. I attached it to this post.

Also it's not safe to share your emby and plex api tokens. You should really edit your post and remove them and then delete and recreate them on your servers. 

 

 

poster-migration-var.py

Edited by CloudWing93
  • Like 1
Link to comment
Share on other sites

Tangsgod

Thank you!
Here is what I get:

 

C:\Users\Tangs\Desktop\plex-to-emby-migration-master>poster-migration-var.py
Getting Library Items. This can take a while.
EMBY request failed for cmd 'Items?Recursive=true&IncludeItemTypes=Movie&Fields=ProviderIds'. Invalid EMBY URL? Error: HTTPConnectionPool(host='localhost', port=8096): Max retries exceeded with url: /emby/Items?Recursive=true&IncludeItemTypes=Movie&Fields=ProviderIds&api_key=**************************** (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001F2C3B70880>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée'))
Traceback (most recent call last):
  File "C:\Users\Tangs\Desktop\plex-to-emby-migration-master\poster-migration-var.py", line 134, in <module>
    embyMovies = emby.get_emby_movies(emby_server)
  File "C:\Users\Tangs\Desktop\plex-to-emby-migration-master\poster-migration-var.py", line 90, in get_emby_movies
    return self._call_api(cmd, 'GET')
  File "C:\Users\Tangs\Desktop\plex-to-emby-migration-master\poster-migration-var.py", line 66, in _call_api
    if response.status_code != 204:
UnboundLocalError: local variable 'response' referenced before assignment

 

Edited by GrimReaper
Hid API key
Link to comment
Share on other sites

CloudWing93

It wouldn't hurt to try it. The error is saying it can't find anything at the the url set using the embyUrl variable. You would want to use the first part of whatever you use to access the emby web up up to the :8096/

Link to comment
Share on other sites

Tangsgod
8 minutes ago, CloudWing93 said:

It wouldn't hurt to try it. The error is saying it can't find anything at the the url set using the embyUrl variable. You would want to use the first part of whatever you use to access the emby web up up to the :8096/

So I could make it work, but, the posters didn't change at all for the series and 1 movie poster stayed the same

 

Link to comment
Share on other sites

CloudWing93

That's good. The script uses imdb, tvdb, and tmdb to match. So if they aren't matching it's because in either plex or emby  don't both have the same provider ID for at least one of those. I can try and add a fallback and use names for matching if none of the provider ids match up.

Link to comment
Share on other sites

Tangsgod
45 minutes ago, CloudWing93 said:

That's good. The script uses imdb, tvdb, and tmdb to match. So if they aren't matching it's because in either plex or emby  don't both have the same provider ID for at least one of those. I can try and add a fallback and use names for matching if none of the provider ids match up.

Ok, i ran some tests and as a results:

-  all the movies posters get changed. The one that didn't match was because it was identify in Plex, once I did, it worked!

- none of the series posters get changed, even after re identify everything

 

Also, the changes were pretty fast! Less than 5 seconds for 5 movies :

While I'll wait for your reply I'll make a true test with my kids librairie (850 movies), seeing how it works I'll do it for the largest librairie (about 6500 movies)

Link to comment
Share on other sites

Tangsgod

Well, I'm simply impressed by the result.

It took only 3 minutes 15 seconds  to match and change those 850 posters....

And what more, because now they are in Emby, they are saved localy along the media folder, that is a big plus!

Before doing it with the large librairie I'll make sur that all the movies in Emby are identify, then I'll give it a go :)

 

How about the series, did you find what may be the cause of them failling to match?

THANK YOU! 
 


P.S.: One thing I'm thinking about, is that possible at the end of the matching process to have the list of the movies that didn't match?

Link to comment
Share on other sites

CloudWing93
3 hours ago, Tangsgod said:

Well, I'm simply impressed by the result.

It took only 3 minutes 15 seconds  to match and change those 850 posters....

And what more, because now they are in Emby, they are saved localy along the media folder, that is a big plus!

Before doing it with the large librairie I'll make sur that all the movies in Emby are identify, then I'll give it a go :)

 

How about the series, did you find what may be the cause of them failling to match?

THANK YOU! 
 


P.S.: One thing I'm thinking about, is that possible at the end of the matching process to have the list of the movies that didn't match?

I made some changes to the script to have it return a list of movies and series that a match can't be found for. It should also be more efficient now.

I'm not sure why the series aren't matching for you. I have been testing with my own test libraries and it works flawlessly on mine. It does seem like most of the matches are made using IMDB so maybe either your plex or emby libraries aren't pulling that metadata for some reason.

poster-migration-var.py

Link to comment
Share on other sites

CloudWing93

It's also possible that there is a typo or something like that in the library name you are passing through so plex isn't actually returning any tv shows.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...