Sunday, June 9, 2013

Bash Download of M3U MP3 Playlist


I have a list of MP3’s I regularly listen to which are all pulled from a website via a “*.m3u” list.  My wife wanted the songs, but she wants to listen to them on her IPhone.  So I whipped up this Bash script to take a “*.m3u” file as an argument, and pull all the tracks in the playlist down to the current directory.

If you look at the m3u playlist in Itunes, you may see some streaming files that are of duration “continuous”.  Those will not download correctly using this method.

#!/bin/bash

# Takes a list of MP3's (generally an m3u file) and downloads all to current directory
# www.klugedeforce.com
#
if [ $# != 1 ] ; then
  echo "usage $0 mp3_list_file.txt"
  echo "file list can have any extension, but should contain list of files one per line:"
  echo ""
  echo "http://downloads.hpmgl.net/mp3song_file1.mp3"
  echo "http://downloads.hpmgl.net/song_file2.mp3"
  echo "http://downloads.hpmgl.net/song_file3.mp3"

elif [ -e $1 ] ; then
   IFS=$'\r\n'
   for line in $(cat $1); do
       trimmed_line="$(echo ${line} | sed 's/^[ \t\r\n]*//g' | sed 's/[ \t\r\n]*$//g')"
       # trimmed_line=$line | sed 's/^[ \t\r\n]*//g' | sed 's/[ \t\r\n]*$/b/g'
       outfile=${trimmed_line##http://*/}
       if [ -n "$outfile" ] ; then
       `curl "${trimmed_line}" > "${outfile}"`;
          echo $outfile;
       fi
   done
else
   echo "Filename $1 not found"
fi          


Wednesday, June 5, 2013

Magento XMLRPC Credit Memo List with Filter


Magento XMLRPC Credit Memo List with Filter

There are some examples of using credit memos on the Magento API documentation web page:


But the only examples there are for the SOAP implementation.  However, the Magento API also supports the XMLRPC protocol. 

The following code works as is for the Zend_XmlRpc_Client, but the key thing is the parameter formatting, which is not platform specific.

$params = array( array(‘order_id’ => ‘12345678’),
                  array(‘whatever_field’ => $target_val),
                  array(‘another_field’ => $another_val),
          );

$this->client = new Zend_XmlRpc_Client($apiUrl);

$session = $this->client->call('login', array($this->apiUser, $this->apiKey));

$response = $this->client->call('call',
                 array($session, 'sales_order_creditmemo.list', $params));