Repository: streamlink/streamlink

Issue:
July 17 Douyu.com error
0.7.0
streamlink https://www.douyu.com/17732 source -o "PATH & FILENAME"
[cli][info] Found matching plugin douyutv for URL https://www.douyu.com/17732
error: Unable to open URL: https://www.douyu.com/lapi/live/getPlay/17732 (500 Server Error: Internal Server Error for url: https://www.douyu.com/lapi/live/getPlay/17732)
@fozzysec @steven7851


Discussion:
There is no solution for the LAPI 500 error AFAIK. Douyu changed their flash player and their api again, waiting for a solution to it.
@fozzysec 
I have several software on my computer,
At present, only this one can be normal video

I tried to catch the bag
You see
Do you look at these for your help?
-------------------------

GET /api/v1/room/156277?aid=dytool2&time=1500284308&auth=8b972619bb9ae83d63dd175cf1e44c8e HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: text/html, application/xhtml+xml, /
Accept-Language: zh-cn
User-Agent: Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 6.1)
Host: api.douyutv.com

GET /live/156277raU8XQkRHx.flv?wsAuth=e04b9d008c40e5a68fdd02e0427a5d13&token=app-dytool2-0-156277-dafa16da92004488622f7dc918e03ed2&logo=0&expire=0 HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: text/html, application/xhtml+xml, /
Accept-Language: zh-cn
User-Agent: Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 6.1)
Host: hdla.douyucdn.cn

GET /hdla.douyucdn.cn/live/156277raU8XQkRHx.flv?wsAuth=e04b9d008c40e5a68fdd02e0427a5d13&token=app-dytool2-0-156277-dafa16da92004488622f7dc918e03ed2&logo=0&expire=0&wshc_tag=0&wsts_tag=596c85ce&wsid_tag=3a1240ec&wsiphost=ipdbm HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: text/html, application/xhtml+xml, /
Accept-Language: zh-cn
User-Agent: Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 6.1)
Host: 221.194.180.100
@lki2019 I tried the API but it seems it doesn't work for me.
```
curl 'http://api.douyutv.com/api/v1/room/156277?aid=dytool2&time=1500284308&auth=8b972619bb9ae83d63dd175cf1e44c8e' -H 'User-Agent: Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 6.1)' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html, application/xhtml+xml, /' 
{"error":1003,"msg":"","data":[]}
```
I modified the time it doesn't work too. Would you please provide me with the app/software name so I can have a try on it.
@fozzysec It is a need for a machine a code of software, you will crack it?
If i can pass you, you get it verified

Leave a mailbox, I sent you
@lki2019 No, I don't know much about cracking, thanks for the help.
https://github.com/spacemeowx2/DouyuHTML5Player/issues/28
@bupmc I only have Mac computers so I can't get dump decoded SWF ASCRIPT from memory while running the official flash player. I will keep on watch that issue and try to fix the plugin ASAP. Thanks.
感谢
According to https://github.com/spacemeowx2/DouyuHTML5Player/issues/28 , I wrote an simple script to redirect the HLS playlist, it can work temporarily but have lag. I don't know if I should add a simple http server to this project and generate HLS playlist dynamically to enable it can work with streamlink.
ps. If someone want to stream douyu.com, just use http://open.douyucdn.cn/api/RoomApi/room/ROOMID to get the real roomid then use mpv to play playlist.m3u8?room=REALROOMID
The code is here https://gist.github.com/fozzysec/b98e681c352b6e5b0c7503d99c942670
And can also be directly accessed via http://fozzy.co/douyu/playlist.m3u8
https://www.douyu.com/274874  Being broadcast live

How do you enter the specific order?


mpv http://fozzy.co/douyu/playlist.m3u8 274874


What about that?
@lki2019 
For those numerical room, just try
```
mpv "http://fozzy.co/douyu/playlist.m3u8?room=274874"
```
For those non-numerical room, for example https://www.douyu.com/nado, first visit http://open.douyucdn.cn/api/RoomApi/room/nado to get the room id, then
```
mpv "http://fozzy.co/douyu/playlist.m3u8?room=2020877"
```
For those special room whose format is `/t/roomid`, in html source find `onlineid` and get the room id.
OK，谢谢！
![qq 20170720141000](https://user-images.githubusercontent.com/30022431/28403004-53245956-6d55-11e7-9e20-860e0f81f19d.png)

Can play, but will be from time to time about the card,


I watched for 2 minutes, the player did not automatically, and broke
@lki2019 If there are broken frames, just try add `--autosync=30` to mpv, it will smooth the audio/video matching.
It is very strange that douyu's WAF may block frequent request. Maybe a local http server is needed.
```
[root@freebsd ~/www/douyu]# ./playlist2.m3u8 1047629
Content-Type: application/x-mpegURL; charset=ISO-8859-1

[root@freebsd ~/www/douyu]# curl "https://m.douyu.com/html5/live?roomId=1047629"
{"error":0,"data":{"hls_url":"http:\/\/hls3.douyucdn.cn\/live\/1047629rbtEPD0T0\/playlist.m3u8?wsSecret=09368623d3b82dcc83e01cf6d101dc05&wsTime=1500529944&did=&ver="}}[root@freebsd ~/www/douyu]# 
[root@freebsd ~/www/douyu]# curl "http://hls3.douyucdn.cn/live/1047629rbtEPD0T0/playlist.m3u8?wsSecret=09368623d3b82dcc83e01cf6d101dc05&wsTime=1500529944&did=&ver="
[root@freebsd ~/www/douyu]# 
```
![zuiixinde](https://user-images.githubusercontent.com/30022431/28404234-13568dd4-6d5b-11e7-87d7-7048eab05192.png)

mpv --autosync=30 "http://fozzy.co/douyu/playlist.m3u8?room=274874"

I watched more than 7 minutes without disconnected!


Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).


Card a bit


[ffmpeg/demuxer] hls,applehttp: Failed to reload playlist 0

Card a bit



@lki2019 Yes, a local http server may reduce lag, my server is located in Tokyo so it may be a bit slow when mpv fetching the playlist.
Thank you

Read more than 15 minutes, did not break!

feel good

Is it possible to record?
@lki2019 
```
ffmpeg -i "http://fozzy.co/douyu/playlist.m3u8?room=xxx" -acodec copy -vcodec copy -bsf:a aac_adtstoasc douyu.flv
```
Also has async problems. If you really want to download, just download all the sequenced TS files and combine all those files together.
mpv can also record streams by
```
mpv --autosync=30 "http://fozzy.co/douyu/playlist.m3u8?room=xxx" -o file1.flv
```
frame=13935 fps= 40 q=-1.0 size=   76390kB time=00:05:50.92 bitrate=1783.3kbits/
[http @ 047beae0] No trailing CRLF found in HTTP header.
frame=14056 fps= 41 q=-1.0 size=   77085kB time=00:05:54.03 bitrate=1783.7kbits/
[hls,applehttp @ 00397a00] Failed to reload playlist 0
[http @ 047beae0] No trailing CRLF found in HTTP header.
http://fozzy.co/douyu/playlist.m3u8?room=274874: Unknown error
frame=14175 fps= 40 q=-1.0 size=   77723kB time=00:05:57.00 bitrate=1783.5kbits/
frame=14175 fps= 40 q=-1.0 Lsize=   77732kB time=00:05:57.00 bitrate=1783.7kbits
/s
video:71487kB audio:5712kB subtitle:0kB other streams:0kB global headers:0kB mux
ing overhead: 0.689756%

G:\tools\tools>



Recorded more than five minutes to disconnect

@lki2019 This is network error, a local http server will be better. The remote server is not stable. Or someone can place this redirect script on cloud within Mainland China such as Aliyun or something else.
https://gist.github.com/fozzysec/af4b6c2a4d95e3bb84cbb8462f2ec709
I edited the code to make a local simple http server, this is much more smooth than the previous script.
just use
```
mpv --autosync=30 "http://localhost:8181/playlist.m3u8?room=xxx"
```
You can also change the port in the code.
I am the network, you can use it?

![qq 20170720163533](https://user-images.githubusercontent.com/30022431/28408312-a09f564a-6d69-11e7-9b01-15bb87588887.png)


I was WIN7 32-bit system

How can i do it?

I've copied your code


What should I do next?


![1a00](https://user-images.githubusercontent.com/30022431/28408503-4d0668e2-6d6a-11e7-92b5-aba05a37e535.jpg)



@lki2019 First you need to install the perl environment, for windows system, ActivePerl is easy to use. After installing perl, you need to install those CPAN packages:
```
JSON
LWP::UserAgent
CGI
HTTP::Server::Simple
```
After get everything installed, you can just start the server by `perl douyu_server.pl`, then access http://localhost:8181/ , you will see a simple page to input the douyu room id, input the room id and it will give you an link, copy that link and just use mpv to play it ;D
The douyu support cannot be implemented by plugin so you can temporarily use this for streaming.

**Chinese translation**
首先需要安装perl执行环境，windows系统可以安装ActivePerl，装好了之后需要安装以下Perl包：
```
JSON
LWP::UserAgent
CGI
HTTP::Server::Simple
```
都装好了之后直接在命令行运行`perl douyu_server.pl`，然后访问http://localhost:8181/，会看到一个输入房间号的输入框，输入后回车会返回mpv可以直接播放的地址，直接用mpv播放即可。
目前斗鱼的支持做不进插件里面
OK，谢谢！
D:\下载\Http_File_Server_2.3i_297\Http File Server 2.3i Build 297>perl douyu_ser
ver.pl
Unrecognized character \xA3; marked by <-- HERE after <-- HERE near column 1 at
douyu_server.pl line 1.
@lki2019 Don't paste use Notepad, directly download the code from https://raw.githubusercontent.com/fozzysec/DouyuHLS/master/douyu_server.pl

P.S.
Editing with Notepad on Windows is always a bad idea for nearly every script language, when you need to edit scripts, you can choose [Atom](https://github.com/atom/atom), GVim, notepad++ or some else you like, but not Notepad that come with Microsoft Windows, it will add BOM header to non-ascii file.
D:\下载\Http_File_Server_2.3i_297\Http File Server 2.3i Build 297>perl douyu_ser
ver.pl
Can't locate HTTP/Server/Simple/CGI.pm in @INC (you may need to install the HTTP
::Server::Simple::CGI module) (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at
 douyu_server.pl line 13.
BEGIN failed--compilation aborted at douyu_server.pl line 13.

D:\下载\Http_File_Server_2.3i_297\Http File Server 2.3i Build 297>


![qq 20170720200605](https://user-images.githubusercontent.com/30022431/28416549-0b9d4f02-6d87-11e7-9b95-5ae1a6e995f6.png)

@lki2019 According to https://code.activestate.com/ppm/HTTP-Server-Simple/ , just open your cmd and run
```
ppm install HTTP-Server-Simple
ppm install JSON
ppm install LWP-UserAgent
ppm install CGI
```
It should work according to the activeperl's website.

![11](https://user-images.githubusercontent.com/30022431/28417448-bd72242a-6d8a-11e7-965b-babbb7108e52.png)

very good   谢谢！！！！！


![qq 20170720203330](https://user-images.githubusercontent.com/30022431/28417498-edf7b646-6d8a-11e7-8f1f-86c3e3bf247b.png)

Can I add a feature?

Click on the link automatically call, mpv player out!

Harder?
@lki2019 Not hard, but need to install url scheme to register in Windows, also enabling url scheme need to allow chrome to install developer extensions, it is annoying(Everytime you start Chrome, there is a alert that saying you are enabling developer mode). So just copy the link and paste it to mpv is the simplest way to play it.
If you do need extension, you can reference https://github.com/fozzysec/streamlink-chrome-extension-for-windows this, only few modification are needed to make it work with mpv.
Okay thank you!
are you just replacing the **_550** from the **.ts** file with your server?

if so, you could do this with streamlink

based on https://github.com/beardypig/streamlink/blob/yoursportsinhd/src/streamlink/plugins/yoursportsinhd.py

---

Here is a test plugin where the **_550** gets removed from the **.ts** file
```
streamlink http://exampledouyu.com/ID best
```
https://gist.github.com/back-to/9cec89ecc9c1fb7556523a8658391375

I don't know if this works, **douyu.com** is to laggy for my location.
@back-to It works fine, very thanks.
The only problem is that it will reconnect every 5 mins because of ```hls_url``` key expired.
@back-to The problem now is that the original m3u8 playlist has an one-time token. When playing by player, the further request on the playlist will result in 403 error. We need a background script to provide the playlist that works with player.
ok so you need to reload the m3u8 aswell,
here is a new version of the test plugin it

- reloads every **60 sec** the **playlist.m3u8** and replace it
- replace **_550** from **.ts** link

the **_550** link did not timeout for me,
the link without **_550** did not timeout, but it's very laggy for me.

---

```
streamlink http://exampledouyu.com/ID best
```
https://gist.github.com/back-to/9cec89ecc9c1fb7556523a8658391375
Found a new API from https://github.com/spacemeowx2/DouyuHTML5Player/issues/28, I will open a PR later.
@back-to Thanks for your code this can be an alternative way when Douyu block the new API.
A fix(#1109) was done by using new API, you can just download the file and replace your douyutv.py, now only HD is supported.

Resolving patch:
diff --git a/src/streamlink/plugins/douyutv.py b/src/streamlink/plugins/douyutv.py
--- a/src/streamlink/plugins/douyutv.py
+++ b/src/streamlink/plugins/douyutv.py
@@ -10,7 +10,7 @@
 
 API_URL = "https://capi.douyucdn.cn/api/v1/{0}&auth={1}"
 VAPI_URL = "https://vmobile.douyu.com/video/getInfo?vid={0}"
-API_SECRET = "Y237pxTx2In5ayGz"
+API_SECRET = "zNzMV1y4EMxOHS6I5WKm"
 SHOW_STATUS_ONLINE = 1
 SHOW_STATUS_OFFLINE = 2
 STREAM_WEIGHTS = {
@@ -129,10 +129,10 @@ def _get_streams(self):
             if channel is None:
                 channel = http.get(self.url, schema=_room_id_alt_schema)
 
-        http.headers.update({'User-Agent': useragents.ANDROID})
+        http.headers.update({'User-Agent': useragents.WINDOWS_PHONE_8})
         cdns = ["ws", "tct", "ws2", "dl"]
         ts = int(time.time())
-        suffix = "room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}".format(channel, cdns[0], ts)
+        suffix = "room/{0}?aid=wp&cdn={1}&client_sys=wp&time={2}".format(channel, cdns[0], ts)
         sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()
 
         res = http.get(API_URL.format(suffix, sign))


Test patch: