Quantcast
Channel: chirbit blog » Chirbit
Viewing all articles
Browse latest Browse all 10

How to post to chirbit from the Linux commandline

$
0
0

Here is a handy script for posting audio to your chirbit account via the Linux commandline.

This set of scripts is based on this article on how to post to Twitpic via the commandline by Bernhard Schulte [ @dozykraut ].

The first file you need is called creds.lib and it will live in a credentials folder in your HOME folder.
/home/$USER/credentials/chirb.lib
This is where you add your chirbit username and password.

chirb.lib

checkcreds() {
CNAME="username"
CWORD="password"
}

Create a log file: /home/$USER/chirbit/chirbitlog
To store the JSON results of your posts.

The following bash script can be called chirbitpost and it can live in your /usr/local/bin or /usr/bin folder but remember to make it executable with:

>> chmod +x /usr/local/bin/chirbitpost

chirbitpost

#!/bin/bash
# chirbitpost Version 0.1
# script to post audio files to your chirbit account
# based on http://dozykraut.wordpress.com/2009/05/16/how-to-post-to-twitpic
# -from-the-commandline/

# store paths in variables
credsfile=/home/$USER/credentials/chirb.lib
audiodir=/home/$USER/Audio/

if [[ -O $credsfile ]]
then
. $credsfile
else
exit;
fi

checkcreds

read -e -p "Audio: " audio
read -e -p "Title: " words
read -e -p "Tags: " tags

echo "uploading your audio:"

cargo="media=@${audiodir}${audio}"
myname="username=${CNAME}"
pword="pass=${CWORD}"
title="title=${words}"
tags="tags=${tags}"
method="method=json"
filesource="filesource=user"
lat="latitude=00.000000"
lng="longitude=00.000000"

target="https://api.chirbit.com/chirbit/postChirbit"


RET=$(curl -silent \
           -F "$cargo"\
           -F "$myname"\
           -F "$pword"\
           -F "$title"\
           -F "$tags"\
           -F "$method"\
           -F "$filesource"\
           -F "$lat"\
           -F "$lng"\
            ${target})

echo -e "${RET}" | grep -Po '"shorturl":".*"' \
     | perl -pe 's/"shorturl":"//;s/"$//;s/\\//g;'

echo "${RET}" >> ~/chirbit/chirbitlog

exit;

I then set up a directory in my HOME folder called Audio and place the audio files I wish to post to chirbit into this folder.

When you run chirbitpost it will ask you for the filename, title and tags for your post and then return the shortURL for your post on a successful upload.

Uploads via this manner currently support mp3, wav, m4a, amr and ogg.

If you have any suggestions or improvements to this script let me know and I’ll update it.


Viewing all articles
Browse latest Browse all 10

Trending Articles