Advertisement
Guest User

Untitled

a guest
Apr 18th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. Oh apparently it's SQlite: https://www.lightroomqueen.com/community/tags/sqlite/
  2.  
  3. I don't have lightroom so I've guessed a few things.
  4.  
  5. So try this one:
  6.  
  7. ```
  8. pip install sqlite3 pandas borgbackup
  9. ```
  10.  
  11. ```
  12. import os
  13. import sys
  14. import sqlite3
  15. import pandas as pd
  16. from subprocess import call
  17.  
  18. def get_rated_images(catalog_file):
  19. conn = sqlite3.connect(catalog_file)
  20. cursor = conn.cursor()
  21.  
  22. query = '''
  23. SELECT
  24. A.name AS Folder_Name,
  25. B.baseName || '.' || C.value AS File_Name,
  26. D.value AS Rating,
  27. A.absolutePath || A.name || '/' || B.baseName || '.' || C.value AS File_Path
  28. FROM
  29. AgLibraryFolder A
  30. JOIN AgLibraryFile B ON A.id_local = B.folder
  31. JOIN AgLibraryIPTC C ON B.id_local = C.image
  32. JOIN Adobe_images D ON B.id_local = D.id_local
  33. WHERE
  34. C.fieldName = 'XMP:MetadataDate'
  35. AND D.rating IN (4, 5)
  36. AND B.fileFormat IN ('RAW', 'CR2', 'NEF', 'DNG', 'ARW')
  37. '''
  38.  
  39. cursor.execute(query)
  40.  
  41. rated_images = cursor.fetchall()
  42.  
  43. conn.close()
  44.  
  45. return rated_images
  46.  
  47. def main():
  48. if len(sys.argv) != 4:
  49. print("Usage: python lightroom_borgbackup.py <lightroom_catalog_path> <repo_path> <backup_name>")
  50. return
  51.  
  52. catalog_path = sys.argv[1]
  53. repo_path = sys.argv[2]
  54. backup_name = sys.argv[3]
  55.  
  56. catalog_file = os.path.join(catalog_path, 'Lightroom Catalog.lrcat')
  57.  
  58. if not os.path.exists(catalog_file):
  59. print("Lightroom Catalog not found. Please check the path.")
  60. return
  61.  
  62. rated_images = get_rated_images(catalog_file)
  63.  
  64. files_to_backup = [image[3] for image in rated_images]
  65.  
  66. # Create a temporary file with the list of files
  67. with open('files_to_backup.txt', 'w') as f:
  68. f.write('\n'.join(files_to_backup))
  69.  
  70. # Invoke borgbackup
  71. call(['borg', 'create', '--files-from', 'files_to_backup.txt', f'{repo_path}::{backup_name}', '.'])
  72.  
  73. # Remove the temporary file
  74. os.remove('files_to_backup.txt')
  75.  
  76. if __name__ == "__main__":
  77. main()
  78. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement