Hi folks!

I recently started streaming on Peertube (along with Twitch and YouTube) and I have been looking for ways to display a view count, same as I do for the other two platforms.

I found a trick, using a browser source (I use OBS) and cropping to show only the view count, but it is less than ideal (it tends to move between streams). Any ideas?

  • NorthWestWind@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 month ago

    EDIT: Upon further tinkering, I found out the API doesn’t actually require any authorization to use. I made a simple HTML here. You can try it!

    Taking a look at the network tab in devtools, I found an authorized GET request of https://peertube.wtf/api/v1/videos/%7Bvideo_id%7D. The response JSON has a field called viewers and views, which (I guess would) represent live views and the actual video’s views respectively. I haven’t dived too deep into getting access tokens but the PeerTube docs should help.

    Alternatively, you can fetch the public video page directly (i.e. https://peertube.wtf/w/%7Bvideo_id%7D) and extract the view count from the HTML, maybe something like document.querySelector("my-video-views-counter").innerText in Javascript.

    I doubt there’s any website that directly provides a browser source for PeerTube, so you probably have to create your own source making use of this knowledge. The source can be as simple as a single HTML file.

    And thanks to @Meldrik@lemmy.wtf for pinging me :>

    • Alias@lemmy.wtfOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 month ago

      Hi and thanks for your comment and links; I need to check that closer, but at this moment, I could not manage to get the HTML to work properly. I’ll do some more checks.