예제 #1
0
        protected override bool read(BinaryReader source, MetaDataIO.ReadTagParams readTagParams)
        {
            bool      result = true;
            PSFHeader header = new PSFHeader();
            PSFTag    tag    = new PSFTag();

            header.Reset();
            tag.Reset();
            resetData();

            isValid = readHeader(source, ref header);
            if (!isValid)
            {
                throw new Exception("Not a PSF file");
            }

            if (source.BaseStream.Length > HEADER_LENGTH + header.CompressedProgramLength + header.ReservedAreaLength)
            {
                source.BaseStream.Seek((long)(4 + header.CompressedProgramLength + header.ReservedAreaLength), SeekOrigin.Current);

                if (!readTag(source, ref tag, readTagParams))
                {
                    throw new Exception("Not a PSF tag");
                }

                tagExists = true;
            }

            bitrate = (sizeInfo.FileSize - tag.size) * 8 / duration;

            return(result);
        }
예제 #2
0
        private bool readTag(ref BinaryReader source, ref PSFTag tag)
        {
            tag.TagHeader = Utils.GetStringFromCharArray(Utils.ReadTrueChars(source, 5));
            if (TAG_HEADER == tag.TagHeader)
            {
                FTagExists = true;
                String s = readPSFLine(ref source);

                int    equalIndex;
                String keyStr;
                String valueStr;

                while (s != "")
                {
                    equalIndex = s.IndexOf("=");
                    if (equalIndex != -1)
                    {
                        keyStr   = s.Substring(0, equalIndex).Trim().ToLower();
                        valueStr = s.Substring(equalIndex + 1, s.Length - (equalIndex + 1)).Trim();

                        if (tag.tags.ContainsKey(keyStr))
                        {
                            tag.tags[keyStr] = tag.tags[keyStr] + " " + valueStr;
                        }
                        else
                        {
                            tag.tags[keyStr] = valueStr;
                        }
                    }

                    s = readPSFLine(ref source);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        // === PUBLIC METHODS ===

        public bool ReadFromFile(String fileName)
        {
            bool      result = true;
            PSFHeader header = new PSFHeader();
            PSFTag    tag    = new PSFTag();

            FResetData();

            header.Reset();
            tag.Reset();

            FileStream   fs     = null;
            BinaryReader source = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                fs.Lock(0, fs.Length);
                source = new BinaryReader(fs);

                if (!readHeader(ref source, ref header))
                {
                    throw new Exception("Not a PSF file");
                }

                if (fs.Length > HEADER_LENGTH + header.CompressedProgramLength + header.ReservedAreaLength)
                {
                    fs.Seek((long)(4 + header.CompressedProgramLength + header.ReservedAreaLength), SeekOrigin.Current);

                    if (!readTag(ref source, ref tag))
                    {
                        throw new Exception("Not a PSF tag");
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.StackTrace);
                //LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            if (fs != null)
            {
                fs.Unlock(0, fs.Length);
                fs.Close();
            }

            if (tag.tags.ContainsKey(TAG_GAME))
            {
                FAlbum = (String)tag.tags[TAG_GAME];
            }
            if (tag.tags.ContainsKey(TAG_ARTIST))
            {
                FArtist = (String)tag.tags[TAG_ARTIST];
            }
            if (tag.tags.ContainsKey(TAG_COMMENT))
            {
                FComment = (String)tag.tags[TAG_COMMENT];
            }
            if (tag.tags.ContainsKey(TAG_TITLE))
            {
                FTitle = (String)tag.tags[TAG_TITLE];
            }
            if (tag.tags.ContainsKey(TAG_YEAR))
            {
                FYear = (String)tag.tags[TAG_YEAR];
            }
            if (tag.tags.ContainsKey(TAG_LENGTH))
            {
                FDuration = parsePSFDuration((String)tag.tags[TAG_LENGTH]);
            }
            if (tag.tags.ContainsKey(TAG_FADE))
            {
                FDuration += parsePSFDuration((String)tag.tags[TAG_FADE]);
            }

            return(result);
        }
예제 #4
0
        private bool readTag(BinaryReader source, ref PSFTag tag, ReadTagParams readTagParams)
        {
            long     initialPosition = source.BaseStream.Position;
            Encoding encoding        = Utils.Latin1Encoding;

            tag.TagHeader = Utils.Latin1Encoding.GetString(source.ReadBytes(5));
            if (TAG_HEADER == tag.TagHeader)
            {
                string s = readPSFLine(source.BaseStream, encoding);

                int    equalIndex;
                string keyStr, valueStr, lowKeyStr;
                string lastKey          = "";
                string lastValue        = "";
                bool   lengthFieldFound = false;

                while (s != "")
                {
                    equalIndex = s.IndexOf("=");
                    if (equalIndex != -1)
                    {
                        keyStr    = s.Substring(0, equalIndex).Trim();
                        lowKeyStr = keyStr.ToLower();
                        valueStr  = s.Substring(equalIndex + 1, s.Length - (equalIndex + 1)).Trim();

                        if (lowKeyStr.Equals("utf8") && valueStr.Equals("1"))
                        {
                            encoding = Encoding.UTF8;
                        }

                        if (lowKeyStr.Equals(TAG_LENGTH) || lowKeyStr.Equals(TAG_FADE))
                        {
                            if (lowKeyStr.Equals(TAG_LENGTH))
                            {
                                lengthFieldFound = true;
                            }
                            duration += parsePSFDuration(valueStr);
                        }

                        // PSF specifics : a field appearing more than once is the same field, with values spanning over multiple lines
                        if (lastKey.Equals(keyStr))
                        {
                            lastValue += Environment.NewLine + valueStr;
                        }
                        else
                        {
                            SetMetaField(lastKey, lastValue, readTagParams.ReadAllMetaFrames);
                            lastValue = valueStr;
                        }
                        lastKey = keyStr;
                    }

                    s = readPSFLine(source.BaseStream, encoding);
                }                 // Metadata lines
                SetMetaField(lastKey, lastValue, readTagParams.ReadAllMetaFrames);

                // PSF files without any 'length' tag take default duration, regardless of 'fade' value
                if (!lengthFieldFound)
                {
                    duration = PSF_DEFAULT_DURATION;
                }

                tag.size = (int)(source.BaseStream.Position - initialPosition);
                if (readTagParams.PrepareForWriting)
                {
                    structureHelper.AddZone(initialPosition, tag.size);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
		// === PUBLIC METHODS ===

		public bool ReadFromFile(String fileName)
		{
			bool result = true;
			PSFHeader header = new PSFHeader();
			PSFTag tag = new PSFTag();

			FResetData();
			
			header.Reset();
			tag.Reset();

			FileStream fs = null;
			BinaryReader source = null;

			try
			{
				fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
				fs.Lock(0,fs.Length);
				source = new BinaryReader(fs);

				if ( !readHeader(ref source, ref header) ) throw new Exception("Not a PSF file");

				if (fs.Length > HEADER_LENGTH+header.CompressedProgramLength+header.ReservedAreaLength)
				{
					fs.Seek((long)(4+header.CompressedProgramLength+header.ReservedAreaLength),SeekOrigin.Current);
				
					if ( !readTag(ref source,ref tag) ) throw new Exception("Not a PSF tag");
				} 
			}
			catch (Exception e) 
			{
				System.Console.WriteLine(e.StackTrace);
				//LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
				result = false;
			}

			if (fs != null)
			{
				fs.Unlock(0,fs.Length);
				fs.Close();
			}

			if (tag.tags.ContainsKey(TAG_GAME)) FAlbum = (String)tag.tags[TAG_GAME];
			if (tag.tags.ContainsKey(TAG_ARTIST)) FArtist = (String)tag.tags[TAG_ARTIST];
			if (tag.tags.ContainsKey(TAG_COMMENT)) FComment = (String)tag.tags[TAG_COMMENT];
			if (tag.tags.ContainsKey(TAG_TITLE)) FTitle = (String)tag.tags[TAG_TITLE];
			if (tag.tags.ContainsKey(TAG_YEAR)) FYear = (String)tag.tags[TAG_YEAR];
			if (tag.tags.ContainsKey(TAG_LENGTH)) 
			{
				FDuration = parsePSFDuration( (String)tag.tags[TAG_LENGTH] );				
			}
			if (tag.tags.ContainsKey(TAG_FADE)) 
			{
				FDuration += parsePSFDuration( (String)tag.tags[TAG_FADE] );				
			}

			return result;
		}
예제 #6
0
		private bool readTag(ref BinaryReader source, ref PSFTag tag)
		{
			tag.TagHeader = Utils.GetStringFromCharArray( Utils.ReadTrueChars(source, 5) );
			if (TAG_HEADER == tag.TagHeader)
			{
				FTagExists = true;
				String s = readPSFLine(ref source);
				
				int equalIndex;
				String keyStr;
				String valueStr;

				while ( s != "" )
				{
					equalIndex = s.IndexOf("=");
					if (equalIndex != -1)
					{
						keyStr = s.Substring(0,equalIndex).Trim().ToLower();
						valueStr = s.Substring(equalIndex+1, s.Length-(equalIndex+1)).Trim();

						if (tag.tags.ContainsKey(keyStr))
						{
							tag.tags[keyStr] = tag.tags[keyStr] + " " + valueStr;
						}
						else
						{
							tag.tags[keyStr] = valueStr;
						}
					}

					s = readPSFLine(ref source);
				}
				return true;
			}
			else
			{
				return false;
			}
		}