trakt icon indicating copy to clipboard operation
trakt copied to clipboard

Import From Plex's database to Trakt.

Open ghost opened this issue 5 years ago • 7 comments

Is there a simple way to sync historical data from Plex's database to Trakt? Plex has all watched data stored in metadata_item_views table. I am not sure how to extract from that table to format which your script would expect. Seems like something that might have been done before so figured I might ask. Thanks.

ghost avatar Mar 10 '19 15:03 ghost

I don't use Plex, so it has not been done before at least per me. If Plex use sqlite db the script should be similar to the Kodi export. Ideally you export in a file the IMDB ID. https://github.com/xbgmsharp/trakt/blob/master/KODI.md

xbgmsharp avatar Mar 11 '19 12:03 xbgmsharp

Sorry to resurrect this; I am running into this situation now.

Is there a chance you could please post the schema(s) of the .csv file that the import script expects? Then it shouldn't be a problem for me to work out the proper query that will output the necessary data from Plex's SQLite DB to the .csv file correctly.

SturmB avatar Mar 30 '22 21:03 SturmB

The import csv file should at least include a least an id, you can also have a rated_at and watched_at column. https://github.com/xbgmsharp/trakt/blob/master/import.md

xbgmsharp avatar Mar 31 '22 11:03 xbgmsharp

The import csv file should at least include a list a id, you can also have a rated_at and watched_at column. https://github.com/xbgmsharp/trakt/blob/master/import.md

I assume you meant "at least an id". And I guess the id would be either imdb, tvdb, etc.? That's fine, I am able to find that info in Plex. Same with watched_at.

However, I'm curious about adding to Trakt's 'collection' list. There is definitely an added_at column in one of Plex's db tables, which would be perfect for importing the date/time when a movie or tv show was added to Trakt's 'collection'. How would this be done? I'm guessing that I just need to add the flag -l collection to the cli command, but should the column name stay added_at in the csv file?

SturmB avatar Apr 01 '22 02:04 SturmB

That is correct the id can be either 'imdb', 'tmdb', 'tvdb', 'tvrage', 'trakt'. watched_at and rated_at are the only additional column supported at the moment. Feel free to contribute, anyhow I don't see an added_at in the doc, https://trakt.docs.apiary.io/#reference/sync But there is an collected_at when importing collection .

Example integration rated_at for https://github.com/xbgmsharp/trakt/pull/45/files Import cvs loop, https://github.com/xbgmsharp/trakt/blob/master/import_trakt.py#L450

xbgmsharp avatar Apr 01 '22 08:04 xbgmsharp

Okay, those links help, thank you. I am still missing something, though, as I got the following error message:

Invalid file format, id (row) must exists and is not blank (has a format).

From the following simple csv:

id,collected_at
tt0111282,2020-02-16T17:40:42Z

SturmB avatar Apr 01 '22 23:04 SturmB

After exploring the repo more and discovering the proper format at https://github.com/xbgmsharp/trakt/blob/master/import.md, I was finally able to get it to work. And I see that collected_at isn't, as you said, supported at the moment.

I just might fork the repo and take a stab at it, myself. If it works, I might even see if I can include the other metadata as well, such as resolution, audio, etc.

SturmB avatar Apr 03 '22 23:04 SturmB