How to detect DVD drive name with nodejs? - node.js

i create an cross platform electron application for playing video from dvd (in offline mode).
when user inserted DVD in the driver , the xml file (list of videos url and details) should load from DVD.
so for video url i need access to dvd driver name.
<video src="file:/video/video.mp4">
*file:/ should be dvd drive name.
there was a npm package but not working
https://www.npmjs.com/package/drivelist

there was another package return system volume as dvd-rom.
https://www.npmjs.com/package/diskinfo
this code return the dvd drive name, but i'm not sure its good idea or not.
var d = require('diskinfo');
var cddisk;
d.getDrives(function (err, aDrives) {
for (var i = 0; i < aDrives.length; i++) {
if (aDrives[i].available == 0) {
cddisk = aDrives[i].mounted;
console.log(cddisk);
}
}
});
also this package not supported in mac.

Related

node.js how to read file in stream from remote server

In node.js I am trying to watch and read a text file on filechange.For this, I am using below code and it is working absolutely fine.
var fs = require('fs'),bite_size = 256,readbytes = 0,file;
fs.open('testread.txt', 'r', function(err, fd) {
file = fd; //readsome();
var func = (function readsome() {
var stats = fs.fstatSync(file); // yes sometimes async does not make sense!
if(stats.size<readbytes+1) {
setTimeout(readsome, 1000);
}
else {
fs.read(file, new Buffer(bite_size), 0, bite_size, readbytes, function (err, bytecount, buff) {
console.log(buff.toString('utf-8', 0, bytecount));
readbytes+=bytecount;
process.nextTick(readsome);
});
}
})();
});
But this works only for local file and now I need to read text file from remote server ( may be linux or windows) in same way.
Please help , how can I use remote server login information like below
IP address = "XXX.XXX.XX.XX";,
username = username,
password = password,
filepath = "/root/testread.txt" or "D:\testread.txt"
and read the data from text file present at filepath in remote server.
fs uses the local filesystem.
To access remote files you need to use some network protocol (NTFS for Windows and ssh or ftp for linux for example)
Those protocols expose files to remote access, you cannot access the filesystem of a remote host not using them

Android Studio - prompt to open a downloaded file with any application available

I have an application which receives urls from a server, using Firebase. When the url is received, the file at that url is automatically saved on the local storage (they are gpx files).
But after this, I want my application to prompt the user to open the downloaded file with whatever navigation application they have installed on their phone. Something similar to when you go to the file manager yourself, click on a file, and the system shows you all applications which could open that file, and lets you chose (or opens it directly with your default setting, if you have one).
I have not been able to find anything about this, and searches containing "android studio" and "open file" show mostly tutorials about how to manage the source files themselves, so they are not helpful at all.
You could do something like:
String mimeType = myMime.getMimeTypeFromExtension(fileExt(getFile()).substring(1));
newIntent.setDataAndType(Uri.fromFile(getFile()),mimeType);
private String fileExt(String url) {
if (url.indexOf("?") > -1) {
url = url.substring(0, url.indexOf("?"));
}
if (url.lastIndexOf(".") == -1) {
return null;
} else {
String ext = url.substring(url.lastIndexOf(".") + 1);
if (ext.indexOf("%") > -1) {
ext = ext.substring(0, ext.indexOf("%"));
}
if (ext.indexOf("/") > -1) {
ext = ext.substring(0, ext.indexOf("/"));
}
return ext.toLowerCase();
}
}
This allows you to get the type based on file extension. Then just startActivity passing in the newIntent. This should achieve what you are looking for.

Windows 10 IOT Network File

i'm trying to access videos from local network with Windows 10 IOT Core.
I Have added Permissions:
internetClient
privateNetworkClientServer
internetClientServer
enterpriseAuthentication
videosLibrary
removableStorage
remoteSystem
FileTypeAssociation are set in manifest.
folderPicker.PickSingleFolderAsync() return null:
var folderPicker = new FolderPicker();
//folderPicker.SuggestedStartLocation = PickerLocationId.HomeGroup;
folderPicker.FileTypeFilter.Add(".avi");
folderPicker.FileTypeFilter.Add(".mp4");
folderPicker.FileTypeFilter.Add(".mpg");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
var files = await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByTitle);
this throw a fileNotFountException:
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(#"\\192.168.0.10\videos\TestVideos\");
StorageFile file = await folder.GetFileAsync("video1.avi");
the codes work in debug x86 (windows 10 App), but dont on the ARM(RT) (Windows 10 IOT)
As i can understand, they are some limitation for security. Its there a way to disable this security? Or is it possible to write a library to access files?
tanks!
windows IOT version : 10.0.14393.448
Hardware: Raspberry Pi 2 Model B
Network: Ethernet Cable

Unauthorized access while copying files onto USB via OTG Xamarin Android

I am writing a code to paste files onto the USB Sandisk pen drive connected to my android KitKat device using an OTG cable.
I am using the following code snippet.
Using the following code I get a popup asking permission and on allowing it the mUsbManager.HasPermission(device); returns true, but while i copy the file I get an Unauthorized access exception.
I have set the WRITE_EXTERNAL_STORAGE permission.
//Code Snippet
UsbManager manager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
var deviceList = manager.DeviceList;
IEnumerable deviceIterator = deviceList.Values.AsEnumerable();
if (deviceIterator.Count() > 0)
{
var device = deviceIterator.ElementAt(0);
ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
var mPermissionIntent = PendingIntent.GetBroadcast(_mainActivity.ApplicationContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
UsbManager mUsbManager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
mUsbManager.RequestPermission(device, mPermissionIntent);
bool perm = mUsbManager.HasPermission(device);
if (perm)
{
string FileNameSource = "/storage/emulated/0/FileNotPresent.txt";
string FileNameDestination = "/storage/2A85-5687/FileNotPresent.txt";
File.Copy(FileNameSource, FileNameDestination);
}
}
Second question how can i get the path for the connected USB that as of now i have hard coded into the FileNameDestination variable.
A sample code snippet will really be helpful. Thanks.

Headless browsers and Windows Azure Websites

I´m trying to use a headless browser for crawling purposes to add SEO features in a open source project i´m developing.
The project sample site is deployed via Azure Websites.
I tried several ways to get the task working using different solutions like Selenium .NET (PhantomJSDriver, HTMLUnitDriver, ...) or even standalone PhantomJs .exe file.
I´m using a headless browser because the site is based in DurandalJS, so it needs to execute scripts and wait for a condition to be true in order to return the generated HTML. For this reason, can´t use things like WebClient/WebResponse classes or HTMLAgilityPack which use to work just fine for non-javascript sites.
All the above methods works in my devbox localhost environment but the problem comes when uploading the site to Azure Websites. When using standalone phantomjs the site freezes when accessing the url endpoint and after a while return a HTTP 502 error. In case of using Selenium Webdriver i´m getting a
OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:XXXX
I think the problem is with running .exe files in Azure and not with the code. I know it´s possible to run .exe files in Azure CloudServices via WebRole/WebWorkers but need to stay in Azure Websites for keep things simple.
It´s possible to run a headless browser in Azure Websites? Anyone have experience with this type of situation?
My code for the standalone PhantomJS solution is
//ASP MVC ActionResult
public ActionResult GetHTML(string url)
{
string appRoot = Server.MapPath("~/");
var startInfo = new ProcessStartInfo
{
Arguments = String.Format("{0} {1}", Path.Combine(appRoot, "Scripts\\seo\\renderHTML.js"), url),
FileName = Path.Combine(appRoot, "bin\\phantomjs.exe"),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
StandardOutputEncoding = System.Text.Encoding.UTF8
};
var p = new Process();
p.StartInfo = startInfo;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
ViewData["result"] = output;
return View();
}
// PhantomJS script
var resourceWait = 300,
maxRenderWait = 10000;
var page = require('webpage').create(),
system = require('system'),
count = 0,
forcedRenderTimeout,
renderTimeout;
page.viewportSize = { width: 1280, height: 1024 };
function doRender() {
console.log(page.content);
phantom.exit();
}
page.onResourceRequested = function (req) {
count += 1;
//console.log('> ' + req.id + ' - ' + req.url);
clearTimeout(renderTimeout);
};
page.onResourceReceived = function (res) {
if (!res.stage || res.stage === 'end') {
count -= 1;
//console.log(res.id + ' ' + res.status + ' - ' + res.url);
if (count === 0) {
renderTimeout = setTimeout(doRender, resourceWait);
}
}
};
page.open(system.args[1], function (status) {
if (status !== "success") {
//console.log('Unable to load url');
phantom.exit();
} else {
forcedRenderTimeout = setTimeout(function () {
//console.log(count);
doRender();
}, maxRenderWait);
}
});
and for the Selenium option
public ActionResult GetHTML(string url)
{
using (IWebDriver driver = new PhantomJSDriver())
{
driver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.CssSelector("#compositionComplete"));
});
var content = driver.PageSource;
driver.Quit();
return Content(content);
}
}
Thanks!!
You cannot execute exe files in the shared website environment, either you have to use the web services or you have to set up a proper (azure) virtual machine.
The free shared website service is really basic, and won't cut it when you need more advanced functionality.
See this question and accepted answer for a more elaborated answer: Can we run windowservice or EXE in Azure website or in Virtual Machine?
I am not sure about shared and basic website environment but i am successfully run ffmpeg.exe from standart website environment. Despite that still phantomjs and even chromedriver itself is not working.
However i am able run Firefox driver successfully. In order to do that
I copied latest firefox directory from my local to website and below code worked well.
var binary = new FirefoxBinary("/websitefolder/blabla/firefox.exe");
var driver = new FirefoxDriver(binary, new FirefoxProfile());
driver.Navigate().GoToUrl("http://www.google.com");

Resources