Quote:
Originally Posted by asdf030989
Is the cam4 plugin dont work?
I got the error of unable to open URL of the m3u8 playlist.
|
The streamlink plugin still works for me this code:
Code:
import re
from streamlink.plugin import Plugin
from streamlink.plugin.api import http, useragents, validate
from streamlink.stream import HLSStream, RTMPStream
from streamlink.utils import parse_json
class Cam4(Plugin):
_url_re = re.compile(r'https?://([a-z]+\.)?cam4.com/.+')
_video_data_re = re.compile(r"flashData: (?P<flash_data>{.*}), hlsUrl: '(?P<hls_url>.+?)'")
_flash_data_schema = validate.Schema(
validate.all(
validate.transform(parse_json),
validate.Schema({
'playerUrl': validate.url(),
'flashVars': validate.Schema({
'videoPlayUrl': validate.text,
'videoAppUrl': validate.url(scheme='rtmp')
})
})
)
)
@classmethod
def can_handle_url(cls, url):
return Cam4._url_re.match(url)
def _get_streams(self):
res = http.get(self.url, headers={'User-Agent': useragents.ANDROID})
match = self._video_data_re.search(res.text)
if match is None:
return
hls_streams = HLSStream.parse_variant_playlist(
self.session,
match.group('hls_url'),
headers={'Referer': self.url}
)
for s in hls_streams.items():
yield s
rtmp_video = self._flash_data_schema.validate(match.group('flash_data'))
rtmp_stream = RTMPStream(self.session, {
'rtmp': rtmp_video['flashVars']['videoAppUrl'],
'playpath': rtmp_video['flashVars']['videoPlayUrl'],
'swfUrl': rtmp_video['playerUrl']
})
yield 'live', rtmp_stream
__plugin__ = Cam4
Script stopped working without www, en, ru, pl etc in the page address. The revised looks like this:
Code:
@echo off
setlocal enableDelayedExpansion
set USERNAME=AnonymousUser
set PASSWORD=anonymous
set SECONDS=15
set /p model=Enter username:
set model=%model:https://www.cam4.com/=%
set model=%model:/=%
set OUT_DIR=Cam4
if not exist %OUT_DIR% (mkdir %OUT_DIR%)
for /L %%i in (1,1,99) do (
set N=!time:~9,12!
set /a N=10000!N! %% 10000
set rand=!random!
set /a rand=!rand!* 31/32768+1
set /a rand=!N!+!rand!
set /a rand=!rand!*31/131+1
)
set server=edge%rand%
:doCapture
for /r %%F in (*) do if %%~zF==0 @del "%%F"
set ts=%date:/=-%_%time::=-%
set ts=%ts: =%
set output=%OUT_DIR%\%model%_%ts%.flv
set PASSWORD=%PASSWORD:\u003D==%
color 2F && title %model% @ %time% - %server%
cls && echo Capturing: %model% @ %time% - %server% && echo.
streamlink "https://www.cam4.com/%model%/" best --http-header "swfUrl=https://static.cam4.com/client/Cam4Chatless_1.184_guest.swf" --http-header "flashVer=WIN 25.0.0.148" -o "%OUT_DIR%\%model%_%ts%.flv
for %%r in (%output%) do (
if %%~zr lss 1 del %output%
color 4F && title %model% - OFFLINE
)
set /a rand=%random%*31/32768+1
set server=edge%rand%
timeout %SECONDS%
goto doCapture