Beispiel #1
0
        public override bool UpdateTitle(TAG_INFO tag, string url)
        {
            if (tag == null)
            {
                this.v2SongTitleNext = string.Empty;
                return(false);
            }
            if (!string.IsNullOrEmpty(url))
            {
                url = url.Trim(new char[1]).Replace('\0', ' ');
            }
            if (!base.UseBASS || !this.IsConnected)
            {
                string text = base.SongTitle;
                if (string.IsNullOrEmpty(text))
                {
                    text = tag.ToString();
                }
                return(this.SHOUTcastUpdateTitle(text, url));
            }
            if (this.UseSHOUTcastv2)
            {
                try
                {
                    StringWriterWithEncoding stringWriterWithEncoding = new StringWriterWithEncoding(Encoding.UTF8);
                    using (XmlWriter xmlWriter = XmlWriter.Create(stringWriterWithEncoding, new XmlWriterSettings
                    {
                        Encoding = stringWriterWithEncoding.Encoding,
                        IndentChars = string.Empty,
                        Indent = false,
                        NewLineHandling = NewLineHandling.None,
                        NewLineChars = string.Empty,
                        CheckCharacters = false
                    }))
                    {
                        xmlWriter.WriteStartElement("metadata");
                        if (this.v2SendSongTitleOnly)
                        {
                            if (string.IsNullOrEmpty(base.SongTitle))
                            {
                                xmlWriter.WriteElementString("TIT2", tag.ToString());
                            }
                            else
                            {
                                xmlWriter.WriteElementString("TIT2", base.SongTitle);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(tag.artist))
                            {
                                xmlWriter.WriteElementString("TIT2", tag.title);
                                xmlWriter.WriteElementString("TPE1", tag.artist);
                            }
                            else
                            {
                                xmlWriter.WriteElementString("TIT2", tag.ToString());
                            }
                            if (!string.IsNullOrEmpty(tag.album))
                            {
                                xmlWriter.WriteElementString("TALB", tag.album);
                            }
                            if (!string.IsNullOrEmpty(tag.albumartist))
                            {
                                xmlWriter.WriteElementString("TPE2", tag.albumartist);
                            }
                            if (!string.IsNullOrEmpty(tag.genre))
                            {
                                xmlWriter.WriteElementString("TCON", tag.genre);
                            }
                            if (!string.IsNullOrEmpty(tag.year))
                            {
                                xmlWriter.WriteElementString("TYER", tag.year);
                            }
                            if (!string.IsNullOrEmpty(tag.copyright))
                            {
                                xmlWriter.WriteElementString("TCOP", tag.copyright);
                            }
                            if (!string.IsNullOrEmpty(tag.publisher))
                            {
                                xmlWriter.WriteElementString("TPUB", tag.publisher);
                            }
                            if (!string.IsNullOrEmpty(tag.composer))
                            {
                                xmlWriter.WriteElementString("TCOM", tag.composer);
                            }
                            if (!string.IsNullOrEmpty(tag.conductor))
                            {
                                xmlWriter.WriteElementString("TPE3", tag.conductor);
                            }
                            if (!string.IsNullOrEmpty(tag.remixer))
                            {
                                xmlWriter.WriteElementString("TPE4", tag.remixer);
                            }
                            if (!string.IsNullOrEmpty(tag.lyricist))
                            {
                                xmlWriter.WriteElementString("TEXT", tag.lyricist);
                            }
                            if (!string.IsNullOrEmpty(tag.isrc))
                            {
                                xmlWriter.WriteElementString("TSRC", tag.isrc);
                            }
                            if (!string.IsNullOrEmpty(tag.producer))
                            {
                                xmlWriter.WriteStartElement("IPLS");
                                xmlWriter.WriteAttributeString("role", "producer");
                                xmlWriter.WriteString(tag.producer);
                                xmlWriter.WriteEndElement();
                            }
                            if (!string.IsNullOrEmpty(tag.grouping))
                            {
                                xmlWriter.WriteElementString("TIT1", tag.grouping);
                            }
                            if (!string.IsNullOrEmpty(this.StationName))
                            {
                                xmlWriter.WriteElementString("TRSN", this.StationName);
                            }
                            xmlWriter.WriteElementString("TENC", BassNet.InternalName + " (Broadcast Framework)");
                            if (!string.IsNullOrEmpty(url))
                            {
                                xmlWriter.WriteElementString("WOAF", url);
                            }
                            if (!string.IsNullOrEmpty(this.Url))
                            {
                                xmlWriter.WriteElementString("WORS", this.Url);
                            }
                        }
                        if (this.v2SongTitleNext != null)
                        {
                            xmlWriter.WriteStartElement("extension");
                            xmlWriter.WriteStartElement("title");
                            xmlWriter.WriteAttributeString("seq", "1");
                            if (string.IsNullOrEmpty(base.SongTitle))
                            {
                                xmlWriter.WriteString(tag.ToString());
                            }
                            else
                            {
                                xmlWriter.WriteString(base.SongTitle);
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteStartElement("title");
                            xmlWriter.WriteAttributeString("seq", "2");
                            xmlWriter.WriteString(this.v2SongTitleNext);
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteElementString("soon", this.v2SongTitleNext);
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.Flush();
                    }
                    bool result = BassEnc.BASS_Encode_CastSendMeta(base.Encoder.EncoderHandle, BASSEncodeMetaDataType.BASS_METADATA_XML_SHOUTCAST, stringWriterWithEncoding.ToString());
                    if (this.v2SendArtwork)
                    {
                        Task.Factory.StartNew(delegate()
                        {
                            try
                            {
                                BASSEncodeMetaDataType bassencodeMetaDataType = (BASSEncodeMetaDataType)0;
                                TagPicture tagPicture = null;
                                byte[] array          = null;
                                if (tag.PictureCount > 0)
                                {
                                    tagPicture = tag.PictureGet(0);
                                }
                                if (tagPicture == null && !string.IsNullOrEmpty(this.v2StreamArtwork))
                                {
                                    tagPicture = new TagPicture(this.v2StreamArtwork, TagPicture.PICTURE_TYPE.Location, this.StationName);
                                }
                                if (tagPicture != null)
                                {
                                    tagPicture = new TagPicture(tagPicture, 300);
                                    if (tagPicture.PictureStorage == TagPicture.PICTURE_STORAGE.Internal)
                                    {
                                        if (tagPicture.Data.Length <= 523680)
                                        {
                                            array = tagPicture.Data;
                                        }
                                    }
                                    else
                                    {
                                        try
                                        {
                                            using (Stream stream = new FileStream(Encoding.UTF8.GetString(tagPicture.Data), FileMode.Open, FileAccess.Read))
                                            {
                                                if (stream.Length <= 523680L)
                                                {
                                                    byte[] array2 = new byte[stream.Length];
                                                    stream.Read(array2, 0, (int)stream.Length);
                                                    array = array2;
                                                }
                                                stream.Close();
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    string mimetype = tagPicture.MIMEType;
                                    if (!(mimetype == "image/jpeg"))
                                    {
                                        if (!(mimetype == "image/bmp"))
                                        {
                                            if (!(mimetype == "image/png"))
                                            {
                                                if (mimetype == "image/gif")
                                                {
                                                    bassencodeMetaDataType = BASSEncodeMetaDataType.BASS_METADATA_BIN_ALBUMART_GIF;
                                                }
                                            }
                                            else
                                            {
                                                bassencodeMetaDataType = BASSEncodeMetaDataType.BASS_METADATA_BIN_ALBUMART_PNG;
                                            }
                                        }
                                        else
                                        {
                                            bassencodeMetaDataType = BASSEncodeMetaDataType.BASS_METADATA_BIN_ALBUMART_BMP;
                                        }
                                    }
                                    else
                                    {
                                        bassencodeMetaDataType = BASSEncodeMetaDataType.BASS_METADATA_BIN_ALBUMART_JPG;
                                    }
                                }
                                if (bassencodeMetaDataType > (BASSEncodeMetaDataType)0 && array != null)
                                {
                                    BassEnc.BASS_Encode_CastSendMeta(this.Encoder.EncoderHandle, bassencodeMetaDataType, array);
                                }
                            }
                            catch
                            {
                            }
                        });
                    }
                    this.v2SongTitleNext = string.Empty;
                    return(result);
                }
                catch
                {
                    return(false);
                }
            }
            if (base.ForceUTF8TitleUpdates)
            {
                string text2 = base.SongTitle;
                if (string.IsNullOrEmpty(text2))
                {
                    text2 = tag.ToString();
                }
                this.v2SongTitleNext = string.Empty;
                bool flag = BassEnc.BASS_Encode_CastSetTitle(base.Encoder.EncoderHandle, Encoding.UTF8.GetBytes(text2 + "\0"), string.IsNullOrEmpty(url) ? null : Encoding.UTF8.GetBytes(url + "\0"));
                if (!flag)
                {
                    flag = this.SHOUTcastUpdateTitle(text2, url);
                }
                return(flag);
            }
            string text3 = base.SongTitle;

            if (string.IsNullOrEmpty(text3))
            {
                text3 = tag.ToString();
            }
            this.v2SongTitleNext = string.Empty;
            bool flag2 = BassEnc.BASS_Encode_CastSetTitle(base.Encoder.EncoderHandle, this._encoding.GetBytes(text3 + "\0"), string.IsNullOrEmpty(url) ? null : this._encoding.GetBytes(url + "\0"));

            if (!flag2)
            {
                flag2 = this.SHOUTcastUpdateTitle(text3, url);
            }
            return(flag2);
        }
Beispiel #2
0
        public override bool UpdateTitle(string song, string url)
        {
            if (song == null)
            {
                base.SongTitle = string.Empty;
            }
            else
            {
                base.SongTitle = song.Trim(new char[1]).Replace('\0', ' ');
            }
            if (!string.IsNullOrEmpty(url))
            {
                url = url.Trim(new char[1]).Replace('\0', ' ');
            }
            if (string.IsNullOrEmpty(base.SongTitle))
            {
                this.v2SongTitleNext = string.Empty;
            }
            if (!base.UseBASS || !this.IsConnected)
            {
                return(this.SHOUTcastUpdateTitle(base.SongTitle, url));
            }
            if (this.UseSHOUTcastv2)
            {
                try
                {
                    StringWriterWithEncoding stringWriterWithEncoding = new StringWriterWithEncoding(Encoding.UTF8);
                    using (XmlWriter xmlWriter = XmlWriter.Create(stringWriterWithEncoding, new XmlWriterSettings
                    {
                        Encoding = stringWriterWithEncoding.Encoding,
                        IndentChars = string.Empty,
                        Indent = false,
                        NewLineHandling = NewLineHandling.None,
                        NewLineChars = string.Empty,
                        CheckCharacters = false
                    }))
                    {
                        xmlWriter.WriteStartElement("metadata");
                        xmlWriter.WriteElementString("TIT2", base.SongTitle);
                        if (!string.IsNullOrEmpty(this.StationName))
                        {
                            xmlWriter.WriteElementString("TRSN", this.StationName);
                        }
                        xmlWriter.WriteElementString("TENC", BassNet.InternalName + " (Broadcast Framework)");
                        if (!string.IsNullOrEmpty(url))
                        {
                            xmlWriter.WriteElementString("WOAF", url);
                        }
                        if (!string.IsNullOrEmpty(this.Url))
                        {
                            xmlWriter.WriteElementString("WORS", this.Url);
                        }
                        if (this.v2SongTitleNext != null)
                        {
                            xmlWriter.WriteStartElement("extension");
                            xmlWriter.WriteStartElement("title");
                            xmlWriter.WriteAttributeString("seq", "1");
                            xmlWriter.WriteString(base.SongTitle);
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteStartElement("title");
                            xmlWriter.WriteAttributeString("seq", "2");
                            xmlWriter.WriteString(this.v2SongTitleNext);
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteElementString("soon", this.v2SongTitleNext);
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.Flush();
                    }
                    this.v2SongTitleNext = string.Empty;
                    return(BassEnc.BASS_Encode_CastSendMeta(base.Encoder.EncoderHandle, BASSEncodeMetaDataType.BASS_METADATA_XML_SHOUTCAST, stringWriterWithEncoding.ToString()));
                }
                catch
                {
                    return(false);
                }
            }
            if (base.ForceUTF8TitleUpdates)
            {
                this.v2SongTitleNext = string.Empty;
                bool flag = BassEnc.BASS_Encode_CastSetTitle(base.Encoder.EncoderHandle, Encoding.UTF8.GetBytes(base.SongTitle + "\0"), string.IsNullOrEmpty(url) ? null : Encoding.UTF8.GetBytes(url + "\0"));
                if (!flag)
                {
                    flag = this.SHOUTcastUpdateTitle(base.SongTitle, url);
                }
                return(flag);
            }
            this.v2SongTitleNext = string.Empty;
            bool flag2 = BassEnc.BASS_Encode_CastSetTitle(base.Encoder.EncoderHandle, this._encoding.GetBytes(base.SongTitle + "\0"), string.IsNullOrEmpty(url) ? null : this._encoding.GetBytes(url + "\0"));

            if (!flag2)
            {
                flag2 = this.SHOUTcastUpdateTitle(base.SongTitle, url);
            }
            return(flag2);
        }