Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play order sync pattern from playlist #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Resources/syncpatterns.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<SyncPatternCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SyncPatterns>
<SyncPattern>
<Identifier>playorder-flat</Identifier>
<Name># Title - Artist</Name>
<Pattern>%TRACKNUMINPLAYLIST% - %NAME% - %ARTIST%</Pattern>
<Description>This pattern appends the track position according to playlist and then places the tracks in a flat folder.</Description>
<!-- <CompilationsPattern>%TRACKNUMINPLAYLIST% - %NAME% - %ARTIST%</CompilationsPattern> -->
<CompilationsPattern />
</SyncPattern>
<SyncPattern>
<Identifier>itunes-style</Identifier>
<Name>Artist\Album\Track</Name>
<Pattern>%ARTIST%\%ALBUM%\%TRACKNUMSPACE%%NAME%</Pattern>
Expand Down
21 changes: 20 additions & 1 deletion SyncPatternTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SyncPatternTranslator
/// %ALBUM% = The album name
/// %ALBUMINITIAL% = The album initial
/// %NAME% = The track name
/// %TRACKNUMINPLAYLIST% = Play order index from playlist with leading zero
/// %TRACKNUMSPACE% = The track number with a trailing space
/// %TRACKNUM% = The track number (no trailing space)
/// %DISCNUMDASH% = The disc number with a trailing minus and space
Expand All @@ -46,6 +47,7 @@ public static string Translate(SyncPattern pattern, IITFileOrCDTrack track)

patternstring = TranslateArtist(pattern, track, patternstring);
patternstring = TranslateArtistInitial(pattern, track, patternstring);
patternstring = TranslateTrackNumberInPlaylist(track, patternstring);
patternstring = TranslateAlbumArtist(pattern, track, patternstring);
patternstring = TranslateDiscNumber(track, patternstring);
patternstring = TranslateAlbum(track.Album, patternstring);
Expand Down Expand Up @@ -82,6 +84,23 @@ private static string TranslateArtistInitial(SyncPattern pattern, IITFileOrCDTra
return patternstring;
}

/// <summary>
/// Translate track playorder index from playlist.
/// </summary>
/// <param name="track"></param>
/// <param name="patternstring"></param>
/// <returns></returns>
private static string TranslateTrackNumberInPlaylist(IITFileOrCDTrack track, string patternstring)
{
//%TRACKNUMINPLAYLIST%
patternstring = patternstring.Replace("%TRACKNUMINPLAYLIST%",
(track.PlayOrderIndex.ToString().Length == 1 ? "00" + track.PlayOrderIndex.ToString()
: track.PlayOrderIndex.ToString().Length == 2 ? "0" + track.PlayOrderIndex.ToString()
: track.PlayOrderIndex.ToString())
);
return patternstring;
}

/// <summary>
/// Translate file extension.
/// </summary>
Expand Down Expand Up @@ -215,4 +234,4 @@ private static string TranslateDiscNumber(IITFileOrCDTrack track, string pattern
}

}
}
}