# traktexport
Export your Movie/TV shows ratings and history from https://trakt.tv/
This isn't meant to be used to re-import info back into Trakt or export to another site, its just meant to save all my data so I have it locally, and can do analysis or graph my history (e.g., on [my feed](https://sean.fish/feed/?order_by=when&sort=desc&ftype=trakt_history_episode%2Ctrakt_history_movie))
This is also used internally in [trakt-watch](https://github.com/seanbreckenridge/trakt-watch/tree/main), a small CLI to let you mark episodes/movies as watched on Trakt
## Installation
Requires `python3.8+`
To install with pip, run:
pip install traktexport
## Usage
```
Usage: traktexport [OPTIONS] COMMAND [ARGS]...
Export data from your Trakt account
Options:
--help Show this message and exit.
Commands:
auth setup authentication
export run an account export
inspect read/interact with an export file
merge merge multiple exports
partial_export run a partial export
```
### Auth
This uses OAuth to authenticate with the Trakt API, see [here](https://glensc.github.io/python-pytrakt/getstarted.html#oauth-auth) for more info.
This requires a manual setup the first time you use it, after which credentials are stored and this can run without any interaction.
### Setup
- Go to <https://trakt.tv/oauth/applications> and create a new application
- Use `urn:ietf:wg:oauth:2.0:oob` for the Redirect URI
- Run `traktexport auth yourTraktUsername`
- Follow the instructions, pasting in your Client ID/Secret from the Trakt dashboard, going to the link and pasting the generated pin back into the terminal
Once you've done that, this saves OAuth refresh info in `${XDG_DATA_HOME:-$HOME/.local/share}/traktexport.json` (can overwrite location with the `TRAKTEXPORT_CFG` environment variable)
### Export
Then, to export all your ratings/movies/shows, run:
`traktexport export yourTraktUsername > data.json`
The results are printed to STDOUT, so `> data.json` saves it to `data.json`
```
$ python3 -m traktexport export yourTraktUsername > data.json
[D 210326 18:42:43 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/followers'...
[D 210326 18:42:45 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/following'...
[D 210326 18:42:48 export:32] Requesting 'https://api-v2launch.trakt.tv/users/settings'...
[D 210326 18:42:51 export:32] Requesting 'https://api-v2launch.trakt.tv/users/likes'...
[D 210326 18:42:54 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername'...
[D 210326 18:42:56 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/comments'...
[D 210326 18:42:59 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/lists'...
[D 210326 18:43:01 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/ratings'...
[D 210326 18:43:05 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/recommendations'...
[D 210326 18:43:07 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watchlist'...
[D 210326 18:43:10 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watched/movies'...
[D 210326 18:43:13 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watched/shows'...
[D 210326 18:43:21 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/collection/movies'...
[D 210326 18:43:23 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/collection/shows'...
[D 210326 18:43:26 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/stats'...
[D 210326 18:43:29 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=1'...
[D 210326 18:43:31 export:44] First item: {'id': 7353545729, 'watched_at': '2021-03-22T06:33:24.000Z', 'action': 'watch', 'type': 'movie', 'movie': {'title': 'Rain Man', 'year': 1988, 'ids': {'trakt': 304, 'slug': 'rain-man-1988', 'imdb': 'tt0095953', 'tmdb': 380}}}
[D 210326 18:43:31 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=2'...
[D 210326 18:43:34 export:44] First item: {'id': 7178301624, 'watched_at': '2021-01-23T04:25:15.000Z', 'action': 'watch', 'type': 'episode', 'episode': {'season': 7, 'number': 7, 'title': 'Dangerous Debt', 'ids': {'trakt': 2590748, 'tvdb': 7640571, 'imdb': 'tt9313956', 'tmdb': 2201892, 'tvrage': None}}, 'show': {'title': 'Star Wars: The Clone Wars', 'year': 2008, 'ids': {'trakt': 4170, 'slug': 'star-wars-the-clone-wars', 'tvdb': 83268, 'imdb': 'tt0458290', 'tmdb': 4194, 'tvrage': 19187}}}
[D 210326 18:43:34 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=3'...
```
#### Partial Export
You can also export a part of your recent history, instead of your entire history (as that tends to take a few minutes)
```
traktexport partial_export --help
Usage: traktexport partial_export [OPTIONS] USERNAME
Run a partial history export - assumes authentication has already
been setup
This exports your movie/TV show history from Trakt without all
the other attributes. You can specify --pages to only request the
first few pages so this doesn't take ages to run.
The 'merge' command takes multiple partial exports (or full
exports) and merges them all together into a complete history
Options:
--pages INTEGER Only request these many pages of your history
--help Show this message and exit.
```
E.g. To export your most recent 100 watches, you can run `traktexport partial_export yourTraktUsername --pages 1`
Those can then all be combined by the `merge` command, like: `traktexport merge ~/data/trakt/*.json`
To do that in python, you can also do:
```
from traktexport.merge import read_and_merge_exports
read_and_merge_exports(["full_export.json", "partial_export.json"])
```
### Inspect
[`traktexport.dal`](./traktexport/dal.py) includes some code I use to parse the resulting JSON file into Python objects so its easier to manipulate
```python
class TraktExport(NamedTuple):
username: str
followers: List[Follow]
following: List[Follow]
likes: List[Like]
stats: Dict[str, Any]
settings: Dict[str, Any]
watchlist: List[WatchListEntry]
ratings: List[Rating]
history: List[HistoryEntry]
```
```
python3 -m traktexport inspect data.json
Use 'data' to interact with the parsed TraktExport object
In [1]: data.history[0]
Out[1]: HistoryEntry(history_id=7353545729, watched_at=datetime.datetime(2021, 3, 22, 13, 33, 24, tzinfo=datetime.timezone.utc), action='watch', media_type='movie', media_data=Movie(title='Rain Man', year=1988, ids=SiteIds(trakt_id=304, trakt_slug='rain-man-1988', imdb_id='tt0095953', tmdb_id=380, tvdb_id=None, tvrage_id=None)))
In [2]: len(data.history)
Out[2]: 16063
In [3]: data.stats["movies"]["plays"]
Out[3]: 1511
```
Note: This does include this info the export, but it doesn't currently parse:
- collection
- comments
- lists
- recommendations
... because I don't have any of those on trakt. If you use those, a PR would be appreciated!
Created to use as part of [`HPI`](https://github.com/seanbreckenridge/HPI)
Raw data
{
"_id": null,
"home_page": "https://github.com/seanbreckenridge/traktexport",
"name": "traktexport",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "media movies export data",
"author": "Sean Breckenridge",
"author_email": "\"seanbrecke@gmail.com\"",
"download_url": "https://files.pythonhosted.org/packages/32/a5/9eccd97c9266dd31f041ba8c7bafdade00a318a838024723363daeb1f0be/traktexport-0.1.8.tar.gz",
"platform": null,
"description": "# traktexport\n\nExport your Movie/TV shows ratings and history from https://trakt.tv/\n\nThis isn't meant to be used to re-import info back into Trakt or export to another site, its just meant to save all my data so I have it locally, and can do analysis or graph my history (e.g., on [my feed](https://sean.fish/feed/?order_by=when&sort=desc&ftype=trakt_history_episode%2Ctrakt_history_movie))\n\nThis is also used internally in [trakt-watch](https://github.com/seanbreckenridge/trakt-watch/tree/main), a small CLI to let you mark episodes/movies as watched on Trakt\n\n## Installation\n\nRequires `python3.8+`\n\nTo install with pip, run:\n\n pip install traktexport\n\n## Usage\n\n```\nUsage: traktexport [OPTIONS] COMMAND [ARGS]...\n\n Export data from your Trakt account\n\nOptions:\n --help Show this message and exit.\n\nCommands:\n auth setup authentication\n export run an account export\n inspect read/interact with an export file\n merge merge multiple exports\n partial_export run a partial export\n```\n\n### Auth\n\nThis uses OAuth to authenticate with the Trakt API, see [here](https://glensc.github.io/python-pytrakt/getstarted.html#oauth-auth) for more info.\n\nThis requires a manual setup the first time you use it, after which credentials are stored and this can run without any interaction.\n\n### Setup\n\n- Go to <https://trakt.tv/oauth/applications> and create a new application\n- Use `urn:ietf:wg:oauth:2.0:oob` for the Redirect URI\n- Run `traktexport auth yourTraktUsername`\n- Follow the instructions, pasting in your Client ID/Secret from the Trakt dashboard, going to the link and pasting the generated pin back into the terminal\n\nOnce you've done that, this saves OAuth refresh info in `${XDG_DATA_HOME:-$HOME/.local/share}/traktexport.json` (can overwrite location with the `TRAKTEXPORT_CFG` environment variable)\n\n### Export\n\nThen, to export all your ratings/movies/shows, run:\n\n`traktexport export yourTraktUsername > data.json`\n\nThe results are printed to STDOUT, so `> data.json` saves it to `data.json`\n\n```\n$ python3 -m traktexport export yourTraktUsername > data.json\n[D 210326 18:42:43 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/followers'...\n[D 210326 18:42:45 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/following'...\n[D 210326 18:42:48 export:32] Requesting 'https://api-v2launch.trakt.tv/users/settings'...\n[D 210326 18:42:51 export:32] Requesting 'https://api-v2launch.trakt.tv/users/likes'...\n[D 210326 18:42:54 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername'...\n[D 210326 18:42:56 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/comments'...\n[D 210326 18:42:59 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/lists'...\n[D 210326 18:43:01 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/ratings'...\n[D 210326 18:43:05 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/recommendations'...\n[D 210326 18:43:07 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watchlist'...\n[D 210326 18:43:10 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watched/movies'...\n[D 210326 18:43:13 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/watched/shows'...\n[D 210326 18:43:21 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/collection/movies'...\n[D 210326 18:43:23 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/collection/shows'...\n[D 210326 18:43:26 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/stats'...\n[D 210326 18:43:29 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=1'...\n[D 210326 18:43:31 export:44] First item: {'id': 7353545729, 'watched_at': '2021-03-22T06:33:24.000Z', 'action': 'watch', 'type': 'movie', 'movie': {'title': 'Rain Man', 'year': 1988, 'ids': {'trakt': 304, 'slug': 'rain-man-1988', 'imdb': 'tt0095953', 'tmdb': 380}}}\n[D 210326 18:43:31 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=2'...\n[D 210326 18:43:34 export:44] First item: {'id': 7178301624, 'watched_at': '2021-01-23T04:25:15.000Z', 'action': 'watch', 'type': 'episode', 'episode': {'season': 7, 'number': 7, 'title': 'Dangerous Debt', 'ids': {'trakt': 2590748, 'tvdb': 7640571, 'imdb': 'tt9313956', 'tmdb': 2201892, 'tvrage': None}}, 'show': {'title': 'Star Wars: The Clone Wars', 'year': 2008, 'ids': {'trakt': 4170, 'slug': 'star-wars-the-clone-wars', 'tvdb': 83268, 'imdb': 'tt0458290', 'tmdb': 4194, 'tvrage': 19187}}}\n[D 210326 18:43:34 export:32] Requesting 'https://api-v2launch.trakt.tv/users/yourTraktUsername/history?limit=100&page=3'...\n```\n\n#### Partial Export\n\nYou can also export a part of your recent history, instead of your entire history (as that tends to take a few minutes)\n\n```\ntraktexport partial_export --help\nUsage: traktexport partial_export [OPTIONS] USERNAME\n\n Run a partial history export - assumes authentication has already\n been setup\n\n This exports your movie/TV show history from Trakt without all\n the other attributes. You can specify --pages to only request the\n first few pages so this doesn't take ages to run.\n\n The 'merge' command takes multiple partial exports (or full\n exports) and merges them all together into a complete history\n\nOptions:\n --pages INTEGER Only request these many pages of your history\n --help Show this message and exit.\n```\n\nE.g. To export your most recent 100 watches, you can run `traktexport partial_export yourTraktUsername --pages 1`\n\nThose can then all be combined by the `merge` command, like: `traktexport merge ~/data/trakt/*.json`\n\nTo do that in python, you can also do:\n\n```\nfrom traktexport.merge import read_and_merge_exports\nread_and_merge_exports([\"full_export.json\", \"partial_export.json\"])\n```\n\n### Inspect\n\n[`traktexport.dal`](./traktexport/dal.py) includes some code I use to parse the resulting JSON file into Python objects so its easier to manipulate\n\n```python\nclass TraktExport(NamedTuple):\n username: str\n followers: List[Follow]\n following: List[Follow]\n likes: List[Like]\n stats: Dict[str, Any]\n settings: Dict[str, Any]\n watchlist: List[WatchListEntry]\n ratings: List[Rating]\n history: List[HistoryEntry]\n```\n\n```\npython3 -m traktexport inspect data.json\nUse 'data' to interact with the parsed TraktExport object\n\nIn [1]: data.history[0]\nOut[1]: HistoryEntry(history_id=7353545729, watched_at=datetime.datetime(2021, 3, 22, 13, 33, 24, tzinfo=datetime.timezone.utc), action='watch', media_type='movie', media_data=Movie(title='Rain Man', year=1988, ids=SiteIds(trakt_id=304, trakt_slug='rain-man-1988', imdb_id='tt0095953', tmdb_id=380, tvdb_id=None, tvrage_id=None)))\n\nIn [2]: len(data.history)\nOut[2]: 16063\n\nIn [3]: data.stats[\"movies\"][\"plays\"]\nOut[3]: 1511\n```\n\nNote: This does include this info the export, but it doesn't currently parse:\n\n- collection\n- comments\n- lists\n- recommendations\n\n... because I don't have any of those on trakt. If you use those, a PR would be appreciated!\n\nCreated to use as part of [`HPI`](https://github.com/seanbreckenridge/HPI)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Export your Movies, TV shows and ratings from Trakt.tv",
"version": "0.1.8",
"project_urls": {
"Homepage": "https://github.com/seanbreckenridge/traktexport"
},
"split_keywords": [
"media",
"movies",
"export",
"data"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "91d57176223d7fc4b3b7849d161d9c52b3c2e2779bc749a97a1f9c080db09ac8",
"md5": "cd3f0a8ab6703a5b1eb2115c9418af1a",
"sha256": "0a5ec566b77b61793740e69a4ce6499c1bf5000190161b301d97c6a900ab8065"
},
"downloads": -1,
"filename": "traktexport-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd3f0a8ab6703a5b1eb2115c9418af1a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 12258,
"upload_time": "2024-02-02T20:47:48",
"upload_time_iso_8601": "2024-02-02T20:47:48.889558Z",
"url": "https://files.pythonhosted.org/packages/91/d5/7176223d7fc4b3b7849d161d9c52b3c2e2779bc749a97a1f9c080db09ac8/traktexport-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "32a59eccd97c9266dd31f041ba8c7bafdade00a318a838024723363daeb1f0be",
"md5": "fbfc99a83554f4d2bb23f870fd38e11b",
"sha256": "0ef03dc6ef871a639c423136e3e562bae8a7e86b2c9cf3562ec84ee7976fc453"
},
"downloads": -1,
"filename": "traktexport-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "fbfc99a83554f4d2bb23f870fd38e11b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 13293,
"upload_time": "2024-02-02T20:47:50",
"upload_time_iso_8601": "2024-02-02T20:47:50.707554Z",
"url": "https://files.pythonhosted.org/packages/32/a5/9eccd97c9266dd31f041ba8c7bafdade00a318a838024723363daeb1f0be/traktexport-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-02 20:47:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "seanbreckenridge",
"github_project": "traktexport",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "traktexport"
}