I need to get these information not from a file located on my machine, but on another one.
In general I'm able to get these infos in this way:
TagLib::MPEG::File.open("myfile.mp3") do |file|
tag = file.tag
"Artist: " + tag.artist + " " +
"Title: " + tag.title + " " +
"Album: " + tag.album + " "
end
... but if I open a link to the file like "http:// .../myfile.mp3" It doesn't work. Why?
Is there a different way to resolve it?
TagLib only works on files on the local filesystem. To retrieve tags from remote files, you'd first have to download that file to your local disk.
So a path to the file system should be given to the TagLib::MPEG::File.open param, not a url.
Related
I am working on selecting files to email and then passing them to the user's notes email client.
The string I want to send to the system command should be in the format of:
"C:\Program Files (x86)\IBM\Lotus\Notes\notes.exe"
Mailto:chris#mydomain.com?Subject=MailSubject?Attach=C:\test.bat
However, the code
$attached_files = $attached_files + "?Attach="+ Rails.root.to_s + "/public/images/" + document.id.to_s + "/" + document.doc_file_file_name
gives me forward slashes instead:
C:/Users/cmendla/RubymineProjects/technical_library/public/images/2/High_Durability.pdf
When that is passed to system() it won't launch the notes email. I think that the problem is that the server looks for / and the windows pc looks for \
Is there any way to easily change / to \ at least for the time being for testing?
Have you tried
Rails.root.join("public","images", document.id, document.doc_file_file_name)
?
I am trying to let users record an audio file in a Phonegap app. It works well on Android, but on iOS I get the following error when the recording should start:
"Failed to start recording using AvAudioRecorder".
I use a .wav filename, I create the file first, I have followed all instructions I have found and I keep getting the error.
This is the piece of code:
theFileSystem.root.getFile(filename,{create:true},function(fileEntry){
mediaFileURL = fileEntry.toURL();
console.log('Created file ' + mediaFileURL);
mediaRec = new Media(mediaFileURL, function(){
//console.log('Media File created');
}, function(err){
alert('Error creating the media file: ' + err.message);
console.log(mediaFileURL);
for(k in err){
console.log(k + ': ' + err[k]);
}
stopRecordingFile();
});
mediaRec.startRecord();
},function(err){
alert("Error setting audio file");
});
I see the console message 'Created file ...' so the file is successfully created. Then I get the error.
Media plugin version is 0.2.11
I don't know what else to try. Thanks for any help.
I solved this myself.
I'll leave solution here in case it helps someone.
For iOS, this needs to be changed:
mediaFileURL = fileEntry.toURL();
to this:
mediaFileURL = fileEntry.fullPath;
Also, even though I was requesting the Persistent filesystem, iOS saved the file in the tmp folder. So to upload the file afterwards using FileTransfer, I used this to refer to the file (I tried different approaches and this was the one that worked):
sendFileURL = cordova.file.tempDirectory + filename;
following fix to the Url solved the problem for me.
fixFileName = mediaFiles[i].fullPath.indexOf('file://') > -1 ? mediaFiles[i].fullPath : "file://" + mediaFiles[i].fullPath;
ok. this creepy error was solved.
all i did was made the file extension to uppercase, i.e.
made ".wav" to ".WAV".
I am developing an application for crawling the web using crawler4j and Jsoup. I need to parse a webpage using JSoup and check if it has zip files, pdf/doc and mp3/mov file available as a resource for download.
For zip files i did the following and it works:
Elements zip = doc.select("a[href\$=.zip]")
println "No of zip files is " + zip.size()
This code correctly tells me how many zip files are there in a page. I am not sure how to count all audio files or document files using JSoup. Any help is appreciated. Thanks.
Using the same approach I suspect it would be something like this:
Elements docs = doc.select("a[href\$=.doc]")
println "No of doc files is " + docs.size()
Elements mp3s = doc.select("a[href\$=.mp3]")
println "No of mp3 files is " + mp3s.size()
Really it's just a selector where the href attribute ends in some file extension.
Please help!!! I am trying to add some performtaskwithpathargumentstimeout functions to my ios UI automation javascript. Specifically I am submitting a form within the app and subsequently want to check that it has been submitted successfully. However I am having problems.
I want to do several things. The ideal was to do a curl request to a url, and then search the stdout body that comes back to ensure that several keywords were there. However, instruments keeps crashing when I try and use any indexOf or .search functions on the result.stdout...
I thought another option would be to output the html to a file, and then search that file by writing a command line application which will search for the keyword passed as an argument. However, when I try and output the file to a directory using the following-
var target = UIATarget.localTarget();
var host = target.host();
result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o /Users/andrewweaver/Documents/output.html", "http://www.google.co.uk"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
I get the following error-
Warning: Failed to create the file /Users/me/Documents/output.html:
\nWarning: No such file or directory
This directory DOES exist, and has permissions for anyone to read & write to it.... also, if I create the .html file in that directory the same thing happens. If I run the same command from terminal it works fine...
I also wanted to do a write out of the http code...
result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["--write-out %{http_code}", "http://www.google.co.uk"], 30);
But again, that is failing....
curl: option --write-out %{http_code}: is unknown
I'm not sure what I'm doing wrong....
Any help would be much appreciated : - )
Fixed it. Each of the args passed into performTaskWithPathArgumentsTimeout needs to be separated by "" and a ,
So, for example to query a website and write the output to a file...
var host = target.host();
var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/curl", ["-o", "/Users/me/Documents/football.html", "http://www.bbc.co.uk/"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
And then to search the outputted file for a particular element I use grep...
var str = "BBC Sport - Football";
var result = target.host().performTaskWithPathArgumentsTimeout("usr/bin/grep", ["-w", (str), "/Users/me/Documents/football.html"], 15);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
This will return a 0 if the regex is found, and BBC Sport - Football as the stdout.
I can then use an if statement to pass or fail (or use a tuneup js assert) based on whether the expected expression is present...
Useful for sending requests to webservices and then verifying the content...
I need to join any files (2GB) without read their content. I have tried to use CopyFile method but it doesn't work.
My code is that:
Public Function UnificarCRIs(ByVal path, ByVal FICRIEC, ByVal sessio, ByVal CIBAA)
Dim objFile, objCurrentFolder, filesys, origenFitxers
Dim FileName, WshShell
On error resume next
Set filesys = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objCurrentFolder = filesys.getFolder(path)
origenFitxers = " "
For Each objFile In objCurrentFolder.Files
FileName = objFile
If (right(FileName, 4) = ".cri") Then
origenFitxers = FileName
'Wscript.Echo FileName
If filesys.FileExists(path & FICRIEC & sessio) Then
'Wscript.Echo "If"
Wscript.Echo path & FICRIEC & sessio & "+" & FileName
filesys.CopyFile path & FICRIEC & sessio & "+" & FileName, path & FICRIEC & sessio
'WshShell.Run ("copy " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp")
'filesys.DeleteFile path & FICRIEC & sessio
'filesys.MoveFile path & FICRIEC & sessio & "_tmp", path & FICRIEC & sessio
Else
Wscript.Echo "Else"
WshShell.Run ("copy " & FileName & " " & path & FICRIEC & sessio)
'filesys.CopyFile FileName,path & FICRIEC & sessio
End If
End If
Next
End Function
Are there some way to join two files using Vbscript?
Thanks
To join two files, 'someone' has to to read (and write) the contents of both files. This 'someone' could be copy [/B] f1 + f2 f3. So use your loop to build the correct file specs and WshShell.Run/.Exec the suitabe commands.
Depends which COM objects you have access to and where the code is running.
1) If you have access to the Shell, then use the copy command of the DOS prompt. This example shows the excecution of the Dir command but it's the same technique.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
' Note the True value means wait to complete...
' And the 0 value means do not display any window...
oShell.run "cmd /K CD C:\ & Dir", 0, True
Set oShell = Nothing
And maybe also take a look here http://ss64.com/vb/shellexecute.html. Don't know if that method will help.
2) If you have no shell then if you can make COM objects then make one with C++ or Delphi or VB6 etc. Then use that COM object to execute the DOS command to do the merging.
3) Otherwise you will have to read the data from the file. If it is text files then that is easy because there are simple commands to do that with in the Vbs. If it is binary data then that requires more work to get at the binary data and use the "LenB" and "AscB" style functions to access the raw bytes of the Unicode. But you really do not want to do that.
Any upload handling script for ASP should show you the technique for working with raw bytes from the strings.
You can combine VBScript with Windows Copy command to join files.
You can see the document on appending binary files using Copy here
https://support.microsoft.com/en-us/kb/71161
Here's the example of the technique:
JoinFiles "c:\test\", "c:\test\mergedfile.cri"
Function JoinFiles (inPath, outPath)
Dim objShell, objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
Dim strFilenames, objFile, intFilecount, intExitCode
strFilenames = ""
intFilecount = 0
intExitCode = 0
' If the input folder exists, proceed to listing the files
If objFSO.FolderExists (inPath) Then
' List the files in the folder and join the files which has cri extension
For Each objFile In objFSO.GetFolder(inPath).Files
If LCase (objFSO.GetExtensionName (objFile.Path)) = "cri" Then
intFilecount = intFilecount+1
strFilenames = strFilenames & """" & objFile.Path & """ + "
End If
Next
' If there're more than one file, proceed to join the file
If (intFilecount > 1) Then
' join the files. Remove the last 3 characters from strFilenames (" + ").
intExitCode = objShell.Run ("%COMSPEC% /C COPY /B " & Left (strFilenames, Len (strFilenames)-3) _
& " """ & outPath & """ /Y", 0, True)
Else
' Not enough file to join
End If
Else
' Can't find folder, exit.
End If
End Function