Reading/Writing metadata of audio/video files - c#

I need some help in reading/writing meta data inforamation of audio/vido file. I have searched alot but not find anything thing helpful. Taglib sharp is an open source library that provide help in reading/writing metadata. Using tag lib i'm able to edit some of values but not all like.
TagLib.File videoFile = TagLib.File.Create("test.mp4");
videoFile.Tag.Title = "Test";
videoFile.Tag.Comment = "Nothing";
but i'm unable to edit following properties like Author url, producers etc. How i edit these properties ??

I've never done this for video files before but I have for mp3 files. You can get access to those frames like this:
TagLib.File file = TagLib.File.Create(mp3FileName);
file.Tag.Title = "some title"; // you've got this
TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)file.GetTag(TagTypes.Id3v2);
tag.SetTextFrame("WOAR", "some url"); // WOAR = Official artist/performer webpage
file.Save();
You can find a list of the text frame identifiers at Wikipedia:
ID3v2 Frame Specification (Version 2.3)
I don't know if video files give you the same range of frames that ID3 does, though notice that Wikipedia also says (Implementation in non-mp3s and alternatives)
MP4 also allows the embedding of an ID3 tag, and this is widely supported.
So I would guess this also works for mp4 files like you're trying.

You will need to use AppleTag. This will work. For mp4 file you have to write value into dashbox. Like this:
TagLib.File videoFile = TagLib.File.Create("test.mp4");
TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)f.GetTag(TagLib.TagTypes.Apple);
customTag.SetDashBox("Producer","Producer1", "value");
f.Save();
f.Dispose();
And you can get the value like this:
var tokenValue = customTag.GetDashBox("Producer", "Producer1");

Related

TglibSharp i cant write to the metadata of an mp3 song

I have been trying to read/write metadata of mp3 files.I searched around a bit and found out i could use Taglibsharp in order to do it.Reading the metadata works perfectly however when i try to write in order to change a tag for example the title nothing happens.Also there is no documentation for taglibsharp so if someone who has previously used it knows what i can do , please help me.Thanks in advance!
Some code:
var tfile = TagLib.File.Create(songPath);
//Reading: works perfectly
string title = tfile.Tag.Title;
//writing: does nothing
tfile.Tag.Title = "A title";
You need to call the .Save() method:
using (var tfile = TagLib.File.Create(songPath))
{
tfile.Tag.Title = "A title";
tfile.Save();
}

TagLib-Sharp - Retagging files

im about to create a small tool, which recreates all tags on my mp3 files.
Because they are in a mess, i want to remove all tags and recreate them with the correct values.
Doing so ive encountered the problem that im not able to set the tag values.
But the problem is, that im not able to set the tags. I have the following code:
File tagLibFile = File.Create(filePath);
tagLibFile.RemoveTags(TagLib.TagTypes.AllTags);
tagLibFile.Tag.Album = album;
tagLibFile.Tag.AlbumArtists = artists.ToArray();
tagLibFile.Tag.Track = track;
tagLibFile.Tag.Title = title;
tagLibFile.Tag.TitleSort = titleSort;
...
tagLibFile.Save();
The file is read out correctly. Then the tags are removed.
But after that setting the Tag does not work. The strings inside the tag are still null.
I havent seen a method like "tagLibFile.SetTag(Tag t)". The Tag is only available as a getter, but not a setter.
After that ive added some Frames, but that doesent have the effect of setting the tags. Maybe im using it the wrong way?
Hope you can help me out of this!
Kind regards,
SyLuS
I'm guessing that after removing tags, TagLib# (or TagLib, for that matter) does not create a new tag to hold information. However, when opening a file, it possibly does some checking and if the file doesn't have one, it creates a new tag.
Hence, as a workaround, you could save the file once after removing the tags, and then proceed to add new tag information.
File tagLibFile = File.Create(filePath);
tagLibFile.RemoveTags(TagLib.TagTypes.AllTags);
// Save the file once, so that Taglib Sharp takes care of creating any necessary tags when opening the file next time and dispose the file reference:
tagLibFile.Save();
tagLibFile.Dispose();
You can then proceed to editing the tags as you're already doing after opening the file again:
tagLibFile = File.Create(filePath);
tagLibFile.Tag.Album = album;
tagLibFile.Tag.AlbumArtists = artists.ToArray();
tagLibFile.Tag.Track = track;
tagLibFile.Tag.Title = title;
tagLibFile.Tag.TitleSort = titleSort;
// ...
Remember to save the file again, after you're done editing tags:
tagLibFile.Save();
I hope this helps. If you have any further questions, or the above code doesn't work still, feel free to comment. :)

Listing extended tags in files with Tagliib

I am working with .flac audio files that use extended tags for a bit of magic. There is a tag called ReleaseGuid. I want to be able to list the contents or create the tag if it doesn't exist. I have done the prerequisite beating of my head against the wall for three days now. I have found a way to add a usertextinformation frame...although I don't see the value just the Owner. Please help me figure this out.
The following are lines of code that at least compile and seem to do something.
I need to get this to the point where I can add the needed tag.
File objFile = TagLib.File.Create(path);
TagLib.Id3v2.Tag id3v2tag = (TagLib.Id3v2.Tag)objFile.GetTag TagLib.TagTypes.Id3v2, true);
if (id3v2tag != null)
{
// Get the private frame, create if necessary.
PrivateFrame frame = PrivateFrame.Get(id3v2tag, "Mytag", true);
frame.PrivateData = System.Text.Encoding.Unicode.GetBytes "MyInfo");
id3v2tag.AddFrame(frame);
}
I have used mp3tag to see the tags I am needing by clicking on "extended tags".
Which type of tags would these be if I can add them using mp3tag? How do I read/write them using taglib?
To search for the tag type, you can open the (.flac) audio file in a texteditor like Notepad++ and search for your 'ReleaseGuid'. In front of this ID you will see the type like TXXX or PRIV or COMM.
Or you can have a look into the documentation (source code?) of the program who writes this 'ReleaseGuid' in your audio files.

Add sound to swf file via SwfDotNet tool

I need to make swf file (slide show) from images and sounds (narrations).
I am trying to use SwfDotNet tool for it.
There is article which describes how to add images to swf http://www.codeproject.com/KB/graphics/jpeg2swf.aspx?fid=369197&df=90&mpp=10&noise=3&prof=True&sort=Position&view=Quick&fr=21#xx0xx
I can't add sound to swf.
I try to use next code, but it doesn't work.
Looks that DefineSoundTag works because file size is increased, but StartSoundTag doesn't work.
var soundId = swf.GetNewDefineId();
swf.Tags.Add(DefineSoundTag.FromFile(soundId, fileName));
var soundInfo = new SoundInfo() {
InPoint = 1,
OutPoint = 10000
};
swf.Tags.Add(new StartSoundTag(soundId, soundInfo));
Does anyone know how to add sound to swf via swfdotnet tool?

programmatically adding files to the Kentico Media Library

Using CMSDesk and click on the Tools tab, then Media Library I can add files to the inbuilt Kentico Media Library. Is there a way to do this using their API?
You can do this using the Kentico API. It is actually quite rich but the documentation and samples out there are a bit lacking.
Following is a sample method (actually used as a web service method as we have both remote and local pages that use it) and a sample method that calls it (say from an 'edit' web page).
fileLogo - > protected System.Web.UI.WebControls.FileUpload fileLogo;
[WebMethod]
public bool Import(int libraryID, string folderName, string fileName, byte[] bytes)
{
SiteInfo siteInfo = SiteInfoProvider.GetCurrentSite();
MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryID);
fileName = fileName.Replace(" ", "-").Replace("&", "-").Replace("'", "-").Replace("+", "-").Replace("=", "-").Replace("[", "-").Replace("]", "-").Replace("#", "-").Replace("%", "-").Replace("\\", "-").Replace("/", "-").Replace(":", "-").Replace("*", "-").Replace("?", "-").Replace("\"", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-");
bool bRetValue = false;
string filePath = Server.MapPath(string.Format("/{0}/media/{1}/{2}/{3}", siteInfo.SiteName, libraryInfo.LibraryFolder, folderName, fileName));
File.WriteAllBytes(filePath, bytes);
if (File.Exists(filePath))
{
string path = MediaLibraryHelper.EnsurePath(filePath);
MediaFileInfo fileInfo = new MediaFileInfo(filePath, libraryInfo.LibraryID, folderName);
fileInfo.FileSiteID = siteInfo.SiteID;
MediaFileInfoProvider.ImportMediaFileInfo(fileInfo);
bRetValue = true;
}
return bRetValue;
}
string filePath = "~/SITENAME/media/SITE_MEDIALIB/Logos/";
string fileName = string.Empty ;
if (fileLogo.FileName.Length > 0)
{
var ext = fileLogo.FileName.Substring(fileLogo.FileName.LastIndexOf('.') + 1).ToLower();
fileName = entryTitle + "." + ext;
MediaLibrary il = new MediaLibrary();
il.Import(3, "FOLDERNAME", fileName, fileLogo.FileBytes);
}
Keeping it here as the original link seems to be dead.
Posted on June 23, 2010 by kevin
So, if you’ve ever worked with the .NET based CMS Kentico (http://www.kentico.com), you’ll know that Media Libraries can be a very powerful tool for organizing your non-site data, including images, documents, and anything else that you need storing and integrating with your CMS. And it all works fantastically, as long as you don’t try to do anything with it code-side. That’s where things get interesting, to say the least.
The Kentico documentation website (http://devnet.kentico.com/documentation.aspx) is very useful in terms of working with and manipulating the tree from the code, it offers very little in terms of manipulating and working-with in general with Media Libraries. So I spent a good amount of time looking through the Modules seeing what Kentico does and how it does it so you don’t have to.
Since this is my first post, and I’m still a little rusty on the whole “writing” thing, so let’s just get to the code.
//Media Library Info - takes Media Library Name and Website Name
MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo("Website", "MediaLibrary");
//Folder in Media Library where Item will be Inserted
string mediaLibraryFolder = "MediaLibraryFolder";
//Absolute Path to File
string filePath = Server.MapPath("~/Website/media/MediaLibrary/" + "MediaLibraryFolder/MediaLibraryItem.pdf");
// Get Relative Path to File
string path = MediaLibraryHelper.EnsurePath(filePath);
//create media file info item - takes the relative path to the document, the library ID, and the folder name where the document will be located within the media library
MediaFileInfo fileInfo = new MediaFileInfo(path, libraryInfo.LibraryID, mediaLibraryFolder);
//set the title to something nice
fileInfo.FileTitle = "Document Title";
//set the description to something useful
fileInfo.FileDescription = "Document Description";
// Save media file info
MediaFileInfoProvider.ImportMediaFileInfo(fileInfo);
I think this is pretty self explanatory, we create a MediaFileInfo object, set some stuff in it, and then insert it into the MediaFileInfoProvider. There are a lot of additional properties within the MediaFileInfo object, such as FileSize, which (as the name of the property suggests), stores the file size in a long. Pro tip – use the CMS.GlobalHelper.DataHelper.GetSizeString function to convert the long to a string, formatting it into user-readable data.
This really just scratches the surface on what you can do with Media Libraries in the code-behind. Take a closer look at the MediaFileInfo and MediaFIleInfoProvider classes, along with the MediaLibraryHelper, MediaLibraryInfo, MediaLibraryInfoProvider classes. There’s very little that can’t be done.

Categories