#!/usr/bin/python3 # Copyright 2012, Svenne Krap # svenne@krap.dk # # Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # This script enables you to save all tabs in a (single-window) firefox sessions to a text file import json import os import os.path import sys import time ts = time.strftime("%Y-%m-%d-%H:%M:%S") if len(sys.argv) == 2: profile = sys.argv[1] else: profile = "default" basedir = os.environ['HOME'] + "/.mozilla/firefox/" histdir = os.environ['HOME'] + "/mozhistory"; if not os.path.exists(histdir): os.mkdir(histdir) outfile = histdir + "/" + profile + "-" + ts os.chdir(basedir) files = os.listdir(".") thefile = None for fil in files: if not fil.endswith("." + profile): continue thefile = fil if thefile == None: print("cant find profile") sys.exit() thefile = basedir + "/" + thefile + "/sessionstore.js" print ("Using " + thefile) data = open(thefile,'r').read() j = json.loads(data) fields = ["title","url"] windows = len(j['windows']) outfp = open(outfile,"w") for w in range(windows): print("Looking at window " + str(w)) tabs = len(j['windows'][w]["tabs"]) print (" Found " + str(tabs) + " tabs") for t in range(tabs): print(" Looking at tab " + str(w)) entries = len(j['windows'][w]["tabs"][t]["entries"]) print(" History depth: " + str(entries)) for e in range(entries): try: title = j['windows'][w]["tabs"][t]["entries"][e]["title"] except: title = ""; try: url = j['windows'][w]["tabs"][t]["entries"][e]["url"] except: continue print (" Found:") print (" Entry: " + str(e)) print (" Url : " + url) print (" Title: " + title) outfp.write( str(w) + " " + str(t) + " " + str(e) + " " + url + " \"" + title + "\"\n") outfp.close() print ("Saved as " + outfile)