soundcloud-lib icon indicating copy to clipboard operation
soundcloud-lib copied to clipboard

Adding HLS assembly support

Open willb0 opened this issue 1 year ago • 5 comments

I see HLS assembly support mentioned in the README for songs without downloadable links. What kind of effort would this take?

I can work on this, would enjoy some helpful pointers in the right direction

willb0 avatar Apr 03 '23 03:04 willb0

When I first encountered this issue, I looked for existing python libraries that assembled HLS streams and I didn’t find any.

That was a while ago, so if you can find third party libs that do the work of assembling HLS streams, I’d be willing to accept them as dependencies. Otherwise, you’d need to read up on HLS and how they represent segmented media files and download the parts and concatenation them into full files.

3jackdaws avatar Apr 08 '23 07:04 3jackdaws

cheers, circling back to work on this over the summer.

spent a brief period researching how to implement this when you first responded, but realized I would have to spend significant time and dropped it/forgot to respond. I'll update on progress and hopefully open a PR, otherwise will close

willb0 avatar May 23 '23 00:05 willb0

I'm super new to this and don't really understand what your talking about. But I found this library which claims to compile HLS into a file. Not sure if its relevant for what you guys need.

https://github.com/zmwangx/caterpillar

ruffish avatar Aug 03 '23 21:08 ruffish

As a workarround you can pass track URL to YT-DLP. It parses HLS streams properly and it's written in Python, too.

PatrykMis avatar Aug 14 '23 19:08 PatrykMis

Could something like this work?

import os
import subprocess

# ...


class Track:
    # ...

    def get_hls_url(self):
        """Get url"""
        for transcode in self.media["transcodings"]:
            if transcode["format"]["protocol"] == "hls":
                return transcode["url"] + "?client_id=" + self.client.client_id
        return None

    def download(self, path=None, filename=None):
        """Download track to file"""
        if not path:
            path = os.getcwd()
        if not filename:
            filename = self.title + ".mp3"
        if not filename.endswith(".mp3"):
            filename += ".mp3"
        if not os.path.exists(path):
            os.makedirs(path)
        url = self.get_hls_url()

        ## Download HLS stream using ffmpeg
        subprocess.run(["ffmpeg", "-i", url, f"{path}/{filename}"])
        return f"{path}/{filename}"

muloka avatar Oct 23 '23 01:10 muloka