|
/*
* A Song represents a single track within a media library.
*
* Author: Phillip Piper
* Date: 8/01/2008 4:28 PM
*
* CHANGE LOG:
* 2009-03-19 JPP Added FullPath property
* 2009-02-15 JPP Removed Kind as a visible property
* 2008-01-07 JPP Initial Version
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace LyricsFetcher
{
/// <summary>
/// This enum represents the status of lyrics for a song.
/// </summary>
public enum LyricsStatus {
Success,
Failed,
GenreIgnored,
DataMissing,
Untried
}
/// <summary>
/// A Song represents a single track within a media library.
/// </summary>
abstract public class Song
{
#region Constructors
public Song()
{
}
public Song(string title, string artist, string album, string genre)
{
this.Title = title;
this.Artist = artist;
this.Album = album;
this.Genre = genre;
}
#endregion
#region Public properties
public string Album { get; set; }
public string Artist { get; set; }
public string Genre { get; set; }
public string Lyrics { get; set; }
public string Title { get; set; }
/// <summary>
/// Return the full path to the underlying media file
/// </summary>
abstract public string FullPath { get; }
/// <summary>
/// Return an enum indicating whether the lyrics of this song have been fetched
/// </summary>
public LyricsStatus LyricsStatus {
get {
if (!String.IsNullOrEmpty(this.Lyrics)) {
if (this.Lyrics.StartsWith("Failed") || this.Lyrics.StartsWith("[[LyricsFetcher failed"))
return LyricsStatus.Failed;
else
return LyricsStatus.Success;
}
if (Song.IsGenreIgnored(this.Genre))
return LyricsStatus.GenreIgnored;
if (String.IsNullOrEmpty(this.Title) || String.IsNullOrEmpty(this.Artist))
return LyricsStatus.DataMissing;
if (this.Title.StartsWith("Track ") || this.Title.StartsWith("Faixa "))
return LyricsStatus.DataMissing;
return LyricsStatus.Untried;
}
}
/// <summary>
/// Return a string indicating the status of the lyrics of this song
/// </summary>
public string LyricsStatusString {
get {
switch (this.LyricsStatus) {
case LyricsStatus.Success: return "Success";
case LyricsStatus.Failed: return "Failed";
case LyricsStatus.GenreIgnored: return "Genre ignored";
case LyricsStatus.DataMissing: return "Missing Data";
case LyricsStatus.Untried: return "Untried";
}
return "Unknown";
}
}
#endregion
#region Converters
public override string ToString() {
return string.Format("[Song Title={0} Artist={1} Album={2}]", this.Title, this.Artist, this.Album);
}
#endregion
#region Commands
abstract public void Commit();
/// <summary>
/// Songs should not load lyrics from their source until this method is called.
/// Specifically, lyrics should not be loaded in the constructor.
/// </summary>
abstract public void GetLyrics();
#endregion
#region Static DB type methods
/// <summary>
/// Each string in this list represents a genre for which lyrics should
/// never be fetched.
/// </summary>
static public List<string> GenresToIgnore = new List<String>();
static public bool IsGenreIgnored(string genre)
{
return Song.GenresToIgnore.Contains(genre);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Phillip has been playing with computers since the Apple II was the hottest home computer available. He learned the fine art of C programming and Guru meditation on the Amiga.
C# and Python are his languages of choice. Smalltalk is his mentor for simplicity and beauty. C++ is to programming what drills are to visits to the dentist.
He worked for longer than he cares to remember as Lead Programmer and System Architect of the Objective document management system. (www.objective.com)
He has lived for 10 years in northern Mozambique, teaching in villages.
He has developed high volume trading software, low volume FX trading software, and is currently working for Atlassian on HipChat.