Working file name format.

This commit is contained in:
Damiano Galassi committed 2017-12-01 13:51:20 +01:00
1 parent 5b1ee71ec0
commit aa7308d052
6 files changed
+60 -25

No files matched your search

@@ -20,7 +20,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PZS-8W-dno">
<rect key="frame" x="71" y="124" width="180" height="18"/>
<rect key="frame" x="67" y="124" width="180" height="18"/>
<buttonCell key="cell" type="check" title="Set filename of Movies to:" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="wci-gO-GWT">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@@ -30,7 +30,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TBF-BD-fSk">
<rect key="frame" x="71" y="48" width="197" height="18"/>
<rect key="frame" x="67" y="48" width="197" height="18"/>
<buttonCell key="cell" type="check" title="Set filename of TV Shows to:" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="kQC-bu-0by">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@@ -40,9 +40,9 @@
</connections>
</button>
<tokenField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="i8H-oP-Sif">
<rect key="frame" x="105" y="96" width="400" height="22"/>
<rect key="frame" x="85" y="96" width="440" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="400" id="6Ap-Ey-VHf"/>
<constraint firstAttribute="width" constant="440" id="6Ap-Ey-VHf"/>
</constraints>
<tokenFieldCell key="cell" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" drawsBackground="YES" allowsEditingTextAttributes="YES" id="h4P-Ma-djC">
<font key="font" metaFont="system"/>
@@ -50,22 +50,24 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</tokenFieldCell>
<connections>
<binding destination="BZm-iR-6oK" name="value" keyPath="values.SBMovieFormat" id="mdW-QG-L7g"/>
<outlet property="delegate" destination="-2" id="39Q-aI-o60"/>
</connections>
</tokenField>
<tokenField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rzc-AK-4Vr">
<rect key="frame" x="105" y="20" width="400" height="22"/>
<rect key="frame" x="85" y="20" width="440" height="22"/>
<tokenFieldCell key="cell" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" drawsBackground="YES" allowsEditingTextAttributes="YES" id="aHe-D5-fgj">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</tokenFieldCell>
<connections>
<binding destination="BZm-iR-6oK" name="value" keyPath="values.SBTVShowFormat" id="Fa2-rF-dBm"/>
<outlet property="delegate" destination="-2" id="mh9-CJ-zVx"/>
</connections>
</tokenField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dq1-e8-fa6">
<rect key="frame" x="507" y="89" width="50" height="32"/>
<rect key="frame" x="527" y="89" width="50" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSSmartBadgeTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="qsh-5h-jhl">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -75,7 +77,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fZZ-im-9BI">
<rect key="frame" x="507" y="13" width="50" height="32"/>
<rect key="frame" x="527" y="13" width="50" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSSmartBadgeTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="gf3-DD-hW7">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -86,13 +88,13 @@
</button>
</subviews>
<constraints>
<constraint firstItem="rzc-AK-4Vr" firstAttribute="leading" secondItem="TBF-BD-fSk" secondAttribute="leading" constant="32" id="Aws-ML-M7P"/>
<constraint firstItem="rzc-AK-4Vr" firstAttribute="leading" secondItem="TBF-BD-fSk" secondAttribute="leading" constant="16" id="Aws-ML-M7P"/>
<constraint firstItem="TBF-BD-fSk" firstAttribute="top" secondItem="i8H-oP-Sif" secondAttribute="bottom" constant="32" id="C0O-NO-8Te"/>
<constraint firstItem="dq1-e8-fa6" firstAttribute="centerY" secondItem="i8H-oP-Sif" secondAttribute="centerY" id="Dsc-lq-HSw"/>
<constraint firstItem="rzc-AK-4Vr" firstAttribute="top" secondItem="TBF-BD-fSk" secondAttribute="bottom" constant="8" id="FZZ-y5-ycJ"/>
<constraint firstItem="PZS-8W-dno" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="GYO-gT-cbH"/>
<constraint firstItem="i8H-oP-Sif" firstAttribute="top" secondItem="PZS-8W-dno" secondAttribute="bottom" constant="8" id="Mvi-1G-Dhn"/>
<constraint firstItem="i8H-oP-Sif" firstAttribute="leading" secondItem="PZS-8W-dno" secondAttribute="leading" constant="32" id="ael-zI-oHU"/>
<constraint firstItem="i8H-oP-Sif" firstAttribute="leading" secondItem="PZS-8W-dno" secondAttribute="leading" constant="16" id="ael-zI-oHU"/>
<constraint firstItem="TBF-BD-fSk" firstAttribute="leading" secondItem="PZS-8W-dno" secondAttribute="leading" id="cyH-w2-B1O"/>
<constraint firstItem="dq1-e8-fa6" firstAttribute="leading" secondItem="i8H-oP-Sif" secondAttribute="trailing" constant="8" id="dhO-Zz-g71"/>
<constraint firstItem="fZZ-im-9BI" firstAttribute="centerY" secondItem="rzc-AK-4Vr" secondAttribute="centerY" id="gzL-hH-eGN"/>
+13
View File
@@ -9,6 +9,19 @@ import Foundation
extension SBDocument: ChapterSearchControllerDelegate, MetadataSearchControllerDelegate, FileImportControllerDelegate {
// MARK: File name
@objc func preferredFileName() -> String? {
if let mediaKind = mp4.metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue,
(mediaKind == 10 && UserDefaults.standard.bool(forKey: "SBSetTVShowFormat")) ||
(mediaKind == 9 && UserDefaults.standard.bool(forKey: "SBSetMovieFormat")),
let name = mp4.formattedFileName() {
return name
} else {
return mp4.tracks.flatMap { $0.url }.first?.deletingPathExtension().lastPathComponent
}
}
// MARK: Metadata
@IBAction func searchMetadata(_ sender: Any?) {
+33
View File
@@ -64,4 +64,37 @@ extension MP42File {
}
return MetadataSearchTerms.none
}
private func outputNameFormat(mediaKind: Int) -> [String]? {
if mediaKind == 10 {
return UserDefaults.standard.stringArray(forKey: "SBTVShowFormat")
} else if mediaKind == 9 {
return UserDefaults.standard.stringArray(forKey: "SBMovieFormat")
}
return nil
}
func formattedFileName() -> String? {
guard let mediaKind = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue,
let format = outputNameFormat(mediaKind: mediaKind)
else { return nil }
let separators = CharacterSet(charactersIn: "{}")
var name = ""
for token in format {
if token.hasPrefix("{") && token.hasSuffix("}") {
let trimmedToken = token.trimmingCharacters(in: separators)
let metadataItems = metadata.metadataItemsFiltered(byIdentifier: trimmedToken)
if let string = metadataItems.first?.stringValue {
name.append(string)
}
} else {
name.append(token)
}
}
return name.isEmpty ? nil : name
}
}
-7
View File
@@ -35,13 +35,6 @@ class OutputPrefsViewController: NSViewController, NSTokenFieldDelegate {
movieField.tokenizingCharacterSet = CharacterSet(charactersIn: "%")
tvShowField.tokenizingCharacterSet = CharacterSet(charactersIn: "%")
if let movieFormat = UserDefaults.standard.string(forKey: "SBMovieFormat") {
movieField.stringValue = movieFormat
}
if let tvShowFormat = UserDefaults.standard.string(forKey: "SBTVShowFormat") {
tvShowField.stringValue = tvShowFormat
}
}
// MARK: Actions
+2 -2
View File
@@ -38,8 +38,8 @@ import Cocoa
"chaptersPreviewTrack": true,
"SBChaptersPreviewPosition": 0.5,
"SBMovieFormat": "%{Name}",
"SBTVShowFormat": "%{TV Show}% s%{TV Season}%e%{TV Episode #}",
"SBMovieFormat": ["{Name}"],
"SBTVShowFormat": ["{TV Show}"," s", "{TV Season}", "e", "{TV Episode #}"],
"SBSetMovieFormat": false,
"SBSetTVShowFormat": false,
+1 -7
View File
@@ -379,13 +379,7 @@ static NSDictionary *_detailMonospacedAttr;
_currentSavePanel.allowedFileTypes = @[[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSaveFormat"]];
}
NSString *filename = nil;
for (MP42Track *track in self.mp4.tracks) {
if (track.URL) {
filename = track.URL.lastPathComponent.stringByDeletingPathExtension;
break;
}
}
NSString *filename = [self preferredFileName];
if (filename) {
savePanel.nameFieldStringValue = filename;