Skip to content

Commit c1cceb4

Browse files
committed
feat: support year-month folder structure for photo backup/folders (fixes #262)
1 parent ba3730d commit c1cceb4

File tree

3 files changed

+155
-7
lines changed

3 files changed

+155
-7
lines changed

Localizable.xcstrings

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,74 @@
11401140
}
11411141
}
11421142
},
1143+
"2024-08/IMG_2020.HEIC" : {
1144+
"localizations" : {
1145+
"de" : {
1146+
"stringUnit" : {
1147+
"state" : "translated",
1148+
"value" : "2024-08/IMG_2020.HEIC"
1149+
}
1150+
},
1151+
"es" : {
1152+
"stringUnit" : {
1153+
"state" : "translated",
1154+
"value" : "2024-08/IMG_2020.HEIC"
1155+
}
1156+
},
1157+
"it" : {
1158+
"stringUnit" : {
1159+
"state" : "translated",
1160+
"value" : "2024-08/IMG_2020.HEIC"
1161+
}
1162+
},
1163+
"nl" : {
1164+
"stringUnit" : {
1165+
"state" : "translated",
1166+
"value" : "2024-08/IMG_2020.HEIC"
1167+
}
1168+
},
1169+
"uk" : {
1170+
"stringUnit" : {
1171+
"state" : "translated",
1172+
"value" : "2024-08/IMG_2020.HEIC"
1173+
}
1174+
}
1175+
}
1176+
},
1177+
"2024-08/Video/IMG_2020.MOV" : {
1178+
"localizations" : {
1179+
"de" : {
1180+
"stringUnit" : {
1181+
"state" : "translated",
1182+
"value" : "2024-08/Video/IMG_2020.MOV"
1183+
}
1184+
},
1185+
"es" : {
1186+
"stringUnit" : {
1187+
"state" : "translated",
1188+
"value" : "2024-08/Video/IMG_2020.MOV"
1189+
}
1190+
},
1191+
"it" : {
1192+
"stringUnit" : {
1193+
"state" : "translated",
1194+
"value" : "2024-08/Video/IMG_2020.MOV"
1195+
}
1196+
},
1197+
"nl" : {
1198+
"stringUnit" : {
1199+
"state" : "translated",
1200+
"value" : "2024-08/Video/IMG_2020.MOV"
1201+
}
1202+
},
1203+
"uk" : {
1204+
"stringUnit" : {
1205+
"state" : "translated",
1206+
"value" : "2024-08/Video/IMG_2020.MOV"
1207+
}
1208+
}
1209+
}
1210+
},
11431211
"2024/08/11/IMG_2020.HEIC" : {
11441212
"localizations" : {
11451213
"de" : {
@@ -25342,6 +25410,74 @@
2534225410
}
2534325411
}
2534425412
},
25413+
"Year-month" : {
25414+
"localizations" : {
25415+
"de" : {
25416+
"stringUnit" : {
25417+
"state" : "translated",
25418+
"value" : "Jahr-Monat"
25419+
}
25420+
},
25421+
"es" : {
25422+
"stringUnit" : {
25423+
"state" : "translated",
25424+
"value" : "Año-mes"
25425+
}
25426+
},
25427+
"it" : {
25428+
"stringUnit" : {
25429+
"state" : "translated",
25430+
"value" : "Anno-mese"
25431+
}
25432+
},
25433+
"nl" : {
25434+
"stringUnit" : {
25435+
"state" : "translated",
25436+
"value" : "Jaar-maand"
25437+
}
25438+
},
25439+
"uk" : {
25440+
"stringUnit" : {
25441+
"state" : "translated",
25442+
"value" : "Рік-місяць"
25443+
}
25444+
}
25445+
}
25446+
},
25447+
"Year-month/Type" : {
25448+
"localizations" : {
25449+
"de" : {
25450+
"stringUnit" : {
25451+
"state" : "translated",
25452+
"value" : "Jahr-Monat/Typ"
25453+
}
25454+
},
25455+
"es" : {
25456+
"stringUnit" : {
25457+
"state" : "translated",
25458+
"value" : "Año-mes/Tipo"
25459+
}
25460+
},
25461+
"it" : {
25462+
"stringUnit" : {
25463+
"state" : "translated",
25464+
"value" : "Anno-mese/Tipo"
25465+
}
25466+
},
25467+
"nl" : {
25468+
"stringUnit" : {
25469+
"state" : "translated",
25470+
"value" : "Jaar-maand/Type"
25471+
}
25472+
},
25473+
"uk" : {
25474+
"stringUnit" : {
25475+
"state" : "translated",
25476+
"value" : "Рік-місяць/Тип"
25477+
}
25478+
}
25479+
}
25480+
},
2534525481
"Year/Month" : {
2534625482
"localizations" : {
2534725483
"de" : {

Sushitrain/PhotoBackup.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum PhotoBackupFolderStructure: String, Codable {
4646
case byYear = "byYear"
4747
case byYearAndType = "byYearAndType"
4848
case byYearMonth = "byYearMonth"
49+
case byYearDashMonth = "byYearDashMonth"
50+
case byYearDashMonthAndType = "byYearDashMonthAndType"
4951
case byYearMonthAndType = "byYearMonthAndType"
5052
case singleFolder = "singleFolder"
5153
case singleFolderDatePrefixed = "singleFolderDatePrefixed"
@@ -60,6 +62,8 @@ enum PhotoBackupFolderStructure: String, Codable {
6062
case .byYearAndType: return String(localized: "2024/Video/IMG_2020.MOV")
6163
case .byYearMonth: return String(localized: "2024/08/IMG_2020.HEIC")
6264
case .byYearMonthAndType: return String(localized: "2024/08/Video/IMG_2020.MOV")
65+
case .byYearDashMonth: return String(localized: "2024-08/IMG_2020.HEIC")
66+
case .byYearDashMonthAndType: return String(localized: "2024-08/Video/IMG_2020.MOV")
6367
case .byType: return String(localized: "Video/IMG_2020.MOV")
6468
case .singleFolder: return String(localized: "IMG_2020.MOV")
6569
case .singleFolderDatePrefixed: return String(localized: "2024-08-11_IMG_2020.MOV")
@@ -69,7 +73,7 @@ enum PhotoBackupFolderStructure: String, Codable {
6973
var usesTimeZone: Bool {
7074
switch self {
7175
case .byDate, .byDateAndType, .byDateComponent, .byDateComponentAndType, .singleFolderDatePrefixed,
72-
.byYear, .byYearMonth, .byYearAndType, .byYearMonthAndType:
76+
.byYear, .byYearMonth, .byYearAndType, .byYearMonthAndType, .byYearDashMonth, .byYearDashMonthAndType:
7377
return true
7478
case .byType, .singleFolder: return false
7579
}
@@ -86,6 +90,9 @@ enum PhotoBackupFolderStructure: String, Codable {
8690
case .byYearMonth, .byYearMonthAndType:
8791
return ["yyyy", "MM"]
8892

93+
case .byYearDashMonth, .byYearDashMonthAndType:
94+
return ["yyyy-MM"]
95+
8996
case .byType, .singleFolder, .byDate, .byDateAndType, .singleFolderDatePrefixed:
9097
return []
9198
}
@@ -835,7 +842,8 @@ extension PHAsset {
835842
components.append(dateString)
836843
}
837844

838-
case .byDateComponent, .byDateComponentAndType, .byYear, .byYearMonth, .byYearAndType, .byYearMonthAndType:
845+
case .byDateComponent, .byDateComponentAndType, .byYear, .byYearMonth, .byYearAndType, .byYearMonthAndType,
846+
.byYearDashMonth, .byYearDashMonthAndType:
839847
if let creationDate = self.creationDate {
840848
let dateComponents = structure.dateComponentsForPath
841849
let dateFormatter = self.dateFormatter(timeZone: timeZone)
@@ -851,11 +859,12 @@ extension PHAsset {
851859

852860
// Postfix media type
853861
switch structure {
854-
case .byDateAndType, .byType, .byDateComponentAndType, .byYearAndType, .byYearMonthAndType:
862+
case .byDateAndType, .byType, .byDateComponentAndType, .byYearAndType, .byYearMonthAndType, .byYearDashMonthAndType:
855863
if self.mediaType == .video {
856864
components.append("Video")
857865
}
858-
case .byDate, .singleFolder, .singleFolderDatePrefixed, .byDateComponent, .byYear, .byYearMonth: break
866+
case .byDate, .singleFolder, .singleFolderDatePrefixed, .byDateComponent, .byYear, .byYearMonth, .byYearDashMonth:
867+
break
859868
}
860869

861870
return components
@@ -868,9 +877,10 @@ extension PHAsset {
868877
{
869878
var path = self.directoryPathInFolder(structure: structure, subdirectoryPath: subdirectoryPath, timeZone: timeZone)
870879
switch structure {
871-
case .byDateAndType, .byType, .byDateComponentAndType, .byYearAndType, .byYearMonthAndType:
880+
case .byDateAndType, .byType, .byDateComponentAndType, .byYearAndType, .byYearMonthAndType, .byYearDashMonthAndType:
872881
path = path.appending("Live", isDirectory: true)
873-
case .byDate, .singleFolder, .singleFolderDatePrefixed, .byDateComponent, .byYear, .byYearMonth: break
882+
case .byDate, .singleFolder, .singleFolderDatePrefixed, .byDateComponent, .byYear, .byYearMonth, .byYearDashMonth:
883+
break
874884
}
875885
return path
876886
}
@@ -888,7 +898,7 @@ extension PHAsset {
888898
func fileNameInFolder(structure: PhotoBackupFolderStructure) -> String {
889899
switch structure {
890900
case .byDate, .byDateAndType, .byDateComponent, .byDateComponentAndType, .singleFolder, .byType, .byYear,
891-
.byYearMonth, .byYearAndType, .byYearMonthAndType:
901+
.byYearMonth, .byYearAndType, .byYearMonthAndType, .byYearDashMonth, .byYearDashMonthAndType:
892902
return self.originalFilename
893903

894904
case .singleFolderDatePrefixed:

Sushitrain/PhotoBackupView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ struct PhotoFolderStructureView: View {
379379
Text("Year/Type").tag(PhotoBackupFolderStructure.byYearAndType)
380380
Text("Year/Month").tag(PhotoBackupFolderStructure.byYearMonth)
381381
Text("Year/Month/Type").tag(PhotoBackupFolderStructure.byYearMonthAndType)
382+
Text("Year-month").tag(PhotoBackupFolderStructure.byYearDashMonth)
383+
Text("Year-month/Type").tag(PhotoBackupFolderStructure.byYearDashMonthAndType)
382384
Text("Year/Month/Day").tag(PhotoBackupFolderStructure.byDateComponent)
383385
Text("Year/Month/Day/Type").tag(PhotoBackupFolderStructure.byDateComponentAndType)
384386
}

0 commit comments

Comments
 (0)