Blog

Integration 101: SoundCloud favorites straight to Dropbox

Apr 2013/ Posted By: wotio team

<p>Integration 101 is an ongoing series where I&rsquo;ll describe some of the useful workflows that can be created with the Bipio API in a few easy steps. A basic understanding of <a href="https://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank">RESTful</a> API&rsquo;s and <a href="http://en.wikipedia.org/wiki/Software_as_a_service" target="_blank">SaaS</a> is assumed, and if you have experience with <a href="http://en.wikipedia.org/wiki/Graph_(mathematics)" target="_blank">graphs</a> and <a href="http://en.wikipedia.org/wiki/Graph_traversal" target="_blank">graph traversals</a> that&rsquo;s helpful too but not necessary. If there&rsquo;s anything you&rsquo;d like to see, let me know. Otherwise it&rsquo;s onward and upward with some crazy experiments! <br /><br /><br /><br /> I&rsquo;m a lazy (busy?) <a href="https://soundcloud.com" target="_blank">SoundCloud</a> music consumer, why click favorite &gt; download &gt; have a cup of tea &gt; find in downloads &gt; drag to <a href="https://soundcloud.com" target="_blank">Dropbox</a> folder when I can just click &lsquo;like&rsquo; instead and let a robot do the legwork? <br /><br /><br /><br /> Here&rsquo;s a little assembly for doing just that with Bipio. It takes 2 Channels (<a href="https://bip.io/docs/pods/soundcloud" target="_blank">soundcloud.get<em>favorites</em></a> and <a href="https://bip.io/docs/pods/dropbox" target="_blank">dropbox.savefile</a>) and 1&nbsp;<a href="https://bip.io/docs/resource/rest/bip#resource_rest_bip_type_config" target="_blank">trigger bip</a> to fire a message into the <a href="https://bip.io/docs/resource/rest/bip#resource_rest_bip_hubs" target="_blank">hub</a>. Less clicks, more consumption. <br /><br /><br /><strong>SoundCloud</strong></p>
<pre class="prettyprint"><code>
POST /rest/channel

{
"action" : "soundcloud.get_favorites",
"name" : "Get All The Favorites!"
}

Response

201 Created
{
"id": "23bb1de5-c950-c448-fbbf-000056c1eed6",
... more attributes here
}
</code></pre>
<p><br /><br /><strong>Dropbox</strong></p>
<pre class="prettyprint"><code>
POST /rest/channel

{
"action" : "dropbox.save_file",
"name" : "Save to SoundCloud Folder",
"config" : {
"base_dir" : "/soundcloud"
}
}

Response

201 Created
{
"id": "5d2de02d-a70c-4ffd-ac15-9a97f6cb3d0f",
... more attributes here
}
</code></pre>
<p><br /><br /><br /> So armed with those two id&rsquo;s, creating the bip is easy, &lsquo;get_favorites&rsquo; is an emitter, meaning it generates its own content periodically (in this case, mp3 files and metadata). We can capture these files with a &lsquo;trigger bip&rsquo;, and process the files with an edge pointing to the Dropbox Channel.</p>
<pre class="prettyprint"><code>
{
"config": {
"channel_id": "23bb1de5-c950-c448-fbbf-000056c1eed6"
},
"end_life": {
"time": 0,
"imp": 0
},
"hub": {
"source": {
"annotation": "SoundCloud &gt; Dropbox",
"edges": [
"5d2de02d-a70c-4ffd-ac15-9a97f6cb3d0f"
]
}
},
"name": "SoundCloud to Dropbox",
"type": "trigger"
}
</code></pre>
<p><br /><br /> Synced, just like that. There&rsquo;s no need to transform any content unless its really necessary. Files that appear to a bip from an external service are simply carried across the hub incase channels need them. So, for this basic sync, we know that a file is appearing from SoundCloud, and whatever that file is, gets saved to DropBox. <br /><br /><br /><strong>Extra Credit</strong><br /><br /> ok ok, so that assembly just ends up in big amorphous glob of music in the /soundcloud folder, so of course we should probably template the destination path a little better. Lets re-work the <a href="https://bip.io/docs/resource/rest/bip#resource_rest_bip_hubs" target="_blank">hub</a> in that bip and add a transform to file it by Genre and Artist, which are two of the <a href="https://bip.io/docs/pods/soundcloud" target="_blank">exports the soundcloud.get<em>favorites action already provides</em></a>. <br /><br /></p>
<pre class="prettyprint"><code> <br />
"hub": {
"source": {
"annotation": "SoundCloud &gt; Dropbox",
"edges": [
"5d2de02d-a70c-4ffd-ac15-9a97f6cb3d0f"
],
"transforms" : {
"5d2de02d-a70c-4ffd-ac15-9a97f6cb3d0f" : {
"/soundcloud/[%genre%]/[%artist%]" : "basedir"
}
}
}
}
</code></pre>
<p><br /> Now isn&rsquo;t that better?</p>