-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
executable file
·86 lines (65 loc) · 1.96 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* 1. Grab cookies from web browser's active session and save to file.
* 2. Pass cooke file as first argument
* 3. Pass username as second argument
* 4. Pass data type as third argument, default is 'activity'
*/
$cfile = @$argv[1];
$user = @$argv[2];
if (!(is_file($cfile) && is_readable($cfile))) {
echo("Cookie file not found or readable.\n");
exit(1);
}
if (empty($user)) {
echo("Username is required.\n");
exit(1);
}
$cookie = trim(file_get_contents($cfile));
$types = ['activity', 'highlight', 'note', 'bookmark'];
$export = in_array(@$argv[3], $types) ? @$argv[3] : $types[0];
$save_dir = __DIR__ . "/data";
if(!is_dir($save_dir)) mkdir($save_dir);
$sfile = "$save_dir/".ucfirst($export) . "-".date('Ymd-His').".json";
$count = 0;
$cerror = null;
$content = "[";
while(true) {
$output = get_pages(++$count, $export);
$decoded = json_decode($output, true);
if (!is_array($decoded)) {
echo "Error parsing YouVersion data\n";
if (!empty($cerror)) echo "$cerror\n";
exit(1);
}
if (isset($decoded['error'])) {
echo(" [DONE] \n");
break;
} else {
if ($count > 1) $content .= ",";
$output = ltrim($output, '[');
$output = rtrim($output, ']');
$content .= $output;
echo "\rExported page $count...";
}
}
$content .= "]";
file_put_contents($sfile, $content);
function get_pages($count, $type) {
global $cookie;
global $user;
global $cerror;
if ($type == "activity") {
$url = "https://my.bible.com/users/{$user}/_cards.json?page=$count";
} else {
$url = "https://my.bible.com/users/{$user}/_cards.json?kind=$type&page=$count";
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: $cookie"));
$output = curl_exec($ch);
$cerror = curl_error($ch);
curl_close($ch);
return $output;
}