chrippa / livestreamer

Command-line utility that extracts streams from various services and pipes them into a video player of choice. No longer maintained, use streamlink or youtube-dl instead.
http://livestreamer.io/
BSD 2-Clause "Simplified" License
3.88k stars 583 forks source link

afreeca.com service changed,please fix it. #982

Closed trocknet closed 9 years ago

trocknet commented 9 years ago

rmtp stream work,but hls stream not work. thanks.

ghost commented 9 years ago

What exactly do you mean? At least the RTMP stream works just fine here:

livestreamer "http://play.afreeca.com/sogoodtt" live
[cli][info] Found matching plugin afreeca for URL http://play.afreeca.com/sogoodtt
[cli][info] Available streams: live (worst, best), live_hls
[cli][info] Opening stream: live (rtmp)

Only when I try to access the HLS stream I get an error message:

livestreamer "http://play.afreeca.com/sogoodtt" live_hls
[cli][info] Found matching plugin afreeca for URL http://play.afreeca.com/sogoodtt
[cli][info] Available streams: live (worst, best), live_hls
[cli][info] Opening stream: live_hls (hls)
[cli][error] Could not open stream: Unable to open URL: http://chromecast.afreeca.gscdn.com/livestream-05/auth_playlist.m3u8 (400 Client Error: Bad Request)
ghost commented 9 years ago

I see you edited your original post. Next time be more specific, when you submit a bug report.

trocknet commented 9 years ago

sorry,i will be more specific next time.

trocknet commented 9 years ago

i try to fix it . but i don't known python ,and i can't code it in python-style.

import re

from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import RTMPStream, HLSStream

CHANNEL_INFO_URL = "http://live.afreeca.com:8057/api/get_broad_state_list.php"
KEEP_ALIVE_URL = "{server}/stream_keepalive.html"
STREAM_INFO_URLS = {
    "rtmp": "http://sessionmanager01.afreeca.tv:6060/broad_stream_assign.html",
    "hls": "http://resourcemanager.afreeca.tv:9090/broad_stream_assign.html"
}
HLS_KEY_URL = "http://api.m.afreeca.com/broad/a/watch"

CHANNEL_RESULT_ERROR = 0
CHANNEL_RESULT_OK = 1

_url_re = re.compile("http(s)?://(\w+\.)?afreeca.com/(?P<username>\w+)")

_channel_schema = validate.Schema(
    {
        "CHANNEL": {
            "RESULT": validate.transform(int),
            "BROAD_INFOS": [{
                "list": [{
                    "nBroadNo": validate.text
                }]
            }]
        }
    },
    validate.get("CHANNEL")
)
_stream_schema = validate.Schema(
    {
        validate.optional("view_url"): validate.url(
            scheme=validate.any("rtmp", "http")
        )
    }
)

class AfreecaTV(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)

    def _get_channel_info(self, username):
        headers = {
            "Referer": self.url
        }
        data = {
            "uid": username
        }
        res = http.post(CHANNEL_INFO_URL, data=data, headers=headers)

        return http.json(res, schema=_channel_schema)

    def _get_hls_key(self, broadcast,username):
        headers = {
            "Referer": self.url
        }
        data = {
            "bj_id": username,
            "broad_no": broadcast
        }
        res = http.post(HLS_KEY_URL, data=data, headers=headers)

        return http.json(res)

    def _get_stream_info(self, broadcast, type):
        params = {
            "return_type": "gs_cdn",
            "use_cors":"true",
            "cors_origin_url":"m.afreeca.com",
            "broad_no":"{broadcast}-mobile-hd-{type}".format(**locals()),
            "broad_key": "{broadcast}-flash-hd-{type}".format(**locals())
        }
        res = http.get(STREAM_INFO_URLS[type], params=params)
        return http.json(res, schema=_stream_schema)

    def _get_hls_stream(self, broadcast,username):
        keyjson=self._get_hls_key(broadcast,username)
        if keyjson["result"] != CHANNEL_RESULT_OK:
            return
        key=keyjson["data"]["hls_authentication_key"]
        info = self._get_stream_info(broadcast, "hls")
        if "view_url" in info:
            return HLSStream(self.session, info["view_url"]+"?aid="+key)

    def _get_rtmp_stream(self, broadcast):
        info = self._get_stream_info(broadcast, "rtmp")
        if "view_url" in info:
            params = dict(rtmp=info["view_url"])
            return RTMPStream(self.session, params=params, redirect=True)

    def _get_streams(self):
        match = _url_re.match(self.url)
        username = match.group("username")

        channel = self._get_channel_info(username)
        if channel["RESULT"] != CHANNEL_RESULT_OK:
            return

        broadcast = channel["BROAD_INFOS"][0]["list"][0]["nBroadNo"]
        if not broadcast:
            return

        flash_stream = self._get_rtmp_stream(broadcast)
        if flash_stream:
            yield "live", flash_stream

        mobile_stream = self._get_hls_stream(broadcast,username)
        if mobile_stream:
            yield "live", mobile_stream

__plugin__ = AfreecaTV
prech commented 9 years ago

Just wanted to corroborate this issue. It appears many of the newer Afreeca streams are HLS-only, so there is no RTMP alternative available for them.

For example: afreeca.com/cantob afreeca.com/momo130

If there might be an easy fix available, it'd be much appreciated!

astarrh commented 9 years ago

I'm running into the same issue..

[cli][info] Found matching plugin afreeca for URL afreeca.com/rlatjdgus228
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (hls)
[cli][error] Could not open stream: Unable to open URL: http://chromecast.afreeca.gscdn.com/livestream-02/auth_playlist.m3u8 (400 Client Error: Bad Request)
astarrh commented 9 years ago

If run it with the option --player-passthrough hls VLC launches successfully, but gives me the following error:

Your input can't be opened:
VLC is unable to open the MRL 'http://chromecast.afreeca.gscdn.com/livestream-02/auth_playlist.m3u8'. Check the log for details.

This is what appears in VLC's "messages" if I manage to open it before the error:

http error: error: HTTP/1.1 400 Bad Request
access_mms error: error: HTTP/1.1 400 Bad Request
core error: open of `http://chromecast.afreeca.gscdn.com/livestream-02/auth_playlist.m3u8' failed
trocknet commented 9 years ago

@prech @astarrh just try my patch.it work for me. save the code to afreecatv.py and replace afreecatv.pyc.

prech commented 9 years ago

@prech @astarrh just try my patch.it work for me. save the code to afreecatv.py and replace afreecatv.pyc.

Thank you, that worked beautifully! Works for both RTMP and HLS streams now!

astarrh commented 9 years ago

@prech @astarrh just try my patch.it work for me. save the code to afreecatv.py and replace afreecatv.pyc.

Worked perfectly for me as well. Thanks trocknet!

LostInInaka commented 9 years ago

thanks @trocknet ! worked great for me as well!

AleXoundOS commented 9 years ago

trocknet, thank you very much!!

(also, if you don't already know, you have moderator permissions at snipealot channels)

ghost commented 9 years ago

hi your solution works but now i can't view 19+ channel, can you help me fix it?

trocknet commented 9 years ago

it seems that afreeca has fixed the "19+" hole......

ghost commented 9 years ago

no way to bypass the 19+ hole again?

zelkovazone commented 9 years ago

hi.. i have same problem.. after trying this patch.. the streamer can stream hls.. but its buffering like crazy.. did anyone experience this too ?

oh and i got this error http://puu.sh/iYUM2/8bd80f783c.png

trocknet commented 9 years ago

it seems that the cdn that afreeca use abroad is not avaliable,try Korean cdn ip.

pmerc98 commented 9 years ago

So can you explain how to apply this patch, what I did was that I copied the code to a .py file, then I compiled it to .pyc and replaced afreeca.pyc with the new one but Im still getting the same error, meaning that I can't watch hls streams.

Thanks.

tomhon6 commented 9 years ago

Anyone know how to bypass the +19 error? I'm not good at python, how can I help?

nOLanSea commented 9 years ago

I know the way how to download 19+ stream http://d-c.kr/

Paste the link with 19+ stream, for example http://live.afreeca.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=khm11903&nStationNo=11165615&nBbsNo=12301161&nTitleNo=26201740&nRowNum=15&szSkin=&nPageNo=1 and get download link

nOLanSea commented 9 years ago

By the way, this patch given by trocknet works not perfectly Sometimes stream open with timer and no sound

Hope next livestreamer build will works good.

zelkovazone commented 9 years ago

@nOLanSea how to get that link stream ? yeah. sometimes i have to close and open it again ...

i hope the streamer for hls more smooth (rtmp is fine)

trocknet commented 9 years ago

patch for solve the timer and no sound problem: change the code in hls.py from

        else:
            content = res.content

        self.reader.buffer.write(content)

to

        else:
            if sequence.segment.uri.find("afreeca") and (sequence.segment.uri.find("_0.TS") or sequence.segment.uri.find("_1.TS") or sequence.segment.uri.find("_2.TS")) and len(res.content)<250000:
                return      
            content = res.content

        self.reader.buffer.write(content)
nOLanSea commented 9 years ago

@zelkovazone go to afreeca.com/id and click to "all broadcast" button @trocknet what is hls.py ? there is only hls.pyc in livestreamer-1.12.2-py2.7.egg\livestreamer\stream folder, which is can not be edited via notepad

mammothb commented 9 years ago

@nOLanSea hls.py is here https://github.com/chrippa/livestreamer/blob/develop/src/livestreamer/stream/hls.py

3viltube commented 9 years ago

can someone post like a step by step to fix the hls thing cause I kinda got lost doing it by myself. What prog do i have to use to implement the codes? thanks

AleXoundOS commented 9 years ago

trocknet, maybe it would be easier if you fork livestreamer's repository to your own. You make changes there, share them and make pull requests. So there is no confusion in applying patches.

trocknet commented 9 years ago

I would like to, but I don't known python and I can't guarantee the quality.

zelkovazone commented 9 years ago

@nOLanSea where is the "all broadcast button" can u show using pic ? i`m kinda lost at it..

nOLanSea commented 9 years ago

@zelkovazone http://www.teamliquid.net/forum/brood-war/490378-help-watch-afreeca-videos-without-lag#4

pmerc98 commented 9 years ago

Thanks for fixing this :)

nOLanSea commented 9 years ago

timer problem again can anyone solve?

trocknet commented 9 years ago

fixed...

change the code in hls.py from

        else:
            content = res.content

        self.reader.buffer.write(content)

to

        else:
            if sequence.segment.uri.find("afreeca")!= -1 and (sequence.segment.uri.find("_0.TS")!= -1 or sequence.segment.uri.find("_1.TS")!= -1 or sequence.segment.uri.find("_2.TS")!= -1):
                return      
            content = res.content

        self.reader.buffer.write(content)
prech commented 9 years ago

Thanks @trocknet, that fixed it! So glad for your help

nOLanSea commented 9 years ago

thank trocknet for timer fix again by the way, al these fixed (afreecatv.py and hls.py) would be included in next livestreamer build?

Hardbunny commented 9 years ago

Thanks a lot @trocknet , never stop being awesome

prech commented 8 years ago

It seems Afreeca has changed over recent weeks and the 15 second timer is back -- is there a way to bypass the timer for HLS streams? I used @trocknet's trick with:

 else:
            if sequence.segment.uri.find("afreeca")!= -1 and (sequence.segment.uri.find("_0.TS")!= -1 or sequence.segment.uri.find("_1.TS")!= -1 or sequence.segment.uri.find("_2.TS")!= -1):
                return      
            content = res.content

        self.reader.buffer.write(content)

in the hls.pyc file, but it no longer appears to be working...

Thanks