I'm trying to write a program that would let me modify the tags of mp3 files, to do this I'm using Taglib with c++11.
I understood how to change the tags of a file but I'm not sure how (or even if) I can rename the file when saving it.
Let's say i have the following code:
TagLib::FileRef f("Vivaldi - La Primavera.mp3");
f.tag()->setTitle("La Primavera");
f.save();
This will change the title tag of the mp3 file (not the filename) to "La Primavera" leaving everything else unchanged.
Is there a way to have the new file after the f.save() be called only "La Primavera" using only Taglib or do i have to do something like reading the file once more and rename it?
I've read Taglib's documentation but can't seem to find anything on the matter.
TagLib sharp isn't a tool to manage your file system. It's for reading and writing the various bits of meta data in media files (audio and video).
In order to rename your files just use the normal methods for copying and deleting files.
Open the original file, edit the meta data, release the file handle, copy to new filename and then finally delete the original file.
Related
I am trying to figure a way to use already translated .md files (Russian Language) with Sphinx. I use readthedocs.io and I have already read the process of making translatable files (.po/.pot) from:
(1) https://docs.readthedocs.io/en/latest/localization.html
(2) https://docs.readthedocs.io/en/latest/guides/manage-translations.html.
This process requires to make .po or .pot files, translate them, and then produce translated html files - served under https://project.readthedocs.io/$language/$version
What I want is to use a different directory (for example named ru) and place there the Russian .md files.
Is that possible? How is it possible to avoid creating these .po/.pot files?
I am having an issue when attempting to copy two files into a separate file using the Windows Copy command. In the first file, when I open the text file in notepad I see the data in the file formatted as expected.
File #1
0900|Y3RN|19944|12/OCT/2016|2|2|1600|C||||||0|0|||Replace
0900|Y3RN|19944|13/OCT/2016|2|2|2000|C||||||0|0|||Replace
0900|Y3RN|19944|14/OCT/2016|2|2|600|C||||||0|0|||Replace
However in the second file that has the same fields the format of the data in notepad is different.
File #2
0901|ECQQ|339489|18/OCT/2016|2|2|25|C||||||0|0|||Replace0901|ECQQ|339489|19/OCT/2016|2|2|180|C||||||0|0|||Replace0901|EK1P|339489|04/OCT/2016|2|2|100|C||||||0|0|||Replace
Supposedly the same process is generating the two files on my customer's system of record. If I open only each file separately using Textpad, the two files have the same format as File#1 above.
When I use the Copy command, the resulting file looks as below when viewing in Notepad.
0900|Y3RN|19944|28/OCT/2016|2|2|1400|C||||||0|0|||Replace
0900|Y3RN|19944|31/OCT/2016|2|2|1400|C||||||0|0|||Replace
0900|Y6CJ|19944|10/OCT/2016|2|2|200|C||||||0|0|||Replace0901|ECQQ|339489|18/OCT/2016|2|2|25|C||||||0|0|||Replace0901|ECQQ|339489|19/OCT/2016|2|2|180|C||||||0|0|||Replace0901|EK1P|339489|04/OCT/2016|2|2|100|C||||||0|0|||Replace
However when viewing the resulting file in Textpad, the format is correct.
There has to be something missing in the format of File#2, but since I do not have access or visibility to how these files are being generated my hands are tied.
Is there a way to convert File #2 so that it is formatted exactly like File#1?
I'm developing a plugin in Jekyll that inserts a new Liquid Tag (a block tag) named latex. It's purpose is to insert a block of LaTeX source code inside a post source file this way:
... post file contents ...
{% latex density=300 usepackages=pstricks-all, %}
\pspicture(5,5)
\psframe(0,0)(5,5) \psline(0,0)(5,5) \psline(0,5)(5,0)
\endpspicture
{% endlatex %}
... post file contents ...
The output post will contain a <img> tag instead of the Liquid Tag block once compiled and the LaTeX source will be compiled by a chained execution of latex, dvips, convert. So it will depend on external programs (TexLive and ImageMagick).
I've not found any issue with the explained so far. I can take the block of LaTeX, put it in a temporary file, and finally compile it to PNG. The rendered files must be put in the same folder of the post.
But just there I'm stuck: I want to put the generated PNG image to this folder inside the destination output folder. No problem defining a site-config variable to define the folder (in fact, I do that), nor put a file there. The problem is simple: I can write to the source folder, but the generated files will not be copied to the destination folder.
I know the reason: Jekyll generates first and renders afterwards. The copy process happens before the render part, so the generated files will not be copied.
I've found this SO entry: "How to generate files from Liquid blocks in Jekyll?", but the answer doesn't feel right: You must make a two-pass build for the files to be copied.
Also found "Generate file inside _site with Jekyll plugin", but this is not applicable because I don't want to render documents by templates.
The solution I've been planning is this:
Keep a folder with all the generated files and some index strategy for their final placement.
Implement a Sitewide method for the final placement procedure, something like:
class Site
def generate_latex_adds
// Code that copies the generated files to destination folders
end
end
Add self.generate_latex_adds calling that method inside the site_process.rb script just before the self.cleanup and self.write calls.
This will probably solve the problem, but I feel wrong to modify the site_process.rb. I'm considering pull this Liquid Tag to the community as a GitHub project, and as such, I must document this manual edit of site_process.rb to the users of this plugin. I know it's probably a common situation and a common solution, but I wonder if there is a better way to pospone the copy of the generated files without modifying core files. I'd like to keep the plugin simple: just copy the plugin file to the _plugins directory.
Any ideas?
EDIT: I'm more interested in the reasoning that on the actual code. I want to learn, not asking for a code solution.
As anyone has answered my question up to now, and I had kept investigating the issue. Finally I've got an elegant solution: use the Jekyll::StaticFile class. I have missed that class (sidenote: Read more carefully the docs).
When you add one object of this class to the site.static_files array, you are marking this file as pending for copy after the render process is completed. In fact, the copy of such files is done in the site.write process. Take a look at the site_process.rb file in your Jekyll installation.
The usage of this class is easy. When you need to mark a file for future copy, you simply execute a code like this:
site.static_files << Jekyll::StaticFile.new(site, site.source, path, filename)
Where path and filename depends on the location of your file in the src folder.
And that's all: You generate the files in the src folder, mark them as pending for copy and let Jekyll do the rest. No modification of site_process.rb at all!
You can take a look at the resulting LaTeX -> PNG liquid tag code at GitHub: https://github.com/fgalindo/jekyll-liquid-latex-plugin
I've also implemented a cleanup method there to eliminate orphaned generated files from posts that have been modified and rebuilt.
We're creating an app that is going to generate some text files on *nix systems with hashed filenames to avoid too-long filenames.
However, it would be nice to tag the files with some metadata that gives a better clue as to what their content is.
Hence my question. Does anyone have any experience with creating files with custom metadata in Ruby?
I've done some searching and there seem to be some (very old) gems that read metadata:
https://github.com/kig/metadata
http://oai.rubyforge.org/
I also found: system file, read write o create custom metadata or attributes extended which seems to suggest that what I need may be at the system level, but dropping down there feels dirty and scary.
Anyone know of libraries that could achieve this? How would one create custom metadata for files generated by Ruby?
A very old but interesting question with no answers!
In order for a file to contain metadata, it has to have a format that has some way (implicitly or explicitly) to describe where and how the metadata is stored.
This can be done by the format, such as having a header that says where the "main" data is stored and where the "metadata" is stored, or perhaps implicitly, such as having a length to the "main" data, and storing metadata as anything beyond the "main" data.
This can also be done by the OS/filesystem by storing information along with the files, such as permission info, modtime, user, and more comprehensive file information like "icon" as you would find with iOS/Windows.
(Note that I am using "quotes" around "main" and "metadata" because the reality is that it's all data, and needs to be stored in some way that tools can retrieve it)
A true text file does not contain any headers or any such file format, and is essentially just a continuous block of characters (disregarding how the OS may store it). This also means that it can be generally opened by any text editor, which will merely read and display all the characters it finds.
So the answer in some sense is that you can't, at least not on a true text file that is truly portable to multiple OS.
A few thoughts on how to get around this:
Use binary at the end of the text file with hope/requirements that their text editor will ignore non-ascii.
Store it in the OS metadata for the file and make it OS specific (such as storing it in the "comments" section that an OS may have for a file.
Store it in a separate file that goes "along with" the file (i.e., file.txt and file.meta) and hope that they keep the files together.
Store it in a separate file and zip the text and the meta file together and have your tool be zip aware.
Come up with a new file format that is not just text but has a text section (though then it can no longer be edited with a text editor).
Store the metadata at the end of the text file in a text format with perhaps comments or some indicator to leave the metadata alone. This is similar to the technique that the vi/vim text editor uses to embed vim commands into a file, it just puts them as comments at the beginning or end of the file.
I'm not sure there are many other ways to accomplish what you want, but perhaps one of those will work.
I've been stuck on this problem for a while, done lots of searches and tried various solutions that others reported to be working, and yet I'm still stuck. So any suggestion is hugely appreciated. Please let me know if I'm being unclear. Many thanks in advance!!
I'm trying to generate a PDF in Classic ASP (I know....) with FPDF v.1.01 (available from http://www.aspxnet.it/public/Default.asp?page=172). But I keep getting a message "File does not begin with '%PDF-'" when the PDF is populated. I've tried this in Firefox 7.0.1, IE9, which are the two browsers we use at work. If I remove this line from the code, then everything works as expected. So all I know is this line is the trouble maker (maybe?)
this.Image('bg_logo_small.jpg',10,8,213,46);
I have a file named report.asp. The organization of the files looks like this:
./rpt/report.asp
./rpt/fpdf.asp
./rpt/bg_logo_small.jpg
./rpt/fpdf/ - this directory contains all the files extracted from fpdf1.01.zip
./rpt/fpdf/extends/
./rpt/fpdf/fonts/
./rpt/fpdf/includes/
./rpt/fpdf/models/
and report.asp looks like this,which is pretty much taken directly from the example on aspxnet.it site, except that I'm using my own jpg:
<%#LANGUAGE="javascript" CODEPAGE="65001"%>
<!--#include file="fpdf.asp" -->
<%
var pdf=new FPDF();
pdf.Header=function Header()
{
this.Image('bg_logo_small.jpg',10,8,213,46);
this.SetFont('Arial','B',15);
this.Cell(80);
this.Cell(30,10,'Title',1,0,'C');
this.Ln(20);
}
pdf.Footer=function Footer()
{
this.SetY(-15);
this.SetFont('Arial','I',8);
this.Cell(0,10,'Page '+ this.PageNo()+ '/{nb}',0,0,'C');
}
pdf.CreatePDF();
pdf.SetPath("fpdf/");
pdf.SetFont("Arial","",16);
pdf.Open();
pdf.AddPage();
pdf.Cell(40,10,"Hello Word!");
pdf.Close();
pdf.Output();
%>
I've tried the same thing in VBScript with
pdf.LoadModels("bgimg")
and function Header() and function Footer() placed in bgimg.mod, which was saved in
./rpt/fpdf/models/
The code above is all report.asp contains - no HTML inside.
I am not sure, if you haven't solved the problem yet, but anyway I answer, because it could help to somebody else.
I had the same problem and I was browsing and looking long long time for solution.
Finally I found the solution.
Go in fpdf.asp file, look for line with code:
xfile=Server.MapPath(lib.fso.GetTempName())
You can change the code e.g. like this:
xfile=Server.MapPath("Temp/"+lib.fso.GetTempName())
where "Temp/" is name of folder where temporary file during PDF file generation will be created and later deleted. The main trick is to assign "Modify" access rights to the folder Temp.
The error "File does not begin with '%PDF-'" appear because there are no access rights to create and then delete temporary files for your final PDF file. So you have an option to assign "Modify" access right to your root folder or transfer temporary files for PDF in folder Temp and assign "Modify" only to folder Temp (this is more secure).
try with <%#LANGUAGE="javascript" %>
insted of <%#LANGUAGE="javascript" CODEPAGE="65001"%>
Just need to remove CODEPAGE="65001"