Does anyone know of a way to programmatically inspect podcasts and create playlists via Python for iTunes 11 on Windows?
Prior to iTunes 11, one could script it on Windows from Python using the win32com.client package. While technically this is still possible, significant portions of the API have been removed with iTunes 11. Apple has also removed the iTunes COM SDK documentation from its website, and the win32com.client interface has always relied on lazy method lookup (so it's not possible to inspect the wrapped COM object for a list of methods or their expected arguments).
The best solution I've found is to use example scripts found on the web to guess at the API and use iPython to verify assumptions. It appears as though Boolean attributes like Podcast become non-existent when false.
For iTunes 10, one can write
is_podcast = track.Podcast
but in iTunes 11, one needs to write
is_podcast = getattr(track, 'Podcast', False)
To be able to resync any created playlists, one can restore the old sidebar, go to the device, go to the podcasts tab, and check off the playlists to sync (as with iTunes 10).
Related
I need a way to programmatically add a new contact to iPhone from a computer.
Preferably using Python.
Long story short, I have contacts extracted from my old phone, and I want to transfer them to my new iPhone.
A solution that comes to my mind is to fill an addressbook supported by iTunes and then synchronize it with iOS.
But I would like a clean, easy, direct approach over intermixing this and that to find out that it wouldn't work because of something idiotic popped up.
Is there any protocol specification for doing that, or a way to link to iTunes DLLs or dynlibs?
Or perhaps a tweak using Apple Script on Mac.
I solved my personal problem by constructing vCard file containing all contacts from my old phone, then transfering that file to my iPhone manually who happily offered to import all contacts from it into its contacts App.
VCard specification can be found on Wikipedia. It is one nice file format. I used version 2.1 and it worked.
I was afraid that iPhone would accept only XML vCard version, but it worked with 2.1.
That's what I really meant in my comment. I wasn't sure which vCard version iOS uses.
It was extremely easy as my old phone gave me all contacts as a bunch of individual vCard files. So I only needed a simple little program to combine them into one file.
Thanks to apraetor for a comment that gave me that idea.
But the way I wanted it done (as I explained in the question) is possible by using LibIMobileDevice library available at:
http://www.libimobiledevice.org/
I didn't have time to experiment but it should work. And anyone searching for a way to do what I wanted should know about this excellent library.
I'd like someone's answer with details on how it is done and the code (for other's benefit), as I wouldn't play with this for some time. I am currently very busy.
I suspect it is something like:
Get all contacts from iPhone
Add new ones or delete old ones
Synchronize back
as I didn't see anything
there hinting at direct contact manipulation.
I was searching for a Python piece of code which would simulate keystrokes.
I stumble upon something using win32com.client.Dispatch("WScript.Shell").
I am not fan (at all) of Windows but it is to help a friend with automation of a game.
I got a problem, this works fine on notepad or firefox for example, it does write but not on his game.
In order to find wether it comes from his game or my automation I would like to have some details about win32com.client and what really represents WScript.Shell
Thank you all
Some citations:
As we discussed previously, automation objects are COM objects that
expose methods and properties using the IDispatch interface. So how do
we use these objects from Python? The win32com.client package contains
a number of modules to provide access to automation objects. This
package supports both late and early bindings, as we will discuss.
To use an IDispatch-based COM object, use the method
win32com.client.Dispatch(). This method takes as its first parameter
the ProgID or CLSID of the object you wish to create. If you read the
documentation for Microsoft Excel, you'll find the ProgID for Excel is
Excel.Application, so to create an object that interfaces to Excel,
use the following code:
import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
(from this)
The WScript.Shell object provides functions to read system information
and environment variables, work with the registry and manage
shortcuts.
(from: 1 2)
I'm thinking of using Kivy to develop my first mobile app (mainly because i don't want to have to learn any new languages). This app would require access to the user's music library files & metadata. I was looking through Kivy's API Reference and couldn't find anything that would fit as a solution. The Audio Module gave me the impression of background music or SFX functionality.
My question is, is Kivy strictly for creating GUI for applications? If not, could someone provide me an example of how one would go about accessing a user's music library on a mobile device using Kivy/python?
Thanks in advance.
If i understand you well, you want access to the place where the OS store the user's music, not just files provided by yourself, on that, kivy doesn't provide any abstraction, it's up to you either to know the one place they should be on your target plateforms (android/ios i guess), or how to ask the OS where they are, you could use pyjnius (for android) and pyobjus (for ios although it's less advanced right now), to ask for that through the native api, then use kivy api to play them, and if you want to read file metadata, use the usual python libs for that, and for library metadata, i guess that's the native api that should give them.
e.g:
http://developer.android.com/reference/android/media/MediaMetadataRetriever.html
http://developer.android.com/reference/android/media/MediaPlayer.TrackInfo.html
http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html
look promising, but i didn't experiment with them.
To answer the more general question, kivy targets the UI mainly, but try to provide abstractions for the plateforms different ways of doing thing where needed, we don't have everything yet, but at least low level things (notice how you use the same method to load/play an audio file on all plateforms? it's not a given :)), are here.
I've been reading through the FileSystem documentation in Python from here:
http://packages.python.org/fs/filesystems.html
After taking the time to read through it and a bit of Google-ing I didn't quite find the answer I was looking for. I was wondering if it was possible with Python, and avoiding any UAC issues on Windows, if you could 'mount' or display a file free from an FTP server inside Windows Explorer for any other applications to -read- from.
Is something this possible? What's the best approach to achieve it? Thanks in advance!
Windows explorer has built-in support for FTP, instructions with screenshots here.
Open Windows Explorer (My computer)
Right-click anywhere in the folder, and then click Add a Network Location.
This displays the Add Network Connection wizard. Click Next.
In the wizard, select Choose a custom network location, and then click Next.
Enter the name of the FTP site, with the full FTP:// in front of it, and then click Next (something like - for example if you domain name is DOMAIN.NET the full name should look like this: ).
To use a name and password, clear the Log on anonymously check box. Type your FTP Account Username, and then click Next.
By default, the name of the shortcut is the same as the FTP address. If you want to give the shortcut a different name, type it in the Type a name for this network location box. Click Next.
You can even use it from the standard "file" dialog box. Is it enough?
[update]
Out of curiosity, does this have support for FTPS and/or SFTP? – André Caron
#AndréCaron: I think WebDAV with SSL is supported, but no native support for SFTP or FTPS. There are extensions like Swish (opensource) or Expandrive (payware).
This is a non-trivial matter and afaik there exist not such a thing as provide os-level functionality through some lines of magical python code.
A possible solution to emulate your intention could be to create a local webdav proxy, which maps to the ftp-server. I know there exists a feature to attach a webdav-network device to a local drive-letter, but because the last time i touched a windows system was ... - i can't even remember - i can't tell you if you might also attach a ftp-resource this way directly.
I guess looking for a solution on a python level might not be productive in a short-term perspective and even on mid/long-term's not possible without heavy tinkering on your side.
While not a "filesystem" per-se, you can provide a Windows Explorer Namespace Extension which will allow the Windows explorer to browse any virtual file-system. This is used to implement browsing of ZIP archives, for example. Note that this does not provide a real file system drive, so it will not allow you to open the contents of this namespace extension using regular file I/O functions.
The namespace extensions are written in COM, and it is possible to implement COM interfaces in Python.
AFAIK, the only permissions you need are for installing of the namespace extension (the COM DLL, plus the namespace registration). Everything else runs in the logged-in user's context and requires no special permissions.
I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:
For example, the slightest upset seems to be able to break the connection to the COM-Server, once severed there seems to be no safe way to re-connect to the Excel application. There's absolutely no safety built into the COM Application object.
The Excel COM interface will not allow me to safely remote-control two seperate instances of the Excel application operating on the same workbook file, even if they are read-only.
Also when something does go wrong I seldom get any useful error-messages... at best I can except a numerical error-code or a barely useful message such as "An Exception has occurred". It's almost impossible to know why something went wrong.
Finally, COM lacks the ability to control some of the most fundamental aspects of Excel? For example there's no way to do a guaranteed close of just the Excel process that a COM client is connected to. You cannot even use COM to find Excel's PID.
So what if I were to completely abandon COM? Is there an alternative way to control Excel?
All I want to do is run macros, open and close workbooks and read and write cell-ranges? Perhaps some .NET experts know a trick or two which have not yet bubbled into the Python community? What about you office-hackers? Could there be a better way to get at Excel's innards than COM?
There is no way that completely bypasses COM. You can use VSTO (Visual Studio Tools for Office), which has nice .NET wrappers on the COM objects, but it is still COM underneath.
The Excel COM interface will not allow me to safely remote-control two seperate instances of the Excel application operating on the same workbook file, even if they are read-only.
This is not a limitation of COM, this is a limitation of Excel. Excel will not even let you open two files with the same name at the same time if they exist in different directories. It is a fundamental limitation of the Excel program.
To answer your other questions
If you check your python documentation, there should be a way to connect to an existing server if the connection is lost.
The lack of useful error messages again may be to do with Python.
You cannot even use COM to find Excel's PID.
COM is an internal object model and exposed what it wishes. PID are available to outside processes as much as they are to internal, there is no real reason to expose as a COM interface.
It is also possible to run Excel as a server application and use it as a calculation engine. This allows non IT users to specify business rules within Excel and call them through webservices. I have not worked with this myself, but I know a coworker of mine used this once. Walkthrough: Developing a Custom Application Using Excel Web Services could be a good starting point. A first glance at that page looks like it requires Sharepoint. This might not be suiteable for every environment.
Have you looked at the xlrd and xlwt packages? I'm not in need of them any more, but I had good success with xlrd on my last project. Last I knew, they couldn't process macros, but could do basic reading and writing of spreadsheets. Also, they're platform independent (the program I wrote was targetted to run on Linux)!
You could use Jython with the JExcelApi (http://jexcelapi.sourceforge.net/) to control your Excel application. I've been considering implementing this solution with one of my PyQt projects, but haven't gotten around to trying it yet. I have effectively used the JExcelApi in Java applications before, but have not used Jython (though I know you can import Java classes).
NOTE: the JExcelApi may be COM under the hood (I'm not sure).