What language to use? - html

What language should I use if i were to write a script to for example download every video from a specific youtube channel as a mp3 file via http://www.youtube-mp3.org/ ? This has been on my mind for a very long time and it would be nice if anyone could answer this question. I know it should be possible with html to use the tag and do some things with JS but i want a simpler and more reliable way. Thnx. PS. examples appreciated

you can easily use c# with webclient class
using (WebClient Client = new WebClient ())
{
Client.DownloadFile("http://google.com", "a.mpeg");
}

Related

how to interact with HTML forms in delphi using TChromium

i need to update the design of a browser in delphi7 I was using the twebbrowser but he had many problems with javascript and navigation.. so i decide to migrate to Chromium. the problem is that I cannot find code on these components. does anyone know which command would be equivalent to this one in tchromium:
OleObject.Document.all.Item ('ElementbyId', 0) .value: = 'edit1.text';
i need to transfer a text from memo to textarea in html form and at the end send a click on the button on the html form. if anyone knows the commands and can share I appreciate it.
A more flexible alternative than DOM access could be to perform this in Javascript, with the ExecuteJavaScript method of TChromium.
From your summary description, the JS could be something like
document.getElementById('yourtextarea').value = <JSON stringified content of your memo>;
document.getElementById('yourform').submit();
Alternatively, you could implement a JS function in your HTML, and call it with ExecuteJavascript, this way there would not be anything specific (besides the function name) on the Delphi side, and the HTML would be free to evolve.
function setTextAreaAndSubmit(value) {
document.getElementById('yourtextarea').value = value;
document.getElementById('yourform').submit();
}

Is it possible to make "HTML to speech" same like "Text to speech"?

I have one weird requirement that in my existing app I have Text2Speech and for that, I have used AVSpeechSynthesizer to speech text, but now the requirement changed and now I need to convert HTML files data to text something like HTML2Speech.
One Solution we can think:
use HTML parsing and get all text from HTML and use same framework
for Text2Speech.
But the client doesn't want that type of parsing and he wants any API or framework which is providing directly HTML2Speech feature.
Any suggestion or help will be highly appreciated.
As I have worked with HTML parsing and text2speech here you can go with 2 steps
1.get Attribute string from HTML file with below code works in iOS7+
As per your client perspective : if there is any API in market for HTML2Speech may be its Paid or
you are depended on that API if you use any. While Native framework
will help same what you/client wants.
Step 1:
[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:#{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: #(NSUTF8StringEncoding)}
documentAttributes:nil error:nil];
Then you can pass this Attributed String in AVSpeechUtterance
Step 2:
use below method to get HTML2String:
/**
* "ConvertHTMLtoStrAndPlay" : This method will convert the HTML to String
synthesizer.
*
* #param aURLHtmlFilePath : "object of html file path"
*/
-(void)ConvertHTMLtoStrAndPlay:(UIButton*)aBtnPlayPause
isSpeechPaused:(BOOL)speechPaused
stringWithHTMLAttributes:(NSAttributedString*)aStrWithHTMLAttributes
{
if (synthesizer.speaking == NO && speechPaused == NO) {
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:aStrWithHTMLAttributes.string];
//utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
if (IS_ARABIC) {
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"ar-au"];
}else{
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-au"];
}
[synthesizer speakUtterance:utterance];
}
else{
[synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
if (speechPaused == NO) {
[synthesizer continueSpeaking];
} else {
[synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
}
and as usual while you need to stop use below code to stop Speech.
/**
* "StopPlayWithAVSpeechSynthesizer" : this method will stop the playing of audio on the application.
*/
-(void)StopPlayWithAVSpeechSynthesizer{
// Do any additional setup after loading the view, typically from a nib.
[synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
Hope This will help you to get HTML2Speech feature.
There's two parts to a solution here...
Presumably you don't care about the formatting in the HTML--after all, by the time it gets to the speech synthesizer, this text is to be spoken, not viewed. AVSpeechSynthesizer takes plain text, so you just need to get rid of the HTML markup. One easy way to do that is to create an NSAttributedString from the HTML, then ask that attributed string for its underlying plain-text string to pass text to the synthesizer.
In iOS 10 you don't even have to extract the string from an attributed string — you can pass an attributed string directly to AVSpeechUtterance.
One way or another it will always be parsing HTML to something else if you don't want to read files. If the client want direct HTML2Speech solution you can provide a method that takes html file as an argument and read it. What's happening with this file under the hood should not bother client that much as long as it's clean and not causing problems.
What happen when client will ask for Markdown2Speech or XML2Speech. For what i see in your desciption is better to have it for now in one framework with two public methods Text2Speech and HTML2Speech that will take as argument link to file or NSString.
So as #rickster suggest it can be NSAttributedString or NSString. There is a lot of parsers out there, Or if you want own solution you can remove everything what's inside < and > and change encoding.
The safest method will be to extract the text and use existing text2speech API.
Though if you are sure that the browser will be chrome then Speech Synthesis API maybe helpful. But this API still not fully adopted by all browsers; it will be a risky solution.
You can find necessary info regarding this API at
https://developers.google.com/web/updates/2014/01/Web-apps-that-talk-Introduction-to-the-Speech-Synthesis-API?hl=en
https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#examples-synthesis
https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API
There is no direct API for HTML to Speech except Speech Synthesis API mentioned above. Though you can try http://responsivevoice.org/. But I think this one is also based on browser's Speech Synthesis or Speech generation at server. So to use this one, you would have to extract text and pass the text to API to get the speech

Action script - printing

You can write action scripts to do flash print.
Is there a way to print define the contents in the iframe and print?
Example:
This is a good flash print demo script.
print_btn.addEventListener(MouseEvent.CLICK,printContent);
function printContent(evt:MouseEvent) {
var printJob:PrintJob = new PrintJob();
if (printJob.start()) {
if (content_mc.width>printJob.pageWidth) {
content_mc.width=printJob.pageWidth;
content_mc.scaleY=content_mc.scaleX;
}
printJob.addPage(content_mc);
printJob.send();
}
}
The content_mc is defined within the .fla file. I would like the action script to look at the current web page and print the content within the ifame.
Can this be done?
Example will be helpful since I’m just learning action scripting.
Thank you for any help!
Directly no. With a couple of "hacks" yeah. So to get started you can use ExternalInterface in Flex to communicate with javascript. That'll be necessary since you can't directly render the IFrame as the browser would within Flex (aside from AIR, even so it's not going to be a 1:1 match in all scenarios). The second step would be to call window.print() in a javascript function. Your AS would look something like this:
ExternalInterface.call("doJSPrint");
The last "hack" involved would be to set the media in css to print/screen appropriately on the other elements in the HTML page to just get the IFrame to print.
Relevant links:
http://www.w3.org/TR/CSS2/media.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html
http://www.spikything.com/blog/index.php/2009/08/23/externalinterface_howto/
Good luck, let me know if you think I can provide more info.

Link in swt browser to file inside jar file [duplicate]

I want to implement a help system for my tiny SWT desktop application.
I've thought about a SWT browser widget containing a single html markup page and a set of anchors to navigate (there are only very few things to explain).
Everything works fine, but how do I load the html file from a jar?
I know aboutgetClass().getClassLoader().getResourceAsStream("foo");, but what is the best practice when reading from the input stream? The answer to Load a resource contained in a jar dissuades using a FileInputStream.
Thanks in advance
Well, I found a rather simple solution that obviously just works:
InputStream in = getClass().getClassLoader().getResourceAsStream("html/index.html");
Scanner scanner = new Scanner(in);
StringBuffer buffer = new StringBuffer();
while(scanner.hasNextLine()) {
buffer.append(scanner.nextLine());
}
browser.setText(buffer.toString());
i tend to use commons-io for such a task giving me simple abstraction methods like IOUtils.toString(InputStream in); and leaving the choice of best implementations to the able people at apache ;)
commons-io: http://commons.apache.org/io/
apidocs: http://commons.apache.org/io/api-release/index.html

Get Current Browser URL - ActionScript 3

I'm trying to get current browser url. I have already tried with External Call, and it didn't work. And with loaderInfo.url I receive the current SWF url.
Give this a go:
import flash.external.ExternalInterface;
var url:String = ExternalInterface.call("window.location.href.toString");
if (url) textfield.text = url;
should do the trick.
There are a couple of ways to solve this problem, however all of them involve the use of JavaScript to query the browser directly.
My preferred way to solve this problem would be to provide the URL via a flashVar property, direct from the embed code (personally, I would reccomend using SWFObject to make this easier); don't forget you will need to URL Encode it to avoid markup issues.
var flashvars = {
browserURL: escape(location.href)
};
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0", "expressInstall.swf", flashvars);
Now you will be able to access the Browser URL via the loaderInfo object:
trace(stage.loaderInfo.parameters["browserURL"]);
note that this will only work if you have control of generated HTML for your SWF file - if users are going to be grabbing the SWF and writing their own embed HTML, it's not going to work.
If you don't have control of the flash embed HTML, then you will need to get flash to query the browser at runtime using the ExternalInterface class; other people have suggested the use of "window.location.href.toString" however this can prove problematic in IE6, I find the following works reliably across all browsers
const browserURL : String = ExternalInterface.call("eval", "window.location.href");
Note that in order for this to work, you will need to grant JavaScript access to your Flash movie, this is done, again, via the HTML embed code and the allowScriptAccess param
var url:String = loaderInfo.loaderURL;
seems to work too.
I would try passing the required info in as a flashvar. Not the best out of the box solution I know, but it will work.
Flash: FlashVars in AS3
i think its posible to use the external interface an do it with javascript window.location
I have been using flash for a long time and never noticed this one. It only gives the domain though for security. It does work through loaded swfs as well. Not sure about iframes.
Security.pageDomain