~thecashewtrader/scripts

3240bd2d124876b026934c5f6b0c4476d56aab68 — thecashewtrader 10 months ago 59677c0
Add get_firefox_tabs.py
2 files changed, 34 insertions(+), 0 deletions(-)

A get_firefox_tabs/get_firefox_tabs.py
M symlinks/symlinks.sh
A get_firefox_tabs/get_firefox_tabs.py => get_firefox_tabs/get_firefox_tabs.py +33 -0
@@ 0,0 1,33 @@
#! /usr/bin/env python3

"""
List all Firefox tabs with title and URL
Supported input: json or jsonlz4 recovery files
Default output: title (URL)
Output format can be specified as argument
"""

import sys
import pathlib
import lz4.block
import json

path = pathlib.Path.home().joinpath('.mozilla/firefox')
files = path.glob('*default*/sessionstore-backups/recovery.js*')

try:
    template = sys.argv[1]
except IndexError:
    template = '%s'

for f in files:
    b = f.read_bytes()
    if b[:8] == b'mozLz40\0':
        b = lz4.block.decompress(b[8:])
    j = json.loads(b)
    for w in j['windows']:
        for t in w['tabs']:
            i = t['index'] - 1
            print(template % (
                t['entries'][i]['url']
                ))

M symlinks/symlinks.sh => symlinks/symlinks.sh +1 -0
@@ 33,3 33,4 @@ ln -s ~/.scripts/zathura_clipboard/zathura_clipboard.sh ~/.local/bin/zathura_cli
ln -s ~/.scripts/cscat/cscat.sh ~/.local/bin/cscat
ln -s ~/.scripts/digitise_clipboard/digitise_clipboard.sh ~/.local/bin/digitise_clipboard
ln -s ~/.scripts/ytdlp_clip/ytdlp_clip.sh ~/.local/bin/ytdlp_clip
ln -s ~/.scripts/get_firefox_tabs/get_firefox_tabs.py ~/.local/bin/get_firefox_tabs