Пример #1
0
        /// <summary>
        /// Transfer over enough of the file to extract the MP3 files tags
        /// </summary>
        /// <param name="fileItem"></param>
        /// <returns></returns>
        private async Task <ScannedSong> GetFileTags(DirectoryItem fileItem)
        {
            ScannedSong song = new ScannedSong();

            try
            {
                song.Modified   = fileItem.Created;
                song.SourcePath = fileItem.AbsolutePath;

                string requestName = ftpHeader + fileItem.AbsolutePath;

                // Get the length of the file
                FtpWebResponse lengthResponse = await new FtpRequest(requestName, WebRequestMethods.Ftp.GetFileSize, true).MakeRequestAsync();
                long           fileSize       = lengthResponse.ContentLength;

                // Start downloading the file
                FtpRequest     request  = new FtpRequest(requestName, WebRequestMethods.Ftp.DownloadFile, true);
                FtpWebResponse response = await request.MakeRequestAsync();

                // Read the file to get the MP3 tags.
                FTPStream wrappedStream = new FTPStream(response.GetResponseStream(), fileSize);

                song.Tags = MP3TagExtractor.GetFileTags(wrappedStream);

                // Read the FTP response and prevent stale data on the socket
                request.AbortRequest();
                wrappedStream.Close();
                response.Close();
            }
            catch (Exception songProblem)
            {
                Logger.Error(string.Format("FTP exception reading song: {0} : {1}", fileItem.AbsolutePath, songProblem.Message));
            }

            return(song);
        }
Пример #2
0
        /// <summary>
        /// Transfer over enough of the file to extract the MP3 files tags
        /// </summary>
        /// <param name="fileItem"></param>
        /// <returns></returns>
        private async Task <ScannedSong> GetFileTags(FileInfo fileItem)
        {
            ScannedSong song = new ScannedSong();

            await Task.Run(() =>
            {
                try
                {
                    song.Modified   = fileItem.LastWriteTime;
                    song.SourcePath = fileItem.FullName.TrimStart(rootDirectory);

                    using (FileStream fs = File.OpenRead(fileItem.FullName))
                    {
                        song.Tags = MP3TagExtractor.GetFileTags(fs);
                    }
                }
                catch (Exception songProblem)
                {
                    Logger.Error(string.Format("FTP exception reading song: {0} : {1}", fileItem.FullName, songProblem.Message));
                }
            });

            return(song);
        }