Starting with Pymaxe 0.50, the application was splitted up in two parts: a library and a GUI interface (actually, there was supposed to be two applications (the "libpymaxe" and Roxe - that's why, on Windows systems, Pymaxe installs in Program Files\Roxe), but finally this thing never happened). The library is actually a class which acts as an interface for Pymaxe's plugins. This simplified a lot the porting of Pymaxe in other languages, making the base part of it indeppendent of the GTK graphic toolkit.
Currently libPymaxe is provided for two programming languages: Python and PHP. I will work to port these classes on other languages, such Perl or Java. To download the library, please select the coresponding programming language:
libPymaxe for PHP | libPymaxe for Python
If you want to start using libPymaxe in your application, first you need to include it in your source files and then to initialize it. In PHP, this is done with:
$pymaxe = new Pymaxe;
$pymaxe->init();
while in Python we use
import libpymaxe
Pymaxe = libpymaxe.Pymaxe()
Next you just need to call the desired functions from the initialized class. For example, if we want to call readplugins() function, in PHP we will do:
and in Python we will do:
Here is a list with the available functions in Pymaxe class. Use this as a simple guide of using libPymaxe; for more advanced stuff, see Pymaxe's source code.
setPluginsDir(str plugins_path) - specify the path where plugins are located. By default, this is 'plugins/' (relative path).
readPlugins() - read the plugins_path directory and search for plugins. The list of found plugins will be stored in the plugins array (or list, in Python), inside the Pymaxe class.
loadPlugin(str plugin_name) - load the specified plugin_name plugin. Please note that plugins must be loaded with this function before using them. To load all the plugins first read the available plugins using the readPlugins() function and then do a loop over plugins array (or list, in Python) calling loadPlugin(current_iteration_plugi_name) on each iteration. Returns true if loading was successfull.
unloadPlugin(str plugin_name) - unload the specified plugin_name plugin. This will remove the plugin from plugins array (or list).
getActivePlugins() - returns an array (or a list) of active (loaded) plugins.
getPluginInfo(str plugin_name) - get informations about plugin_name plugin. Returns an associative array (or dictionary, in Python) with the following keys: name, version, author, update.
search(str query[, str plugin_name]) - search for query. If plugin_name is not specified, will search using all active (loaded) plugins. Otherwise will search only using plugin_name plugin. Returns an associative array (or a dictionary, in Python) with the following structure:
Array
(
[PLUGIN_NAME] => Array
(
[RESULT_NUMBER] => Array
(
[0] => FILE_TYPE,
[1] => TITLE,
[2] => URL,
[3] => TIME,
)
[RESULT_NUMBER] => Array
(
[0] => FILE_TYPE,
[1] => TITLE,
[2] => URL,
[3] => TIME,
)
................................
)
)
where:
- PLUGIN_NAME is the plugin name which results belong to;
- RESULT_NUMBER is a key with the item number in results list
- FILE_TYPE is a value which represents the file type (FILE_TYPE_AUDIO or FILE_TYPE_VIDEO)
- TITLE is the result's title (ussualy in format Artist - Track)
- URL is the address of the webpage where the audio or video file is located
getDetails(str plugin_name, str url) - get details about a results obtained using search() function. plugin is the name of the plugin which will be used to retrieve needed information (that's why the results list include a PLUGIN_NAME array) and url is the address of the webpage where the audio or video file is located (for example, http://www.youtube.com/v=MeFXLA-WtaI). Returns an associative array (or a dictionary, in Python) with the following keys: url, title, length, type, fsize, downurl, where:
- url is the webpage address where the stream is located
- title is the stream's title (ussualy in format Artist - Track)
- length is the stream's length in format MM:SS
- type depending on the file type it will be FILE_TYPE_AUDIO or FILE_TYPE_VIDEO
- fsize is the file size, in bytes
- downurl is the actual URL to the stream. This is what you want to download or play in a media player.
getPluginObj(str plugin_name) - returns an object representing the plugin_name plugin. The plugins are actually classes so you can access methods or variables inside them.
Examples
This is a typical usage of libpymaxe in PHP:
include ('pymaxe.inc.php');
<code># Initialize Pymaxe class
$pymaxe = new Pymaxe;
$pymaxe->init();</code>
<code># Load all available plugins
foreach ($pymaxe->plugins as $plugin_name=>$plugin_file){
$pymaxe->loadPlugin($plugin_name);
}</code>
<code># We want to search for Never gonna give you up
$results_list = $pymaxe->search('Never gonna give you up');</code>
<code># From the results list, we pick up the first result offered by Trilulilu.
$item = $results_list['Trilulilu'][0];</code>
<code># We need the webpage's URL where the file is streamed. This is at the key 2 in the $item array
$url = $item[2];</code>
<code># Now we want the stream's URL. First, we get the stream's details:
$details = $pymaxe->getDetails('Trilulilu', $url);</code>
<code># Then we display the stream's URL. This is found on the 'downurl' key in the returned array before:
echo $details['downurl'];
</code>
There's an another case when we already know the stream's webpage URL, useful when you want to offer a YouTube or Trilulilu downloading service: