Skip to content

Commit

Permalink
Fixed file encoding bug. While writing up documentation, found out th…
Browse files Browse the repository at this point in the history
…at assumed file encoding is "Windows Latin 1" instead of "UTF-8". UTF-8 can also be used, but the implied file extension is "m3u8". Encoding can now be toggled via new "UseM3U8" boolean user default, which also determines the proper file extension to use. However, depending on your specific use case, you can override the file extension with the new "M3UPlaylistFileExtension" user default. Bumped version to 1.3.4.
  • Loading branch information
znek committed Jan 14, 2015
1 parent a2ac003 commit 2eea899
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>iTunesFS version 1.3.3, Copyright 2007-2015 Mulle kybernetiK.</string>
<string>iTunesFS version 1.3.4, Copyright 2007-2015 Mulle kybernetiK.</string>
<key>CFBundleIconFile</key>
<string>iTunesFS</string>
<key>CFBundleIdentifier</key>
Expand All @@ -19,11 +19,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.3</string>
<string>1.3.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3.3</string>
<string>1.3.4</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSUIElement</key>
Expand Down Expand Up @@ -54,6 +54,8 @@
<string>%(artist) / %(album) / %(trackNumber#00) %(name).%(ext.lowercaseString)</string>
<key>M3UTrackFormat</key>
<string>%(name)</string>
<key>UseM3U8</key>
<false/>
<key>ShowFormatFiles</key>
<true/>
<key>SymbolicLinks</key>
Expand Down
2 changes: 1 addition & 1 deletion Version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MAJOR_VERSION=1
MINOR_VERSION=3
SUBMINOR_VERSION=3
SUBMINOR_VERSION=4
1 change: 1 addition & 0 deletions iTunesFSInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PlaylistsTrackFormat = "%(playlistNumber#000) %(name).%(ext)";
"PlaylistsTrackFormat[folders]" = "%(artist) / %(album) / %(trackNumber#00) %(name).%(ext.lowercaseString)";
M3UTrackFormat = "%(name)";
UseM3U8 = NO;
ShowFormatFiles = YES;
};
}
3 changes: 3 additions & 0 deletions iTunesM3UPlaylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
- (NSString *)name;
- (NSString *)fileName;

- (NSString *)fileExtension;
- (NSStringEncoding)fileEncoding;

@end /* iTunesM3UPlaylist */

#endif /* __iTunesFS_iTunesM3UPlaylist_H */
26 changes: 24 additions & 2 deletions iTunesM3UPlaylist.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF

@implementation iTunesM3UPlaylist

static BOOL useM3U8 = NO;
static NSString *fileExt = nil;

+ (void)initialize {
static BOOL didInit = NO;
if (didInit) return;
didInit = YES;

NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
useM3U8 = [ud boolForKey:@"UseM3U8"];
fileExt = [ud stringForKey:@"M3UPlaylistFileExtension"];
}

- (id)initWithPlaylist:(iTunesPlaylist *)_playlist
useRelativePaths:(BOOL)_useRelativePaths
{
Expand All @@ -61,9 +74,18 @@ - (NSString *)name {
return [self->playlist name];
}
- (NSString *)fileName {
return [[[self name] stringByAppendingPathExtension:@"m3u"]
return [[[self name] stringByAppendingPathExtension:[self fileExtension]]
properlyEscapedFSRepresentation];
}
- (NSString *)fileExtension {
if (fileExt)
return fileExt;
return useM3U8 ? @"m3u8" : @"m3u";
}
- (NSStringEncoding)fileEncoding {
return useM3U8 ? NSUTF8StringEncoding : NSWindowsCP1252StringEncoding;
}

- (NSArray *)tracks {
return self->useRelativePaths ? [self->playlist tracks]
: [self->playlist allTracks];
Expand Down Expand Up @@ -121,7 +143,7 @@ - (NSData *)fileContents {
[rep appendString:location];
[rep appendString:@"\n"];
}
NSData *d = [rep dataUsingEncoding:NSUTF8StringEncoding];
NSData *d = [rep dataUsingEncoding:[self fileEncoding]];
[rep release];
[formatter release];
return d;
Expand Down

0 comments on commit 2eea899

Please sign in to comment.