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

Add Support for Popularimeter #28

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions src/Id3.Net.Serialization/SerializationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
*/
#endregion

using System;
using System.Runtime.Serialization;
using Id3.Frames;
using Id3.Serialization.Surrogates;
using System;
using System.Runtime.Serialization;

namespace Id3.Serialization
{
Expand Down Expand Up @@ -101,6 +101,7 @@ public static TFormatter IncludeId3SerializationSupport<TFormatter>(this TFormat
selector.AddFrameSurrogate<PictureFrame, PictureFrameSurrogate>();
selector.AddFrameSurrogate<PrivateFrame, PrivateFrameSurrogate>();
selector.AddFrameSurrogate<UnknownFrame, UnknownFrameSurrogate>();
selector.AddFrameSurrogate<PopularimeterFrame, PopularimeterFrameSurrogate>();

formatter.SurrogateSelector = selector;
return formatter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#region --- License & Copyright Notice ---
/*
Copyright (c) 2005-2018 Jeevan James
All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion

using Id3.Frames;
using System.Runtime.Serialization;

namespace Id3.Serialization.Surrogates
{
internal sealed class PopularimeterFrameSurrogate : Id3FrameSurrogate<PopularimeterFrame>
{
protected override void GetFrameData(PopularimeterFrame frame, SerializationInfo info, StreamingContext context)
{
//info.AddValue("EncodingType", frame.EncodingType);
info.AddValue(nameof(PopularimeterFrame.RatingRaw), frame.RatingRaw);
info.AddValue(nameof(PopularimeterFrame.Email), "ID3.NET"); //todo revisit
info.AddValue(nameof(PopularimeterFrame.PlayCounter), frame.PlayCounter);
}

protected override PopularimeterFrame SetObjectData(PopularimeterFrame frame, SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
//frame.EncodingType = (Id3TextEncoding)info.GetByte("EncodingType");
frame.Rating = (Rating)info.GetByte(nameof(PopularimeterFrame.RatingRaw));
frame.PlayCounter = info.GetInt32(nameof(PopularimeterFrame.PlayCounter));
frame.Email = info.GetString(nameof(PopularimeterFrame.Email));
return frame;
}
}
}
38 changes: 38 additions & 0 deletions src/Id3.Net/Frames/Others/PopularimeterFrame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Id3.Frames
{
public sealed class PopularimeterFrame : Id3Frame
{
public override bool IsAssigned => RatingRaw != 0;

public byte RatingRaw => (byte)Rating;

public Rating Rating { get; set; }

public string Email { get; set; }

public long PlayCounter { get; set; }

public PopularimeterFrame() { }

public PopularimeterFrame(Rating rating)
{
Rating = rating;
}
}

public enum Rating
{
NotRated = 0,
OneStar = 1,
TwoStars = 64,
ThreeStars = 128,
FourStars = 196,
FiveStars = 255
}
}
13 changes: 12 additions & 1 deletion src/Id3.Net/Id3/Id3Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
*/
#endregion

using Id3.Frames;
using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -25,7 +26,6 @@ limitations under the License.
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Id3.Frames;

namespace Id3
{
Expand Down Expand Up @@ -419,6 +419,17 @@ public YearFrame Year
get => GetSingleFrame<YearFrame>();
set => SetSingleFrame(value);
}

public PopularimeterFrame Popularimeter
{
//todo revisit
//http://id3.org/id3v2.4.0-frames
//4.17. Popularimeter
//There may be more than one "POPM" frame in each tag, but only one with the same
//email address.
get => GetSingleFrame<PopularimeterFrame>();
set => SetSingleFrame(value);
}
#endregion

#region Frame internals
Expand Down
Loading