Skip to content

Instantly share code, notes, and snippets.

@anatolinicolae
Last active February 23, 2017 20:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anatolinicolae/d13e844b2bf791322ee0af19d401fa74 to your computer and use it in GitHub Desktop.
Infinit.io links backup
<?php
// Your current session cookie
$cookie = '';
// Files storage path
$storage_dir = './infinit-backup';
// Don't change anything below this. Just works™
$offset = 0;
$links = [];
while ( $offset != -1 ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://infinit.io/meta/links?count=100&offset=$offset");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Cookie: infinit_session=$cookie",
]
);
$resp = curl_exec($ch);
curl_close($ch);
$meta = json_decode($resp, 1);
// Avoid failes API requests which result in 'null' payload,
// will retry automatically same offset since it doesn't change.
if ( !is_null($meta['links']) ) {
$links = array_merge($links, $meta['links']);
if ( count($meta['links']) == 100 ) {
$offset += 100;
} else {
$offset = -1;
}
}
}
// Create path if doesn't exist
mkdir($storage_dir, 0777, true);
// Download links
foreach ($links as $link) {
$file = $storage_dir . '/' . $link['name'];
$url = $link['share_link'] . '/download';
// Prefix links containing multiple files
if ( count($link['files']) > 1 ) {
$file = $storage_dir . '/' . $link['hash'] . '_' . $link['name'];
}
file_put_contents($file, file_get_contents($url));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment