Kodi Community Forum

Full Version: HLS parameters being dropped
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently attempting to create an addon to stream television from CNTV via HLS. My test addon.py is shown below:
Code:
# -*- coding: utf-8 -*-

import sys
import xbmcgui
import xbmcplugin

import urllib2

addon_handle = int(sys.argv[1])

xbmcplugin.setContent(addon_handle, 'movies')

resp = urllib2.urlopen("http://vdn.live.cntv.cn/api2/liveHtml5.do?channel=pa://cctv_p2p_hdcctv13&client=html5")

data = resp.read().decode("utf-8")

url = data[data.index('"hls3":"') + 8:]
url = url[:url.index('"')]
url = url.replace("100-300", "300-500")

print(url)

li = xbmcgui.ListItem('CCTV-13 新闻', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

xbmcplugin.endOfDirectory(addon_handle)

The addon correctly outputs a HLS URL, such as http://ak.live.cntv.cn/i/[email protected], which works when played in VLC and ffplay:Image

When using the addon to stream the video in XBMC 13.2 and Kodi 14.0rc3, however, the server rejects the request and gives an error message:Image

The message indicates that the provided URL is incorrect (expired or missing authentication token, etc.), which suggests to me that the full URL is not being correctly passed to the player.

Does anyone know what can be done to fix this?
Update

I turned on verbose CURL and FFmpeg logging, and got this in the logs:
Code:
06:52:57 T:140007098058752  NOTICE: DVDPlayer: Opening: http://ak.live.cntv.cn/i/cctv13_1@101095/master.m3u8?b=300-500&AUTH=ip%3D1.2.3.4%7Est%3D1418971672%7Eexp%3D1419058072%7Eacl%3D%2F*%7Ehmac%3D8968f364bd16cf3add65408933843e03d6325f74ba12f25e51a72790e9552b4f
06:52:57 T:140007098058752 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
06:52:57 T:140007098058752   DEBUG: CRenderManager::UpdateDisplayLatency - Latency set to 0 msec
06:52:57 T:140007098058752   DEBUG: LinuxRendererGL: Cleaning up GL resources
06:52:57 T:140007098058752   DEBUG: CLinuxRendererGL::PreInit - precision of luminance 16 is 16
06:52:57 T:140006050264832  NOTICE: Thread DVDPlayer start, auto delete: false
06:52:57 T:140006050264832  NOTICE: Creating InputStream
06:52:57 T:140006050264832   DEBUG: CFileCache::Open - opening <i/cctv13_1@101095/master.m3u8> using cache
06:52:57 T:140006050264832   DEBUG: CurlFile::Open(0x7f55ac0a7fa0) http://ak.live.cntv.cn/i/cctv13_1@101095/master.m3u8?b=300-500&AUTH=ip%3D1.2.3.4%7Est%3D1418971672%7Eexp%3D1419058072%7Eacl%3D%2F*%7Ehmac%3D8968f364bd16cf3add65408933843e03d6325f74ba12f25e51a72790e9552b4f
06:52:57 T:140006050264832   DEBUG: Curl::Debug - TEXT: Hostname was NOT found in DNS cache
06:52:57 T:140006050264832   DEBUG: Curl::Debug - TEXT:   Trying 202.7.187.26...
06:52:57 T:140006050264832   DEBUG: Curl::Debug - TEXT: Connected to ak.live.cntv.cn (202.7.187.26) port 80 (#0)
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: GET /i/cctv13_1@101095/master.m3u8?b=300-500&AUTH=ip%3D1.2.3.4%7Est%3D1418971672%7Eexp%3D1419058072%7Eacl%3D%2F*%7Ehmac%3D8968f364bd16cf3add65408933843e03d6325f74ba12f25e51a72790e9552b4f HTTP/1.1
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: Range: bytes=0-
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: User-Agent: Kodi/14.0-RC3 (X11; Linux x86_64) Arch Linux/rolling App_Bitness/64 Version/14.0-RC3-Git:Unknown
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: Host: ak.live.cntv.cn
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: Accept: */*
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: Cookie: _alid_=ucdGQYkNdh9Iu0288Cbn/w==
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: Accept-Charset: UTF-8,*;q=0.8
06:52:57 T:140007098058752   DEBUG: ------ Window Init (DialogBusy.xml) ------
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: HTTP/1.1 200 OK
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Server: AkamaiGHost
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Content-Length: 639
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Content-Type: application/vnd.apple.mpegurl
06:52:57 T:140006050264832   DEBUG: Curl::Debug - TEXT: Replaced cookie _alid_="ucdGQYkNdh9Iu0288Cbn/w==" for domain ak.live.cntv.cn, path /i/cctv13_1@101095/, expire 0
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Set-Cookie: _alid_=ucdGQYkNdh9Iu0288Cbn/w==; path=/i/cctv13_1@101095/; domain=ak.live.cntv.cn
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Mime-Version: 1.0
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Access-Control-Allow-Origin: *
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Expires: Fri, 19 Dec 2014 06:52:57 GMT
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Cache-Control: max-age=0, no-cache, no-store
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Pragma: no-cache
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Date: Fri, 19 Dec 2014 06:52:57 GMT
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_IN: Connection: keep-alive
06:52:57 T:140005430757120  NOTICE: Thread FileCache start, auto delete: false
06:52:57 T:140005430757120   DEBUG: Curl::Debug - TEXT: Connection #0 to host ak.live.cntv.cn left intact
06:52:57 T:140005430757120    INFO: CFileCache::Process - Hit eof.
06:52:57 T:140005430757120   DEBUG: Thread FileCache 140005430757120 terminating
06:52:57 T:140006050264832    INFO: CDVDInputStreamFFmpeg: Auto-selecting http://ak.live.cntv.cn/i/cctv13_1@101095/index_500_av-p.m3u8?AUTH= based on configured bandwidth.
06:52:57 T:140006050264832  NOTICE: Creating Demuxer
06:52:57 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later.
06:52:57 T:140007098058752   DEBUG: Previous line repeats 1 times.
06:52:57 T:140007098058752   DEBUG: ------ Window Init (Pointer.xml) ------
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] request: GET /i/cctv13_1@101095/index_500_av-p.m3u8?AUTH= HTTP/1.1
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] User-Agent: Kodi/14.0-RC3 (X11; Linux x86_64) Arch Linux/rolling App_Bitness/64 Version/14.0-RC3-Git:Unknown
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Accept: */*
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Range: bytes=0-
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Connection: close
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Host: ak.live.cntv.cn
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Cookie: _alid_=ucdGQYkNdh9Iu0288Cbn/w==
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] Icy-MetaData: 1
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http]
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] header='HTTP/1.1 302 Moved Temporarily'
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] http_code=302
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] header='Server: AkamaiGHost'
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] header='Content-Length: 0'
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] header='Location: http://v.cctv.com/flash/live_back/copyright.mp4'

As the log shows, Kodi correctly downloads the M3U8 file:
Code:
06:52:57 T:140006050264832   DEBUG: Curl::Debug - HEADER_OUT: GET /i/cctv13_1@101095/master.m3u8?b=300-500&AUTH=ip%3D1.2.3.4%7Est%3D1418971672%7Eexp%3D1419058072%7Eacl%3D%2F*%7Ehmac%3D8968f364bd16cf3add65408933843e03d6325f74ba12f25e51a72790e9552b4f HTTP/1.1

The contents of this file are:
Code:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=458000,RESOLUTION=720x576,CODECS="avc1.77.30, mp4a.40.2"
http://ak.live.cntv.cn/i/cctv13_1@101095/index_500_av-p.m3u8?AUTH=ip%3D1.2.3.4%7Est%3D1418972109%7Eexp%3D1419058509%7Eacl%3D%2F*%7Ehmac%3D21640c72456e49c34dc433fcf47bf2808fa1f86b8ee582c49764f969e7514410&sd=10&b=300-500&rebase=on
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=46000,CODECS="mp4a.40.2"
http://ak.live.cntv.cn/i/cctv13_1@101095/index_500_a-p.m3u8?AUTH=ip%3D1.2.3.4%7Est%3D1418972109%7Eexp%3D1419058509%7Eacl%3D%2F*%7Ehmac%3D21640c72456e49c34dc433fcf47bf2808fa1f86b8ee582c49764f969e7514410&sd=10&b=300-500&rebase=on

But after dowloading this M3U8 file, it randomly decides to drop the contents of the AUTH parameter:
Code:
06:52:57 T:140006050264832    INFO: CDVDInputStreamFFmpeg: Auto-selecting http://ak.live.cntv.cn/i/cctv13_1@101095/index_500_av-p.m3u8?AUTH= based on configured bandwidth.
06:52:58 T:140006050264832   DEBUG: ffmpeg[7F55B2E47700]: [http] request: GET /i/cctv13_1@101095/index_500_av-p.m3u8?AUTH= HTTP/1.1

Code:
url = url.replace("master.m3u8?b=100-300&", "index_500_av-p.m3u8?")
Changing my code to manually bypass the master.m3u8 file, as above, works, but I would really like a better solution to this problem.
So I take it there is no way to play CNTV without an access token now?