CloudWing93 26 Posted July 30, 2020 Share Posted July 30, 2020 (edited) 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 February 1, 2022 by CloudWing93 Updated with most recent changes. 3 Link to comment Share on other sites More sharing options...
Luke 37191 Posted July 30, 2020 Share Posted July 30, 2020 Hi that's great, thanks for sharing ! Link to comment Share on other sites More sharing options...
capodac 3 Posted December 22, 2021 Share Posted December 22, 2021 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? * 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 - Link to comment Share on other sites More sharing options...
CloudWing93 26 Posted December 28, 2021 Author Share Posted December 28, 2021 @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. 1 Link to comment Share on other sites More sharing options...
capodac 3 Posted December 29, 2021 Share Posted December 29, 2021 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 More sharing options...
Tangsgod 22 Posted January 30, 2022 Share Posted January 30, 2022 That is a really nice feature! And what about to migrate posters? Link to comment Share on other sites More sharing options...
CloudWing93 26 Posted January 30, 2022 Author Share Posted January 30, 2022 55 minutes ago, Tangsgod said: That is a really nice feature! And what about to migrate posters? 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 More sharing options...
Tangsgod 22 Posted January 30, 2022 Share Posted January 30, 2022 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 More sharing options...
CloudWing93 26 Posted January 30, 2022 Author Share Posted January 30, 2022 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. 2 Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 30, 2022 Share Posted January 30, 2022 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 More sharing options...
CloudWing93 26 Posted January 31, 2022 Author Share Posted January 31, 2022 (edited) @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 Edited January 31, 2022 by CloudWing93 1 Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 2 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 Ok then, as it will be my first time with scripts, could you take a minute to tell me how I should procede? Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 Don't tell me, I'm learning how by myself, always better Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 (edited) 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 January 31, 2022 by Tangsgod Hid tokens Link to comment Share on other sites More sharing options...
CloudWing93 26 Posted January 31, 2022 Author Share Posted January 31, 2022 (edited) 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 January 31, 2022 by CloudWing93 1 Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 (edited) 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 January 31, 2022 by GrimReaper Hid API key Link to comment Share on other sites More sharing options...
CloudWing93 26 Posted January 31, 2022 Author Share Posted January 31, 2022 (edited) What did you put for the embyUrl? If you put http://localhost:8096/ you might need to change it to http://localhost:8096/emby/ Or if emby is running on a different machine you would want to use it's IP address like http://192.168.0.x:8096/emby/ Edited January 31, 2022 by CloudWing93 Link to comment Share on other sites More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 (edited) I put this: http://localhost:8096/emby/ Or should i put this : http://192.168.1.89:8096/ ? Edit: using this one worked: http://192.168.1.89:8096/ Edited January 31, 2022 by Tangsgod Link to comment Share on other sites More sharing options...
CloudWing93 26 Posted January 31, 2022 Author Share Posted January 31, 2022 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 More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 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 More sharing options...
CloudWing93 26 Posted January 31, 2022 Author Share Posted January 31, 2022 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 More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 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 More sharing options...
Tangsgod 22 Posted January 31, 2022 Share Posted January 31, 2022 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 More sharing options...
CloudWing93 26 Posted February 1, 2022 Author Share Posted February 1, 2022 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 More sharing options...
CloudWing93 26 Posted February 1, 2022 Author Share Posted February 1, 2022 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now