-
Star
(109)
You must be signed in to star a gist -
Fork
(14)
You must be signed in to fork a gist
-
-
Save darekkay/ff1c5aadf31588f11078 to your computer and use it in GitHub Desktop.
| <?php | |
| /* | |
| Backup script for trakt.tv (API v2). | |
| */ | |
| // create a Trakt app to get a client API key: http://docs.trakt.apiary.io/#introduction/create-an-app | |
| $apikey = "CLIENT_API_KEY"; | |
| $username = "YOUR_USERNAME"; | |
| $zip = new ZipArchive(); | |
| $zip_filename = "trakt_backup_" . date("Y-m-d") . ".zip"; | |
| $zip_filepath = "/tmp/trakt_backup_" . date("Y-m-d") . ".zip"; | |
| if ($zip->open($zip_filepath, ZIPARCHIVE::CREATE) !== TRUE) { | |
| exit("Cannot open <$zip_filepath>\n"); | |
| } | |
| loadAndZip("watchlist/movies/", "watchlist_movies.json"); | |
| loadAndZip("watchlist/shows/", "watchlist_shows.json"); | |
| loadAndZip("watchlist/episodes/", "watchlist_episodes.json"); | |
| loadAndZip("watchlist/seasons/", "watchlist_seasons.json"); | |
| loadAndZip("ratings/movies/", "ratings_movies.json"); | |
| loadAndZip("ratings/shows/", "ratings_shows.json"); | |
| loadAndZip("ratings/episodes/", "ratings_episodes.json"); | |
| loadAndZip("ratings/seasons/", "ratings_seasons.json"); | |
| loadAndZip("collection/movies/", "library_collection_movies.json"); | |
| loadAndZip("collection/shows/", "library_collection_shows.json"); | |
| loadAndZip("watched/movies/", "watched_movies.json"); | |
| loadAndZip("watched/shows/", "watched_shows.json"); | |
| loadAndZip("history/movies/", "history_movies.json"); | |
| loadAndZip("history/shows/", "history_shows.json"); | |
| $zip->close(); | |
| header("Content-type: application/zip"); | |
| header("Content-Disposition: attachment; filename=$zip_filename"); | |
| header("Pragma: no-cache"); | |
| header("Expires: 0"); | |
| readfile($zip_filepath); | |
| exit(); | |
| function loadAndZip($path, $filename) | |
| { | |
| global $zip, $apikey, $username; | |
| $url = "https://api.trakt.tv/users/" . $username . '/' . $path ; | |
| $ch = curl_init(); | |
| curl_setopt_array($ch, array( | |
| CURLOPT_URL => $url, | |
| CURLOPT_HTTPHEADER => array( | |
| "Content-Type: application/json", | |
| "trakt-api-key: " . $apikey, | |
| "trakt-api-version: 2"), | |
| CURLOPT_VERBOSE => true, | |
| CURLOPT_RETURNTRANSFER => true, | |
| CURLOPT_SSL_VERIFYPEER => 0, | |
| CURLOPT_SSL_VERIFYHOST => 0 | |
| )); | |
| $result = curl_exec($ch); | |
| $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| if($httpCode == 404) { | |
| exit("<h3>Wrong username!</h3>"); | |
| } | |
| curl_close($ch); | |
| $zip->addFromString($filename, $result); | |
| } |
Hi @darekkay, looks like Trakt is now blocking this at least for me, don't know if it's affecting others? Got back (trimmed):
<h2 class="cf-subheadline"><span data-translate="unable_to_access">You are unable to access</span> trakt.tv</h2>
<h2 data-translate="blocked_why_headline">Why have I been blocked?</h2>
<p data-translate="blocked_why_detail">This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.</p>
</div>
<h2 data-translate="blocked_resolve_headline">What can I do to resolve this?</h2>
<p data-translate="blocked_resolve_detail">You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.</p>
Trakt has definitely changed something. Can't log in anymore with my own passwd. I'm now receiving a code from them in order to log on. I guess with cyber WWIII going on it's only logical for them to do so.
Just looked on Trakt and they now have the option to download your own data (JSON) "https://trakt.tv/settings/data" which makes this script obsolete. Thx Darekay for this wonderful script.
@pinhead216 Thanks for posting the link to the data export page. This makes my script pretty much obsolete (except for automated backups - which I do not require personally). I removed the live script from my website.
@pinhead216 Thanks for posting the link to the data export page. This makes my script pretty much obsolete (except for automated backups - which I do not require personally). I removed the live script from my website.
It's been so helpful, thanks for all your work on it mate!
I use automated backups every Sunday at midnight (with monitoring in case anything goes wrong), I was originally using https://darekkay.com/service/trakt/trakt.php?username= but since that's been discontinued, I'll be using a copy of this script.
Thanks for sharing this!
@micmalti Thanks a lot for replying. By confirming that it worked for you I started trying again to see why it's not working for me and I finally figured out that it was because of my username. My username on Trakt was my e-mail address with a dot in the middle. (myname.s@gmail.com). I changed it from the email format and only kept myname.s , but trakt changes the URL from . to -
So to fix the problem I entered myname-s in the website and I was able to get it work.
Mentioned all this in case someone else faces the same problem!