static Media RmAnalyse(Stream stream, byte[] header16) { Media music = new Media(); byte[] Id3v1 = new byte[128]; stream.Seek(stream.Length - 128, SeekOrigin.Begin); stream.Read(Id3v1, 0, 128); stream.Seek(0, SeekOrigin.Begin); if (!ByteManager.CompareByteArray(ByteManager.id3v1Tag, ByteManager.CopyByteArray(Id3v1, 0, 3))) return AnalyseRmID3V2(stream, header16); music.Title = Encoding.Default.GetString(ByteManager.CopyByteArray(Id3v1, 3, 30)).Replace("\0", ""); music.Artist = Encoding.Default.GetString(ByteManager.CopyByteArray(Id3v1, 33, 30)).Replace("\0", ""); music.DiscTitle = Encoding.Default.GetString(ByteManager.CopyByteArray(Id3v1, 63, 30)).Replace("\0", ""); music.PublishYear = Encoding.Default.GetString(ByteManager.CopyByteArray(Id3v1, 93, 4)).Replace("\0", ""); music.Remark = Encoding.Default.GetString(ByteManager.CopyByteArray(Id3v1, +97, 30)).Replace("\0", ""); return music; }
static Media AnalyseRmID3V2(Stream stream, byte[] header) { Media music = new Media(); byte[] field = new byte[4]; uint lenght = ByteManager.ByteCovertToUint(header, 4); stream.Seek(lenght, SeekOrigin.Begin); for (; ; ) { stream.Read(field, 0, 4); uint offset = Convert.ToUInt32((stream.ReadByte() << 24) + (stream.ReadByte() << 16) + (stream.ReadByte() << 8) + stream.ReadByte()); if (ByteManager.CompareByteArray(ByteManager.rm_field_CONT, field)) { stream.Seek(2, SeekOrigin.Current); byte[] contInfo = new byte[offset - 10]; stream.Read(contInfo, 0, contInfo.Length); music = AnalyseCONT(contInfo); break; } else stream.Read(new byte[offset - 8], 0, Convert.ToInt32(offset - 8)); } return music; }
static Media WmaAnalyse(Stream stream) { Media music = new Media(); try { StreamIndex(stream, ByteManager.wmaInfoTag); for (int i = 0; i < 8; i++) stream.ReadByte(); int titleLenght = stream.ReadByte() + (stream.ReadByte() << 8); int artistLenght = stream.ReadByte() + (stream.ReadByte() << 8); int copyrightLenght = stream.ReadByte() + (stream.ReadByte() << 8); int remarkLenght = stream.ReadByte() + (stream.ReadByte() << 8); byte[] titleBytes = new byte[titleLenght]; stream.Read(titleBytes, 0, titleLenght); music.Title = Encoding.Unicode.GetString(titleBytes); byte[] artistBytes = new byte[artistLenght]; stream.Read(artistBytes, 0, artistLenght); music.Artist = Encoding.Unicode.GetString(artistBytes); byte[] copyrightBytes = new byte[copyrightLenght]; stream.Read(copyrightBytes, 0, copyrightLenght); music.Copyright = Encoding.Unicode.GetString(copyrightBytes); byte[] remarkBytes = new byte[remarkLenght]; stream.Read(remarkBytes, 0, remarkLenght); music.Remark = Encoding.Unicode.GetString(remarkBytes); } catch { } return music; }
static Media AnalyseCONT(byte[] contInfo) { Media music = new Media(); int startIndex = 0; int titleLenght = contInfo[startIndex + 1]; music.Title = Encoding.Default.GetString(ByteManager.CopyByteArray(contInfo, startIndex + 2, titleLenght)); startIndex += titleLenght + 2; int artistLenght = contInfo[startIndex + 1]; music.Artist = Encoding.Default.GetString(ByteManager.CopyByteArray(contInfo, startIndex + 2, artistLenght)); startIndex += artistLenght + 2; int copyrightLenght = contInfo[startIndex + 1]; music.Copyright = Encoding.Default.GetString(ByteManager.CopyByteArray(contInfo, startIndex + 2, copyrightLenght)); startIndex += copyrightLenght + 2; return music; }
public static string GetShowString(Media m) { string showString = ""; if (!string.IsNullOrEmpty(m.title)) showString += "����:" + m.title + "<br />"; if (!string.IsNullOrEmpty(m.artist)) showString += "������:" + m.artist + "<br />"; if (!string.IsNullOrEmpty(m.discTitle)) showString += "ר��:" + m.discTitle + "<br />"; if (!string.IsNullOrEmpty(m.bitrate)) showString += "������:" + m.bitrate + "<br />"; if (!string.IsNullOrEmpty(m.publishYear)) showString += "������:" + m.publishYear + "<br />"; if (!string.IsNullOrEmpty(m.copyright)) showString += "��Ȩ:" + m.copyright + "<br />"; if (!string.IsNullOrEmpty(m.remark)) showString += "��ע:" + m.remark; return showString.Trim(); }
public static Media Parse(string strFormat) { Media media = new Media(); try { string info = Regex.Match(strFormat, @"\d+(@.+?:\d+)+sun").Value; MatchCollection mc = Regex.Matches(info, @"@(.*?):(\d+)"); string value = strFormat.Replace(info, ""); int start = 0; foreach (Match match in mc) { int lenght = int.Parse(match.Groups[2].Value); media.GetType().GetProperty(match.Groups[1].Value).SetValue(media, value.Substring(start, lenght), null); start += lenght; } } catch { return new Media(); } return media; }