Esempio n. 1
0
        public void SetDuration(MediaSermon sermon, bool save = false)
        {
            var fileName = sermon.Media.getProperty("audioFile").Value as string;

            if (string.IsNullOrEmpty(fileName))
                return;

            try
            {
                var mp3File = TagLib.File.Create(HttpContext.Current.Server.MapPath(fileName));

                var id3v2Tags = (TagLib.Id3v2.Tag)mp3File.GetTag(TagLib.TagTypes.Id3v2);
                var lenFrame = id3v2Tags.GetFrames<TagLib.Id3v2.TextInformationFrame>("TLEN").FirstOrDefault();
                if (lenFrame != null)
                {
                    int lenghtMs;
                    if (int.TryParse(lenFrame.Text[0], out lenghtMs))
                    {
                        sermon.Duration = TimeSpan.FromMilliseconds(lenghtMs);
                    }
                }
                else
                {
                    sermon.Duration = mp3File.Properties.Duration;
                }

                if (save)
                    sermon.Media.Save();
            }
            catch (Exception ex)
            {
                throw new Exception("Error setting duration on " + sermon.Media.Text + " - " + fileName, ex);
            }
        }
Esempio n. 2
0
        public void CanonicalizeFileName(MediaSermon sermon, bool save = false)
        {
            var fileProperty = sermon.Media.getProperty("audioFile");
            string oldFileName = fileProperty.Value.ToString();

            if (!string.IsNullOrWhiteSpace(oldFileName) && File.Exists(HttpContext.Current.Server.MapPath(oldFileName)))
            {
                string newFileName = Path.GetDirectoryName(oldFileName) + "/" + sermon.Media.Text.Replace("/", "-") + Path.GetExtension(oldFileName);
                newFileName = newFileName.Replace("\\", "/").Replace(" ", "");

                if (oldFileName != newFileName)
                {
                    fileProperty.Value = newFileName;

                    if (File.Exists(HttpContext.Current.Server.MapPath(newFileName)))
                        File.Delete(HttpContext.Current.Server.MapPath(newFileName));

                    File.Move(HttpContext.Current.Server.MapPath(oldFileName), HttpContext.Current.Server.MapPath(newFileName));

                    if (save)
                        sermon.Media.Save();
                }
            }
        }
Esempio n. 3
0
 public void SetMp3FileTags(MediaSermon sermon)
 {
     SetMp3FileTags(sermon.Media.getProperty("audioFile").Value as string, sermon);
 }