描述
分析学习喜马拉雅app阅读时长统计机制,并应用到自己app中去
分析
-
使用抓包工具charles观测app统计发送时机,发现切换音频源,或本地缓存有阅读数据进入首页app时发送(nyx/v2/track/statistic/android)
image - 播放过程中,查看本地播放时长记录,发现每隔一段时间向本地SharePreferences保存阅读时长数据,并且发现mListenedDuration大概每隔5秒变化一次,切换音频发送成功后,本地缓存相应条目被删除
adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android\:player.xml
- 播放过程中,杀掉进程。后重启会发送本地缓存的记录,并清除本地条目
- 音频播放及切换音频源本地缓存数据变化
读取本地播放时长记录
- 使用代码代替adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android:player.xml mListenedDuration每个5秒观测动作
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import datetime
import json
import time
def fenxi():
cmd = "adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android\:player.xml"
timeStr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# time = datetime.datetime.strptime(string,'%Y-%m-%d %H:%M:%S')
print("*" * 50 + "start:" + timeStr)
f = os.popen(cmd)
if f:
content = f.read()
# print(content)
content = content.replace(""", '"')
# print(content)
startIndex = content.find("[{")
endIndex = content.rfind("}]")
if startIndex != -1 and endIndex != -1:
# print(startIndex, endIndex)
content = content[startIndex:endIndex + 2]
# print(content)
jsonContent = json.loads(content)
# print(jsonContent)
for ct in jsonContent:
# print(ct)
mListenedDuration = ct.get('xmPlayRecord').get('mListenedDuration')
mSendDataTime = ct.get('xmPlayRecord').get('mSendDataTime')
mDuration = ct.get('xmPlayRecord').get('mDuration')
mStartTime = ct.get('xmPlayRecord').get('mStartTime')
mStartedPosition = ct.get('xmPlayRecord').get('mStartedPosition')
playUrl = ct.get('xmPlayRecord').get('playUrl')
mPlaySource = ct.get('xmPlayRecord').get('mPlaySource')
# timeArray = time.strptime(mStartTime, "%Y-%m-%d %H:%M:%S")
print("mListenedDuration=%s"%mListenedDuration)
print("mDuration=%s"%mDuration)
print("mSendDataTime=%s"%mSendDataTime)
print("mStartTime=%s"%mStartTime)
print("mStartedPosition=%s"%mStartedPosition)
print("playUrl=%s"%playUrl)
# print("mPlaySource=%s"%mPlaySource)
else:
print("无数据")
timeStr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print("*" * 50 + "end:" + timeStr)
print("\n" * 2)
# nyx/v2/track/statistic/android
def main():
while True:
fenxi()
time.sleep(3)
if __name__ == "__main__":
main()
观测终端输出结果
**************************************************start:2018-09-29 15:27:10
mListenedDuration=9
mDuration=9
mSendDataTime=0
mStartTime=1538206021312
mStartedPosition=0
playUrl=http://audio.xmcdn.com/group36/M02/0E/9D/wKgJUlo3b7aiMSvIANicyKRiMZ4986.m4a
**************************************************end:2018-09-29 15:27:10
**************************************************start:2018-09-29 15:27:13
无数据
**************************************************end:2018-09-29 15:27:14
**************************************************start:2018-09-29 15:27:17
mListenedDuration=0
mDuration=0
mSendDataTime=0
mStartTime=1538206035483
mStartedPosition=0
playUrl=http://audio.xmcdn.com/group31/M0B/6C/F8/wKgJX1mG0w-Q7DXpAM_ILYxT6gU048.m4a
**************************************************end:2018-09-29 15:27:17
**************************************************start:2018-09-29 15:27:20
mListenedDuration=5
mDuration=5
mSendDataTime=0
mStartTime=1538206035483
mStartedPosition=0
playUrl=http://audio.xmcdn.com/group31/M0B/6C/F8/wKgJX1mG0w-Q7DXpAM_ILYxT6gU048.m4a
**************************************************end:2018-09-29 15:27:20
网友评论