-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathff-tabs-extract.py
executable file
·61 lines (45 loc) · 1.68 KB
/
ff-tabs-extract.py
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
#!.venv/bin/python3
# import sys
# sys.argv
import fire
## TODO get args -
## ? ff-tabs [in-name] [out-name] # assuming jsonlz4, the moz fmt
def fetch():
"""Copies current version of Firefox recovery backup file and returns path to snapshot"""
from glob import glob
from datetime import datetime
from shutil import copyfile
import os
paths = glob('/Users/mcint/Library/Application Support/Firefox/Profiles/*/sessionstore-backups/recovery.jsonlz4')
srcpath = paths[0]
localpath = 'data/raw'
timestamp = datetime.strftime(datetime.now(), '%F.%T')
tgtfile = '.'.join([os.path.basename(srcpath), timestamp, 'snapshot'])
tgtpath = os.path.join(localpath, tgtfile)
copyfile(srcpath, tgtpath)
# TODO copy to data/raw/ as recovery.jsonlz4.ymd.hms.snapshot
# TODO return new path to data/raw/ file
return tgtpath
# cp
# ~/Library/Application\ Support/Firefox/profiles/x98wumfy.default/sessionstore-backups/recovery.jsonlz4
# data/raw/$(date +"recovery.jsonlz4.%F.%T")
def extract(infile, outfile):
"""Decompress saved state from Mozilla's jsonlz4 with custom header bytes to json"""
f = open(infile, 'rb')
_mozilla_magic_prefix = f.read(8)
jsonlz4 = f.read()
import lz4.block
json = lz4.block.decompress(jsonlz4)
fw = open(outfile, 'wb')
fw.write(json)
return outfile
def backup():
"""Fetches and extracts saved session state to persistent and readable backup"""
import os
src = fetch()
tgtfname = os.path.basename(src).replace('.jsonlz4.','.json.')
outpath = 'data/out'
tgt = os.path.join(outpath, tgtfname)
return extract(src, tgt)
if __name__ == '__main__':
fire.Fire()