Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

  1. #! /usr/bin/python
  2. """
  3. List all Firefox tabs with title and URL
  4. Supported input: json or jsonlz4 recovery files
  5. Default output: title (URL)
  6. Output format can be specified as argument
  7. """
  8. import sys
  9. import os
  10. import pathlib
  11. import lz4.block
  12. import json
  13. class Node:
  14. def __init__(self, url, lastAccessed):
  15. self.url = url
  16. self.lastAccessed = lastAccessed
  17. self.left = None
  18. self.right = None
  19. self.parent = None
  20. def insert(self, node):
  21. if node.lastAccessed > self.lastAccessed:
  22. if self.right:
  23. self.right.insert(node)
  24. else:
  25. self.right = node
  26. node.parent = self
  27. else:
  28. if self.left:
  29. self.left.insert(node)
  30. else:
  31. self.left = node
  32. node.parent = self
  33. def print(self):
  34. if self.right: # Print from high to low
  35. self.right.print()
  36. print(self.url)
  37. if self.left:
  38. self.left.print()
  39. def main():
  40. path = pathlib.Path('/dev/shm/firefox-' + os.environ['FIREFOX_PROFILE'] + "-" + os.environ['USER'] + '/sessionstore-backups')
  41. files = path.glob('recovery.js*')
  42. tree = None
  43. for f in files:
  44. b = f.read_bytes()
  45. if b[:8] == b'mozLz40\0':
  46. b = lz4.block.decompress(b[8:])
  47. j = json.loads(b)
  48. for w in j['windows']:
  49. for t in w['tabs']:
  50. i = t['index'] - 1
  51. node = Node(t['entries'][i]['url'], t['lastAccessed'])
  52. if tree:
  53. tree.insert(node)
  54. else:
  55. tree = node
  56. if tree:
  57. tree.print()
  58. if __name__ == "__main__":
  59. main()