<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mustapha Turki</title>
    <description>The latest articles on DEV Community by Mustapha Turki (@imtoofar).</description>
    <link>https://dev.to/imtoofar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F152012%2F1f1cede5-9bd2-4410-ae4d-e23f3ae39b9c.jpg</url>
      <title>DEV Community: Mustapha Turki</title>
      <link>https://dev.to/imtoofar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imtoofar"/>
    <language>en</language>
    <item>
      <title>Soundcloud podcasts</title>
      <dc:creator>Mustapha Turki</dc:creator>
      <pubDate>Thu, 13 Jun 2019 19:42:54 +0000</pubDate>
      <link>https://dev.to/imtoofar/soundcloud-podcasts-4a07</link>
      <guid>https://dev.to/imtoofar/soundcloud-podcasts-4a07</guid>
      <description>&lt;p&gt;If you happen to have a list of subscriptions you love on Soundcloud, you might enjoy this story to never miss great music.&lt;br&gt;
The idea came in when I wanted to curate music playlists on a blog, but somehow wanted to automate things a little. Having a registered app on Soundcloud, I used their apis to get the newest tracks. The final result is a playlist looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XlOHBkI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gim265a9j03kdi5ewkyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XlOHBkI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gim265a9j03kdi5ewkyz.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see how you can do the same with your preferences.&lt;/p&gt;


&lt;h2&gt;
  
  
  Get subscriptions
&lt;/h2&gt;

&lt;p&gt;First you need to call the SC API to get your followings data. You do this by hitting the url at /me/followings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function getFollowings() {
  let followings = []
  async function build (href) {
    const options = href || {
      url: `/me/followings`,
      baseURL: SC_BASE_URL,
      method: 'GET',
      params: {
        oauth_token: TOKEN,
        limit: 200,
        linked_partitioning: 1
      }
    }

    const response = await axios(options)

    followings = followings.concat(...response.data.collection)

    process.stdout.write('.')

    if (response.data.next_href) {
      await build(response.data.next_href)
    }

    return null
  }

  await build()

  return followings
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Get tracks
&lt;/h2&gt;

&lt;p&gt;You then loop through the previously fetched followings and get their tracks accordingly. You will have a list of tracks starting from a particular date.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function getTracks (id) {
  const fromDate = new Date()
  fromDate.setDate(fromDate.getDate() - 7)

  const response = await axios({
    url: `/users/${id}/tracks`,
    baseURL: SC_BASE_URL,
    method: 'GET',
    params: {
      'oauth_token': SC_API_TOKEN,
      'created_at[from]': fromDate,
    }
  })

  process.stdout.write('.')

  return response.data
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Plugging them together
&lt;/h2&gt;

&lt;p&gt;You can again filter the tracks to only keep those with a particular duration (in this case, long music podcasts or episodes).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getFollowings()
  .then((users) =&amp;gt; users.map(u =&amp;gt; u.id))
  .then((ids) =&amp;gt; {
    console.log('Followings count', ids.length)
    return Promise.all(ids.map((id) =&amp;gt; {
      return getTracks(id)
    }))
  }).then((tracks) =&amp;gt; {
    const merged = [].concat(...tracks)
    return _.uniqBy(merged, 'id')
      .filter(t =&amp;gt; t.duration &amp;gt; 40 * 60 * 1000 
        &amp;amp;&amp;amp; t.playback_count &amp;gt; 1000
        &amp;amp;&amp;amp; t.comment_count &amp;gt; 10
      )
      .filter(t =&amp;gt; helpers.filterVideosByTitle(t.title))
  })
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's it. If you are interested in discovering more, please visit my blog at &lt;a href="https://stolenbeats.com"&gt;https://stolenbeats.com&lt;/a&gt; and don't hestitate to get in touch.&lt;/p&gt;

</description>
      <category>music</category>
      <category>playlist</category>
      <category>code</category>
    </item>
  </channel>
</rss>
