Skip to content

Commit

Permalink
Add legacy Metatogger scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberSinh committed Dec 24, 2015
1 parent d6cfdcd commit fd23179
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .default.csx
@@ -0,0 +1,17 @@
// Describe here what the script does

string NewValue(string oldValue)
{
return oldValue; // change here to return a custom tag value
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));

/*
"files" is the collection of audio files loaded in Metatogger
GetAllTags() returns all tags of an audio file in a Dictionary<string, List<string>> variable
SetTagValue() replace the value of a tag by a new value (returned by the NewValue() function)
*/
115 changes: 115 additions & 0 deletions .intellisense.csx
@@ -0,0 +1,115 @@
using System.Collections.ObjectModel;

//namespace Metatogger.Data
//{
public interface IAudioFile
{
string Bitrate { get; }
string BitsPerSample { get; }
byte BitsSample { get; }
string ChannelMode { get; }
byte Channels { get; }
void ClearArts();
string Codec { get; }
string CodecVersion { get; }
string Cover { get; set; }
string CoverDescription { get; }
string Duration { get; }
string ExternalCover { get; set; }
string ExternalCoverDescription { get; }
FileProcess FileProcess { get; set; }
int[] Fingerprint { get; }
string FullPath { get; }
Dictionary<string, string> GetAllFirstTagsWithExtendedMetadata();
Dictionary<string, List<string>> GetAllTags();
string GetFirstValue(string tag);
string GetPreviousTagValue(string tag);
List<string> GetValues(string tag);
bool HasChange(string tag);
bool HasChanges { get; }
bool HasCoverChanged { get; }
bool HasCoverSupport { get; }
bool HasOutputFilenameChanged { get; }
bool HasOutputPathChanged { get; }
bool HasPathChanges { get; }
bool HasPathError { get; }
bool HasTagChanges { get; }
string InputFilename { get; }
string InputPath { get; }
bool IsPlaying { get; }
int NominalBitrate { get; }
string OutputFilename { get; set; }
string OutputPath { get; set; }
string PathError { get; }
void RejectChange(string tag);
void RejectChanges();
string SampleRate { get; }
void SaveChanges();
float Seconds { get; }
string SetTag(string tag, string value, bool overwrite = true, bool addIfExists = false);
string SetTagValue(string name, string oldValue, string newValue);
int SimilarityGroupId { get; }
}

public enum FileProcess
{
Copy,
Move,
SoftLink,
Rename
}

public static class ExtendedMetadataName
{
public const string CodecVersion = "CODECVERSION";
public const string Codec = "CODEC";
public const string SampleRate = "SAMPLERATE";
public const string Duration = "DURATION";
public const string Bitrate = "BITRATE";
public const string BitsPerSample = "BITSPERSAMPLE";
public const string ChannelMode = "CHANNELMODE";
public const string Channels = "CHANNELS";
public const string Seconds = "SECONDS";
public const string TwoDigitsTrackNumber = "TWODIGITSTRACKNB";
public const string Filename = "FILENAME";
}

public static class TagName
{
public const string DefaultName = "TAGNAME";

public const string Artist = "ARTIST";
public const string Title = "TITLE";
public const string Date = "DATE";
public const string Album = "ALBUM";
public const string Genre = "GENRE";
public const string TrackNumber = "TRACKNUMBER";

public const string AlbumArtist = "ALBUMARTIST";
public const string DiscNumber = "DISCNUMBER";
public const string Lyricist = "LYRICIST";
public const string Composer = "COMPOSER";
public const string Language = "LANGUAGE";
public const string OriginalAlbum = "ORIGINALALBUM";
public const string OriginalArtist = "ORIGINALARTIST";
public const string OriginalDate = "ORIGINALDATE";
public const string AlbumSort = "ALBUMSORT";
public const string ArtistSort = "ARTISTSORT";
public const string AlbumArtistSort = "ALBUMARTISTSORT";
public const string TitleSort = "TITLESORT";
public const string Label = "LABEL";
public const string Comment = "COMMENT";
public const string Lyrics = "LYRICS";

private static readonly string[] commonTags = new[] { Artist, Title, Date, Album, Genre, TrackNumber };
private static readonly string[] uncommonTags = new[] { AlbumArtist, Lyricist, Composer, Language, DiscNumber, OriginalAlbum, OriginalArtist, OriginalDate, AlbumSort, ArtistSort, TitleSort, AlbumArtistSort, Label, Comment, Lyrics };
//private static readonly string[] fileSystem = new[] { "InputPath", "InputFilename", "OutputPath", "OutputFilename" };
//private static readonly string[] technical = new[] { "CodecVersion", "Bitrate", "SampleRate", "Duration", "BitsPerSample", "ChannelMode" };

public static readonly ReadOnlyCollection<string> CommonTags = Array.AsReadOnly(commonTags);
public static readonly ReadOnlyCollection<string> UncommonTags = Array.AsReadOnly(uncommonTags);
public static readonly ReadOnlyCollection<string> AllSupportedTags = commonTags.Concat(uncommonTags).ToList().AsReadOnly();
}
//}

var files = new List<IAudioFile>();
29 changes: 29 additions & 0 deletions Capitalize All Words.csx
@@ -0,0 +1,29 @@
// This script convert the first letter of all words in tag value to uppercase ("the artist" -> "The Artist")

using System;
using System.Text;

string NewValue(string oldValue)
{
var sb = new StringBuilder(oldValue);
if (sb.Length > 0) sb[0] = Char.ToUpper(sb[0]);

for (int i = 1; i < sb.Length; i++)
{
if (Char.IsWhiteSpace(sb[i]) || sb[i] == '-')
{
if (sb[i+1] == '(') i++;
i++;
if (i >= sb.Length) break;
sb[i] = Char.ToUpper(sb[i]);
i--;
}
}

return sb.ToString();
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
16 changes: 16 additions & 0 deletions Capitalize first letter.csx
@@ -0,0 +1,16 @@
// This script convert the first letter of tag value to uppercase ("the artist" -> "The artist")

using System;
using System.Text;

string NewValue(string oldValue)
{
var sb = new StringBuilder(oldValue);
if (sb.Length > 0) sb[0] = Char.ToUpper(sb[0]);
return sb.ToString();
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
8 changes: 8 additions & 0 deletions MAKE UPPERCASE.csx
@@ -0,0 +1,8 @@
// This script changes all tag values to uppercase ("The Artist" -> "THE ARTIST")

string NewValue(string oldValue) => oldValue.ToUpper();

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
29 changes: 27 additions & 2 deletions README.md
@@ -1,2 +1,27 @@
# scripts
C# scripts for Metatogger
# Scripts repository for Metatogger

Scripts for Metatogger are written is C# and executed by Roslyn.

Here is a basic script template:

```cs
// Describe here what the script does
string NewValue(string oldValue)
{
return oldValue; // change here to return a custom tag value
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));

/*
"files" is the collection of audio files loaded in Metatogger
GetAllTags() returns all tags of an audio file in a Dictionary<string, List<string>> variable
SetTagValue() replace the value of a tag by a new value (returned by the NewValue() function)
*/
```

Feel free to submit improvement or new script with "pull request".
12 changes: 12 additions & 0 deletions Remove from value.csx
@@ -0,0 +1,12 @@
// This script removes all tags that contains specified value

string NewValue(string oldValue)
{
string tagValueToRemove = ""; // enter here the tag value that you want to remove
return oldValue != tagValueToRemove ? oldValue : null;
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
13 changes: 13 additions & 0 deletions Search & Replace.csx
@@ -0,0 +1,13 @@
// This script replaces all occurrences of a specified string in a tag value with another specified string

string NewValue(string oldValue)
{
string changeThis = ""; // enter here what you want to search
string toThat = ""; // enter here what you want to enter
return oldValue.Replace(changeThis, toThat);
}

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
16 changes: 16 additions & 0 deletions Split track number.csx
@@ -0,0 +1,16 @@
// This script replaces track number format used in iTunes "track number/total number of tracks" ("3/10" -> "3")

using Metatogger.Data;

string NewValue(string oldValue)
{
int index = oldValue.IndexOf('/');
return index == -1 ? oldValue : oldValue.Substring(0, index);
}

foreach (var file in files)
{
string trackNumber = file.GetFirstValue(TagName.TrackNumber);
if (trackNumber != null)
file.SetTag(TagName.TrackNumber, NewValue(trackNumber));
}
8 changes: 8 additions & 0 deletions Trim white-space characters.csx
@@ -0,0 +1,8 @@
// This script removes all leading and trailing white-space characters from the tag value (" The Artist " -> "The Artist")

string NewValue(string oldValue) => oldValue.Trim();

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
10 changes: 10 additions & 0 deletions Use two digits for track number.csx
@@ -0,0 +1,10 @@
// This script add a zero in front of track number if it is less than ten

using Metatogger.Data;

foreach (var file in files)
{
string trackNumber = file.GetFirstValue(TagName.TrackNumber);
if (trackNumber != null && trackNumber.Length == 1)
file.SetTag(TagName.TrackNumber, $"0{trackNumber}");
}
8 changes: 8 additions & 0 deletions make lowercase.csx
@@ -0,0 +1,8 @@
// This script changes all tag values to lowercase ("The Artist" -> "the artist")

string NewValue(string oldValue) => oldValue.ToLower();

foreach (var file in files)
foreach (var tag in file.GetAllTags())
foreach (string tagValue in tag.Value)
file.SetTagValue(tag.Key, tagValue, NewValue(tagValue));
1 change: 1 addition & 0 deletions project.json
@@ -0,0 +1 @@
{}

0 comments on commit fd23179

Please sign in to comment.