Created
June 19, 2014 09:31
-
-
Save davebrent/b1fa2e8b94b7f6542e13 to your computer and use it in GitHub Desktop.
Links from Messages (OSX)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
from subprocess import PIPE | |
from subprocess import Popen | |
try: | |
from plistlib import loads as readPlistFromString | |
except ImportError: | |
from plistlib import readPlistFromString | |
IS_LINK = re.compile(r'(https?://[^\s]+)') | |
def read_biplist(filename): | |
if not os.path.isfile(filename): | |
return | |
args = ["plutil", "-convert", "xml1", "-o", "-", filename] | |
p = Popen(args, stdout=PIPE) | |
out, err = p.communicate() | |
return readPlistFromString(out) | |
def extract_links(plist): | |
links = set([]) | |
for group in plist["$objects"]: | |
if not isinstance(group, dict) or "NS.string" not in group or \ | |
group["NS.string"] is None: | |
continue | |
value = group["NS.string"] | |
links.update(IS_LINK.findall(value)) | |
return links | |
def list_files(root_dir): | |
for root, _, files in os.walk(root_dir): | |
for filepath in files: | |
yield os.path.join(root, filepath) | |
if __name__ == "__main__": | |
path = "Library/Containers/com.apple.iChat/Data/Library/Messages/Archive" | |
path = os.path.join(os.path.expanduser("~"), path) | |
links = set([]) | |
for filepath in list_files(path): | |
plist = read_biplist(filepath) | |
links.update(extract_links(plist)) | |
for link in links: | |
print(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment