Skip to content

Instantly share code, notes, and snippets.

@yomguy
Last active August 29, 2015 14:07
Show Gist options
  • Save yomguy/dbcf7c55463ad79d6736 to your computer and use it in GitHub Desktop.
Save yomguy/dbcf7c55463ad79d6736 to your computer and use it in GitHub Desktop.

Revisions

  1. yomguy renamed this gist Oct 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. yomguy revised this gist Oct 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deeger-mixcloud.py
    Original file line number Diff line number Diff line change
    @@ -78,7 +78,7 @@ def download(self):
    def main():
    url = sys.argv[-1]
    mc = MixCloud(url)
    mc.download()
    print mc.media_url

    if __name__ == '__main__':
    main()
  3. yomguy renamed this gist Sep 30, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. yomguy revised this gist Sep 30, 2014. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions deeger-mc
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ THE SOFTWARE.
    """


    import sys, urllib2, webbrowser
    import sys, urllib2
    from pyquery import PyQuery as pq


    @@ -44,8 +44,10 @@ class MixCloud(object):
    shift = 0
    if self.url[-1] == '/':
    shift = 1
    self.id = url.split('/')[-1-shift]
    self.slug = url.split('/')[-1-shift]
    self.user = url.split('/')[-2-shift]
    self.media_url = self.get_media_url()
    self.filename = self.user + '_-_' + self.slug + '.m4a'

    def get_media_url(self):
    div = self.pq('.cloudcast-waveform')
    @@ -55,13 +57,11 @@ class MixCloud(object):
    return '/'.join(url)

    def download(self):
    filename = self.user + '_-_' + self.id + '.m4a'
    url = self.get_media_url()
    u = urllib2.urlopen(url)
    f = open(filename, 'wb')
    u = urllib2.urlopen(self.media_url)
    f = open(self.filename, 'wb')
    meta = u.info()
    file_size = int(meta.getheaders("Content-Length")[0])
    print "Downloading: %s Bytes: %s" % (filename, file_size)
    print "Downloading: %s Bytes: %s" % (self.filename, file_size)
    file_size_dl = 0
    while True:
    buffer = u.read(self.block_size)
    @@ -78,9 +78,8 @@ class MixCloud(object):
    def main():
    url = sys.argv[-1]
    mc = MixCloud(url)
    media_url = mc.get_media_url()
    # webbrowser.open(media_url)
    mc.download()

    if __name__ == '__main__':
    main()

  5. yomguy revised this gist Sep 30, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions deeger-mc
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,9 @@ from pyquery import PyQuery as pq


    class MixCloud(object):
    """a MixCloud HTML resource with a hack for downloading related audio file.
    Be carefull, the base_url and the hacky parsing method have been reverse engineered,
    so are not safe, not scalable, even unstable..."""

    base_url = 'https://stream21.mixcloud.com/c/m4a/64/'
    block_size = 8192
  6. yomguy revised this gist Sep 30, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deeger-mc
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ from pyquery import PyQuery as pq
    class MixCloud(object):

    base_url = 'https://stream21.mixcloud.com/c/m4a/64/'
    block_size = 16384
    block_size = 8192

    def __init__(self, url):
    self.url = url
  7. yomguy revised this gist Sep 30, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions deeger-mc
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    # -*- coding: utf-8 -*-

    """
    The MIT License (MIT)
    Copyright (C) 2014 Guillaume Pellerin <[email protected]>
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    @@ -19,9 +23,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    Copyright (C) 2014 Guillaume Pellerin <[email protected]>
    """


  8. yomguy created this gist Sep 30, 2014.
    82 changes: 82 additions & 0 deletions deeger-mc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    """
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    Copyright (C) 2014 Guillaume Pellerin <[email protected]>
    """


    import sys, urllib2, webbrowser
    from pyquery import PyQuery as pq


    class MixCloud(object):

    base_url = 'https://stream21.mixcloud.com/c/m4a/64/'
    block_size = 16384

    def __init__(self, url):
    self.url = url
    self.pq = pq(url=self.url)
    shift = 0
    if self.url[-1] == '/':
    shift = 1
    self.id = url.split('/')[-1-shift]
    self.user = url.split('/')[-2-shift]

    def get_media_url(self):
    div = self.pq('.cloudcast-waveform')
    url = div.attr('m-waveform').split('/')[2:]
    url[0] = self.base_url
    url[-1] = url[-1].replace('json', 'm4a')
    return '/'.join(url)

    def download(self):
    filename = self.user + '_-_' + self.id + '.m4a'
    url = self.get_media_url()
    u = urllib2.urlopen(url)
    f = open(filename, 'wb')
    meta = u.info()
    file_size = int(meta.getheaders("Content-Length")[0])
    print "Downloading: %s Bytes: %s" % (filename, file_size)
    file_size_dl = 0
    while True:
    buffer = u.read(self.block_size)
    if not buffer:
    break
    file_size_dl += len(buffer)
    f.write(buffer)
    status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
    status = status + chr(8)*(len(status)+1)
    print status,
    f.close()


    def main():
    url = sys.argv[-1]
    mc = MixCloud(url)
    media_url = mc.get_media_url()
    # webbrowser.open(media_url)
    mc.download()

    if __name__ == '__main__':
    main()