Search code examples
web-scrapingvideo-streamingdata-miningtwitch

Is there a way to acquire twitch video data?


I am making a website to help video games streamers (on twitch), but to do so I need to analyze there streams and videos. I can always ask the users to download their videos from twitch and upload them on my website but I need a more automatic way... So my question is: is there a way to acquire the video data and the live stream data? Maybe by asking the user to link his twitch account? Or by using a scraper on the twitch website? Note: I need the stream and videos data itself (i am going to do some image processing on them)


Solution

  • You can do this multiple ways.

    Way 1. Use the twitch api V5

    import requests
    import json
    
    r = requests.get("https://api.twitch.tv/kraken/channels/<channel ID>/videos
    
    ", headers={"Client-ID":"CLIENTID"})
    j = json.loads(r.text)
    
    j['url']
    

    to gather all videos and download then execute a command via python or whatever language you choose. To execute either of two options. Youtube-DL which the command would be as follows

    youtube-dl twitchVideoURL
    

    or using twitch-dl

    which you could execute a command like

    twitch-dl download twitchVideoURL
    

    Way 2 use purely twitch-dl

    This way you would end up running twitch-dl videos twitchChannelName which would give you an output as follows (this just grabbed off his github readme)

    Found 33 videos
    
    221837124
    SUPER MARIO ODYSSSEY - Stream #2 / 600,000,000
    Bananasaurus_Rex playing Super Mario Odyssey
    Published 2018-01-24 @ 12:05:25  Length: 3h 40min
    
    221418913
    Dead Space and then SUPER MARIO ODYSSEY PogChamp
    Bananasaurus_Rex playing Dead Space
    Published 2018-01-23 @ 02:40:58  Length: 6h 2min
    

    From there you could grab the first line of each new video. Finally putting that id into twitch-dl download VideoID

    Hopefully this gives you some ideas as to how to do this. As you never specified a language I tried to for the most part be as generic as possible.