duanchai0028 2015-10-21 04:38
浏览 151

PHP提取youtube在线聊天

When there's live broadcast on youtube there's always a chat to the right of video player. I am trying to download messages from chat to my PHP page in order to filter trough them as they scroll really fast and i cannot catch up with them.

I noticed that when you open youtube page with live chat it runs GET to this URL every 10 seconds

https://www.youtube.com/live_comments?action_get_comments=1&video_id=<video_id>&lt=<timestamp of last recorded message>&format=proto&pd=10000&rc=26&scr=true&comment_version=1

If i do

$xml= file_get_contents('https://www.youtube.com/live_comments?action_get_comments=1&video_id=<video_id>&lt=<timestamp of last recorded message>&format=proto&pd=10000&rc=26&scr=true&comment_version=1');
echo "<textarea>{$xml}</textarea>";

I get following

<?xml version="1.0" encoding="utf-8"?>
<root>
    <latest_time>
        <![CDATA[1445398692]]>
    </latest_time>
    <return_code>
        <![CDATA[0]]>
    </return_code>
    <likes_data>
        <![CDATA[{"percent_dislikes":7,"num_likes":"1,383","num_dislikes":"91","percent_likes":93}]]>
    </likes_data>
    <comments>
        <![CDATA[EOcKGFsgkE4=]]>
    </comments>
</root>

I assume this would get me new messages that appear however i am currently testing on chat that has no people in it and i cannot confirm.

There's also POST request every 10 seconds however i am not trying to post just download.

My question is how do i download with PHP existing messages that show in the chat when you open page initially?

  • 写回答

1条回答 默认 最新

  • douchi1945 2019-05-04 02:32
    关注

    This is not an adequate answer (no PHP, no code...), but if you are interested in a dirty and simple solution (grabbing a Youtube Live video Chat as JSON), you can use your browser to do so. In Firefox:

    1. Load video url in Firefox Browser, on top of video chat window.
    2. Select "Live Chat Replay" to get all messages of chat.
    3. Pause video.
    4. On FF Menu go to "Web Developer Tools" and then "Network".
    5. Mark checkbox of "Persistent Register" (optional)
    6. Select "XHR" only and filter results by "live_chat_replay".
    7. Play video and let it row...
    8. At the end, pause video again and at Top-Right of "Network" console find and clik on "HAR" selector.
    9. Select "Save all as HAR"
    10. Select file destination and save.
    11. Open "HAR" file in text/code editor (It's a JSON of JSONS)
    12. Parse it using your favorite languaje.
    13. Cheers!
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测