Skip to content
This repository has been archived by the owner on Nov 24, 2019. It is now read-only.

Commit

Permalink
Regex replace on audio files metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilalh committed Jul 5, 2014
1 parent 8a1335b commit 20560f6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -13,6 +13,7 @@ Version 1.8
* Artist to composer.
* Composer to artist.
* Save last custom format.
* Regex replace on audio files metadata.

### Improvements ###
* Improvements to the auto taggering gui.
Expand Down
2 changes: 2 additions & 0 deletions Classes/Main/MainController.h
Expand Up @@ -38,7 +38,9 @@
IBOutlet NSMenu *whitespaceMenu;
IBOutlet NSMenu *deleteMenu;
IBOutlet NSMenu *swapMenu;
IBOutlet NSMenu *regexMenu;



IBOutlet NSSplitView *splitView;
IBOutlet NSView *leftSplitView;
Expand Down
56 changes: 55 additions & 1 deletion Classes/Main/MainController.m
Expand Up @@ -35,7 +35,7 @@
static const NSArray *tagMenuValues;
static const NSArray *deleteMenuValues;
static const NSArray *swapMenuValues;

static const NSArray *regexMenuValues;

@implementation FileSystemNode (QLPreviewItem)

Expand Down Expand Up @@ -802,6 +802,55 @@ - (IBAction)artistToComposer:(id)sender
}];
}


- (IBAction)regexReplace:(id)sender
{
NSTextField *regex = [[NSTextField alloc] initWithFrame:NSMakeRect(90, 30, 200, 22)];
NSTextField *lregex = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 30, 90, 22)];
[lregex setStringValue:@"Regex:"];
[lregex setBezeled:NO];
[lregex setDrawsBackground:NO];
[lregex setEditable:NO];
[lregex setSelectable:NO];

NSTextField *replace = [[NSTextField alloc] initWithFrame:NSMakeRect(90, 0, 200, 22)];
NSTextField *lreplace = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 90, 22)];
[lreplace setStringValue:@"Replacement:"];
[lreplace setBezeled:NO];
[lreplace setDrawsBackground:NO];
[lreplace setEditable:NO];
[lreplace setSelectable:NO];



NSAlert *alert = [NSAlert new];
NSView* tmpView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 300, 60)];
[tmpView addSubview:lregex];
[tmpView addSubview:regex];
[tmpView addSubview:lreplace];
[tmpView addSubview:replace];

[alert addButtonWithTitle:@"Replace"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Regex replace"];
[alert setInformativeText:@"Replace the substring matching Regex: with Replacement:. Using $1, etc for matched groups"];
[alert setAccessoryView:tmpView];
[alert setAlertStyle:NSWarningAlertStyle];

[alert beginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSAlertFirstButtonReturn){
[self performBlockOnTags:sender tagNames:tagMenuValues block:^id (id value, NSString *tagName, Tags *tags) {
NSString *s = value;
return [s stringByReplacingOccurrencesOfRegex:[regex stringValue] withString:[replace stringValue]];
}];

}
}];


}


- (IBAction)performBlockOnTags:(id)sender
tagNames:(const NSArray*)tagNames
block:(id (^)(id value, NSString *tagName, Tags *tags ))block
Expand Down Expand Up @@ -1211,6 +1260,7 @@ - (void) initTagManipulationSubMenus
makeMenu(tagMenuValues, whitespaceMenu, @selector(trimWhitespace:));
makeMenu(deleteMenuValues, deleteMenu, @selector(deleteTag:));
makeMenu(swapMenuValues, swapMenu, @selector(swapFirstAndLastName:));
makeMenu(regexMenuValues, regexMenu, @selector(regexReplace:));

NSMenuItem *item = [swapMenu itemAtIndex:0];
[item setKeyEquivalent:@"p"];
Expand Down Expand Up @@ -1273,6 +1323,10 @@ + (void)initialize
tagMenuValues = [[NSArray alloc ] initWithObjects:
@"title", @"album", @"artist",@"albumArtist", @"composer", @"genre",
nil];

regexMenuValues = [[NSArray alloc ] initWithObjects:
@"title", @"album", @"artist",@"albumArtist", @"composer", @"genre",
nil];

deleteMenuValues = [[NSArray alloc ] initWithObjects:
@"title", @"album", @"artist",@"albumArtist", @"composer", @"genre", @"cover", @"comment", @"url",
Expand Down
25 changes: 15 additions & 10 deletions Classes/Main/MainMenu.xib
Expand Up @@ -466,19 +466,24 @@
</menuItem>
<menuItem title="Lower Case" id="1439">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Lower Case" id="1440">
<menu key="submenu" title="Lower Case" id="IlI-YV-KLn">
<items>
<menuItem title="All Below" tag="-1" id="1442">
<menuItem title="All Below" tag="-1" id="D9s-w2-zAy">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="lowercaseTags:" target="572" id="1446"/>
<binding destination="572" name="enabled" keyPath="currentNodes.hasBasicMetadata" id="1443"/>
<action selector="lowercaseTags:" target="572" id="jbb-mD-zSi"/>
<binding destination="572" name="enabled" keyPath="currentNodes.hasBasicMetadata" id="eVC-ob-wM8"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="1441"/>
<menuItem isSeparatorItem="YES" id="R9x-hR-I1r"/>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="7RW-HR-0xT"/>
<menuItem title="Regex Replace" id="z7e-MA-SCT">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Regex Replace" id="0cq-17-iE3"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="1366"/>
<menuItem title="Trim Whitespace" id="1450">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -1043,11 +1048,11 @@
</subviews>
</customView>
<customView id="537">
<rect key="frame" x="713" y="0.0" width="391" height="480.99999981740621"/>
<rect key="frame" x="713" y="0.0" width="391" height="481"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tabView initialItem="556" id="554">
<rect key="frame" x="0.0" y="-2" width="391" height="480.99999981740621"/>
<rect key="frame" x="0.0" y="-2" width="391" height="481"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<font key="font" metaFont="system"/>
<tabViewItems>
Expand Down Expand Up @@ -1697,11 +1702,11 @@
</tabViewItem>
<tabViewItem label="Artwork" identifier="2" id="555">
<view key="view" id="564">
<rect key="frame" x="10" y="33" width="371" height="434.99999981740621"/>
<rect key="frame" x="10" y="33" width="371" height="435"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView id="977" customClass="DraggableImageView">
<rect key="frame" x="14" y="14" width="342.5" height="416"/>
<rect key="frame" x="14" y="14.000000182593652" width="342.5" height="416"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
<imageCell key="cell" selectable="YES" editable="YES" alignment="left" animates="YES" imageScaling="proportionallyDown" imageFrameStyle="grayBezel" id="978"/>
<connections>
Expand Down Expand Up @@ -1811,10 +1816,10 @@
<outlet property="downloadMenuItem" destination="1025" id="1492"/>
<outlet property="homeMenuItem" destination="1018" id="1493"/>
<outlet property="leftSplitView" destination="538" id="1472"/>
<outlet property="lowercaseMenu" destination="1440" id="1448"/>
<outlet property="movieMenuItem" destination="1031" id="1494"/>
<outlet property="musicMenuItem" destination="1029" id="1495"/>
<outlet property="popup" destination="540" id="678"/>
<outlet property="regexMenu" destination="0cq-17-iE3" id="1CQ-5z-apM"/>
<outlet property="renameMenu" destination="999" id="1301"/>
<outlet property="rightSplitView" destination="537" id="1478"/>
<outlet property="splitView" destination="536" id="1470"/>
Expand Down

0 comments on commit 20560f6

Please sign in to comment.