From 7fef67f8520fdcb40075fdec2450753a310457d0 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 8 Dec 2019 00:38:58 -0800 Subject: [PATCH] list_photo_libraries now searches entire disk --- README.md | 2 +- osxphotos/__init__.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7940c167..a1a77068 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Returns path to last opened Photo Library as string. #### ```list_photo_libraries()``` -Returns list of Photos libraries found in the user's Pictures folder. +Returns list of Photos libraries found on the system ### PhotosDB diff --git a/osxphotos/__init__.py b/osxphotos/__init__.py index e80dc06a..acfce319 100644 --- a/osxphotos/__init__.py +++ b/osxphotos/__init__.py @@ -1,8 +1,8 @@ -import glob import json import logging import os.path import platform +import subprocess import sqlite3 import sys import tempfile @@ -191,8 +191,16 @@ def get_last_library_path(): def list_photo_libraries(): - """ returns list of Photos libraries found in the user's Pictures folder """ - lib_list = glob.glob(f"{str(Path.home())}/Pictures/*.photoslibrary") + """ returns list of Photos libraries found on the system """ + # lib_list = glob.glob(f"{str(Path.home())}/Pictures/*.photoslibrary") + # return lib_list + + lib_list = [] + output = subprocess.check_output( + ["/usr/bin/mdfind", "-onlyin", "/", "-name", ".photoslibrary"] + ).splitlines() + for lib in output: + lib_list.append(lib.decode("utf-8")) return lib_list