How to scan only a particular directory in Kodi via JSON-RPC? - raspberry-pi

I'd like to know how I can instruct Kodi to search for new (music) content only inside a particular directory via JSON-RPC.
I have my Kodi (more specifically OSMC) installed on a Raspberry Pi 2 and my music is hosted on another system via Samba (another Linux machine; Banana Pi). Now and then I get new music and first tag the whole album utilizing beets on the Banana Pi. Then, after the music was placed into its destination folder I perform a JSON-RPC call to my Kodi machine using this command:
curl --data-binary "{\"jsonrpc\": \"2.0\", \"method\": \"AudioLibrary.Scan\", \"id\": 1}" -H "content-type: application/json;" http://$KODIHOST/jsonrpc
Now I know that I can pass a parameter directory to the AudioLibrary.Scan command, but I don't quite know the correct syntax for that. When I only want one particular album folder to be scanned, what would the correct syntax look like? Should I pass it the physical path where the music lies on the music host (like smb://{HOST}/HDD1/Media/Music/Albums/{Album_Name}) or rather use the virtual directory names that I have in my Kodi library (like Albums, Compilations etc.)?
I already tried it a few times with the smb:// prefix approach in different variations but it either wouldn't work at all or it would just scan the whole music library which takes quite some time.
Any advice on how to achieve what I want and whether it's possible to the granularity I'd expect is highly appreciated!

I just want to bring this to a close for posterity.
My Problem
When I add new music to my network drive and organize it with beets, I also want it to show up in my Kodi media center. Now, issueing a AudioLibrary.Scan over Kodi's JSON-RPC API would rescan my whole music library which consists of tons of albums and could take up some while. What I needed was a way to tell Kodi to just scan that particular album or single - I know the path to that album after all since I just organized it.
The solution
Actually it was pretty easy since I was almost half-way there. All I had to do was adding an additional object named params to the JSON-RPC call and within that passing the directory string. In this example, my music resides on HDD1/Media/Music/Albums on host BPI1 on my Samba network. So the path to my music that's configured in .kodi/sources.xml on my media center looks like this:
smb://BPI1/HDD1/Media/Music/Albums
That's the path you'll want to take as the directory argument for your RPC call and append the album name to it so that Kodi only scans that particular directory and nothing else. An example request for passing it via cURL could look like this:
{
"json_rpc": "2.0",
"method': "audiolibrary.scan",
"id": 1,
"params": {
"directory": "smb://BPI1/HDD1/Media/Music/Albums/Lenny.Kravitz-It.is.Time.for.a.Love.Revolution"
}
}
This would make Kodi scan Lenny Kravitz' album and spare out all the rest.
EDIT:
If you listen to lots of singles then just append the filename to your directory string and Kodi will only add this one song to your library. Like this:
smb://BPI1/HDD1/Media/Music/Albums/Lenny.Kravitz-It.is.Time.for.a.Love.Revolution/01-Love.Revolution.mp3

Related

Where to write data for web server www-data user

I have a web server on a Pi with a Pi Camera. The goal is to click a button on a web page and have the camera take a picture and save it through a script in /usr/lib/cgi-bin/. Then I want to retrieve all of the pictures via ftp. This works, but I don't think I set up the permissions well. I gave www-data write access to a folder in the pi user's home directory, so it can save the pictures.
While this works, it seems sloppy and insecure. Should I be saving the files in a different location? I would still need to access them via ftp.
Thanks for the help.
/var/lib/$progname is usually a good place to save data by (system) programs. You could also choose the webserver's directory, e.g. /var/www/... (depending on your configuration and version in place).

Openoffice Writer macro that uploads current file to a web service on save

I want to know if this is doable and get some hints about how to achieve this.
I guess at least it would need a confirmation dialog to run the (possibly evil) macro.
I want to produce an OpenOffice document that will upload itself on save to a hardcoded URL.
Is it possible?
What are the rough steps to achieve this?
My guess is:
bind a macro to the save event
have that macro get the current file binary data
have it post this data to a URL
but before researching about how to do this I need to know if this can be done in the first place.
I don't believe you need a macro to do this, instead depending on your OS you can map a FTP or other type of protocol remotely.
For example in windows you can "Map" a FTP as a drive and this would do exactly the same thing as your describing, you open the file from the FTP and upon saving it will then be written to the remote server. FTP is just an example here, there are other platforms you can use.
If you are at all interested in this method then following the instructions below, otherwise disregard.
Mapping a Network Drive in Windows Vista and 7.
Click on Windows start orb and then click on "computer".
Click on map a network drive.
Map a network drive will then open a new dialog box where you can click "connect to a website"
Simply follow that easy to use wizard and click add a new network location (Choose a custom network location)
Type in your FTP address, including username and password.
Finally name your network location to whatever you want.
Just a suggestion, I really don't think you need any macro unless you plan on distributing these files to other people then yes, but they would need to install that macro/plugin on their open office since there is no way to encode the document itself with such features as far as I know.

iOS App-to-App Trasnmission of Data using new Document Support API

Problem:
Building Enterprise Applications of a Suite Nature, and need to be able to pass data from one application to another. Example: App1 is a barcode reader that produces and inventory list. App2 needs a "fresh" copy of the same inventory list information that App1 just produced in order to accomplish its goal of producing purchase orders. The two apps and databases are two large to squeeze together in single app, plus the suite will continue to grow with more and more apps.
Understanding:
I fully understand that "Each" application is in it's own sandbox. However, in reading through the documents regarding the new UIDocumentInteractionController API, it appears that an application can dip outside of the sandbox just a little to "Read-In", "View", or "Open-In" a document that was not apart of the bundle or created within the application.
Data Flow:
I'm trying to keep it simple. I have been using the DocInteraction sample application downloaded from Apple, and another application...called App1 to try and work with a simple text file. In App1, I create a simple txt file, and save it to the documents folder. (But this is still inside the app's sandbox?). in the DocInteraction modified sample, I have been trying to figure a way to "View", "Open-In", or better yet "Read-In" the created txt file. If I can pass a simple txt file between the two, I can include a CSV structure to update the databases on each side when ever the applications are opened.
I have tried to utilize the Launch Options Keys with no luck.
In short, I just can't seem to get my head around:
Where App1's data needs to go?
How to find the data in the other App, say App2?
How do you "Open" the file that exist inside another application's sandbox?
End Result:
I have tried to stay away from the
The Document Interaction docs outline:
Previewing a Document or Presenting Options
Registering Your Support of File Types
Opening Files From Other Apps
Displaying and Printing Quick Look Previews
It is the "Opening Files From Other Apps" that I am most interested with. It directs me to utilize the application:didFinishLaunchingWithOptions: method by passing in dictionary values for the keys. This is where I get lost?? How do I set the keys so that it knows "WHERE" and "WHAT" to look for? And I'm still not clear the proper director that App1 should be saving information to in order for the keys to point to the correct place?
Opening email file attachments and opening pdfs in iBooks can't be the only places where you can utilize this API or else Apple wouldn't have went through all the work, they are already allow to talk from App-To-App.
Note: I'm not trying to get App1 to directly transmit data into App2's files. I don't think that would be allowed by Apple at all! I'm trying to get App1 to zip up its data, save it in proper location, so when user decides to use App2, the data can then be available to App2 by "reading-in" the data.
If someone has a sample application, tutorial, or even a solid idea how to get this working I would really appreciate the help.
-Thanks!
P.S. Somebody with 1,500 or higher reputation please create a "UIDocumentInteraction" tag for stackoverflow!
I got it working last month. Here's my mental model:
App1 creates a file anywhere in its sandbox.
App1 calls docinteraction to display the "Open In" GUI for that file
User picks "Open in App2"
The iOS copies the file from one sandbox to the other and launches App2.
App2 implements didfinishlaunchingwithURL and loads the supplied URL (which is the copy in its sandbox)

Streaming and playing an MP3 stream. .mp3 URL format

I used the sample code from http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html. it runs OK with default URL. But when I replace with my URL "http://dl.mp3.kapsule.info/fsfsdfdsfdserwrwq3/fc90613208cc3f16ae6d6ba05d21880c/4b5244f0/b/7e/b7e80afa18d06fdd3dd9f9fa44b51fc0.mp3?filename=Every-Day-I-Love-You.mp3", this app shows an message as "Audio not Found". But when I put my URL on Address Bar of Web Browser, I can download this .mp3 file.
really, I can't understand why it is?
pleased tell me!
Thank you very much
My guess would be that the app is designed to play a MP3 encoded audio stream with no limit in length (which is different from your ordinary music file). To set this up, you need a streaming server on the client side.
I think you can find out for sure by trying with a different radio station that transmits in MP3. If that works, it's most likely that your app doesn't like your file.
You should, as Vivek recommends, also try using a simpler download URL for your file, in case the App gets confused by the URL's length and/or structure.
As mentioned, this is due to the URL of the file. The AudioStreamer code specifically checks for the extension of the file and tries to figure out the audio type based on that. If you change that logic to handle your custom URLs, it will start working
So to point you in the right direction: open AudioStreamer.m and look for the references of
hintForFileExtension:
This function returns the type of file based on the extension. If you know the file type won't change (always mp3), the quick and dirty solution is to always assign mp3 type without any logic... like this:
err = AudioFileStreamOpen(self, MyPropertyListenerProc, MyPacketsProc, kAudioFileMP3Type, &audioFileStream);
Note: I've put kAudioFileMP3Type constant instead of calculated value
PS yes, it does work with static mp3 files, even though it's designed for streams and hence misses some of the functionality one would expect from a player that plays a static file on the server (caching, prefetching, proper seeking)
Thats because the default url directly points to a file in the webserver, whereas the the url you've mentioned is a HTTP (POST/GET) operation, which the application may not be designed to handle.
I suspect that your URL is one-time-use. When I try to visit it, I see 408 - Request Timeout.
Many links on mass file sharing websites are like this. If you could download the file directly, you wouldn't sit through a page of ads and premium account offers.
Try again with a file on a normal website, like this one.

List Out all video from url

I am trying to list out all Video from a url. For this i m sending an request to "You Tube"
url as "http://www.youtube.com/" and want to list out all available video . But i didn't get anything from that request ? any idea or any documentation hint ?
There are utilities for downloading youtube videos (for example Linux has youtube-dl), but it's not uncommon for sites with large numbers of downloadable files to prevent attempts to simply download everything - and even though you said you wanted to list rather than download all the videos, that's unfortunately what it would suggest to a website administrator.
Besides, files on youtube are not accessed by simple urls like http://www.youtube.com/filename
Something more is required. I don't think you can treat the (what is it?) 11 character alphabet soup as a filename, it's a parameter passed to the software which streams back the video.
EDIT: youtube-dl is a command-line program in Linux and probably BSD. You need to know the URL of the Youtube video so you can type (for example)
youtube-dl http://www.youtube.com/watch?v=Z1JZ9O15280
If you had a list of these URLs you could put them in a file and make a bulk download script - but that takes us back to your original question.
In Firefox I would right-click on a link to a Youtube video and choose 'copy link location'. Then paste the URLs one at a time into a text file. But this question is drifting away from mere programming...