public NameChangeRule(SongAttributes attributes, string newName)
            : base(attributes, SongRuleType.NameChange) {
            if(string.IsNullOrEmpty(newName)) {
                throw new ArgumentException("NewName");
            }

            NewName = newName;
        }
Exemplo n.º 2
0
        // TODO: async Task
        public SongAttributes GetSong(int id)
        {
            // Artist and song name
            var responseContent = this.ReadTextResponse(string.Format(SongInfoUrlFormat, id));
            var songTitle       =
                responseContent.GetStringBetween(@"<td class=biggerblue height=30 valign=top>", "</td>")
                .StripHtmlTags()
                .Trim();

            var songArtist =
                responseContent.GetStringBetween(@"<td height=20 colspan=2 valign=top><font color=586973>", "</td>")
                .StripHtmlTags()
                .Trim();

            if (string.IsNullOrWhiteSpace(songTitle) || string.IsNullOrWhiteSpace(songArtist))
            {
                return(null);
            }

            var attributes = new SongAttributes
            {
                [SongMetadataType.Title]  = songTitle,
                [SongMetadataType.Artist] = songArtist,
            };

            // YouTube video
            var videoResponseContent = this.ReadTextResponse(string.Format(SongVideoUrlFormat, id));

            if (videoResponseContent.Contains("<meta property=\"og:video\" content=\"http://www.youtube.com/v/") &&
                videoResponseContent.Contains("?autohide=1&version=3"))
            {
                var youTubeVideoId = videoResponseContent.GetStringBetween(
                    "<meta property=\"og:video\" content=\"http://www.youtube.com/v/",
                    "?autohide=1&version=3");
                if (!string.IsNullOrWhiteSpace(youTubeVideoId))
                {
                    attributes[SongMetadataType.YouTubeVideoId] = youTubeVideoId;
                }
            }

            // Lyrics
            var lyricsResponseContent = this.ReadTextResponse(string.Format(SongLyricsUrlFormat, id));

            if (lyricsResponseContent.Contains("<div style='padding: 10px; ' class=\"translate\" >"))
            {
                var lyrics = lyricsResponseContent.GetStringBetween(
                    "<div style='padding: 10px; ' class=\"translate\" >",
                    "</div>");
                if (!string.IsNullOrWhiteSpace(lyrics))
                {
                    attributes[SongMetadataType.Lyrics] = lyrics.Replace("\r", string.Empty)
                                                          .Replace("<br>\n", Environment.NewLine).StripHtmlTags().Replace("\\'", "'")
                                                          .Replace("\\\"", "\"").Trim();
                }
            }

            return(attributes);
        }
Exemplo n.º 3
0
        public async Task AddMetadataInfoAsync(int songId, SongAttributes songAttributes, string sourceName, string sourceItemId)
        {
            var sourceId = this.sourcesRepository.All().FirstOrDefault(x => x.Name == sourceName)?.Id;

            foreach (var metadata in songAttributes.Where(x => x.Key != SongMetadataType.Artist && x.Key != SongMetadataType.Title))
            {
                foreach (var value in metadata.Value)
                {
                    var songMetadata = new SongMetadata
                    {
                        SongId       = songId,
                        Type         = metadata.Key,
                        Value        = value,
                        SourceId     = sourceId,
                        SourceItemId = sourceItemId,
                    };
                    await this.songMetadataRepository.AddAsync(songMetadata);
                }
            }

            await this.songMetadataRepository.SaveChangesAsync();
        }
Exemplo n.º 4
0
 public SongRule(SongAttributes attributes, SongRuleType type) {
     Attributes = attributes;
     Type = type;
 }
Exemplo n.º 5
0
 public ExcludeRule(SongAttributes attributes)
     : base(attributes, SongRuleType.Exclude)
 {
 }