Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add peertube support #782

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Add peertube support #782

wants to merge 16 commits into from

Conversation

BentiGorlich
Copy link
Member

@BentiGorlich BentiGorlich commented May 15, 2024

To be able to handle the activities peertube sends these things needed to be added:

  • extract the target magazine / group from the attributedTo property. It is an array with both the user and the channel (group) in it. This is necessary, because the channel is not mentioned in the To or Cc field
  • handle array as url property
  • add Video as a supported entry type

Supported interactions with peertube:

  • new video is posted
    that is an incoming Announce activity, no problems there with this PR

  • new comment under a video is posted
    a new comment under a video that we do not have on our server yet works with this PR

  • likes and dislikes
    seem to be sent to other instances by sending an Update activity for the original post. In the json of the post there are collections for likes, dislikes and shares. So maybe we could support that in the future, but it feels very weird to me to fetch instead of getting them sent to me. Additionally the collection does not just contain the actor ids, but the id of the Like/Dislike activity. Since we do not save that we would have to fetch a lot on each update we get.

Example activites pulled from TilVids

Create Activity (https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6)

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/v1",
    {
      "RsaSignature2017": "https://w3id.org/security#RsaSignature2017"
    },
    {
      "pt": "https://joinpeertube.org/ns#",
      "sc": "http://schema.org/",
      "Hashtag": "as:Hashtag",
      "uuid": "sc:identifier",
      "category": "sc:category",
      "licence": "sc:license",
      "subtitleLanguage": "sc:subtitleLanguage",
      "sensitive": "as:sensitive",
      "language": "sc:inLanguage",
      "identifier": "sc:identifier",
      "icons": "as:icon",
      "isLiveBroadcast": "sc:isLiveBroadcast",
      "liveSaveReplay": {
        "@type": "sc:Boolean",
        "@id": "pt:liveSaveReplay"
      },
      "permanentLive": {
        "@type": "sc:Boolean",
        "@id": "pt:permanentLive"
      },
      "latencyMode": {
        "@type": "sc:Number",
        "@id": "pt:latencyMode"
      },
      "Infohash": "pt:Infohash",
      "originallyPublishedAt": "sc:datePublished",
      "views": {
        "@type": "sc:Number",
        "@id": "pt:views"
      },
      "state": {
        "@type": "sc:Number",
        "@id": "pt:state"
      },
      "size": {
        "@type": "sc:Number",
        "@id": "pt:size"
      },
      "fps": {
        "@type": "sc:Number",
        "@id": "pt:fps"
      },
      "commentsEnabled": {
        "@type": "sc:Boolean",
        "@id": "pt:commentsEnabled"
      },
      "downloadEnabled": {
        "@type": "sc:Boolean",
        "@id": "pt:downloadEnabled"
      },
      "waitTranscoding": {
        "@type": "sc:Boolean",
        "@id": "pt:waitTranscoding"
      },
      "support": {
        "@type": "sc:Text",
        "@id": "pt:support"
      },
      "likes": {
        "@id": "as:likes",
        "@type": "@id"
      },
      "dislikes": {
        "@id": "as:dislikes",
        "@type": "@id"
      },
      "shares": {
        "@id": "as:shares",
        "@type": "@id"
      },
      "comments": {
        "@id": "as:comments",
        "@type": "@id"
      }
    }
  ],
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "cc": [
    "https://tilvids.com/accounts/thelinuxexperiment/followers"
  ],
  "type": "Video",
  "id": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6",
  "name": "Fedora wants AI, Nvidia + Wayland fixed, Proton buys Standard Notes: Linux & Open Source News",
  "duration": "PT1048S",
  "uuid": "1c97fd94-5fb3-45e5-ad65-b52b722a64f6",
  "tag": [
    {
      "type": "Hashtag",
      "name": "distro"
    },
    {
      "type": "Hashtag",
      "name": "linux"
    },
    {
      "type": "Hashtag",
      "name": "linux for beginners 2023"
    },
    {
      "type": "Hashtag",
      "name": "linux tips"
    },
    {
      "type": "Hashtag",
      "name": "opensource"
    }
  ],
  "category": {
    "identifier": "15",
    "name": "Science & Technology"
  },
  "language": {
    "identifier": "en",
    "name": "English"
  },
  "views": 371,
  "sensitive": false,
  "waitTranscoding": true,
  "state": 1,
  "commentsEnabled": true,
  "downloadEnabled": true,
  "published": "2024-04-13T16:09:11.988Z",
  "originallyPublishedAt": "2024-04-12T22:00:00.000Z",
  "updated": "2024-05-11T01:18:00.879Z",
  "mediaType": "text/markdown",
  "content": "Head to https://squarespace.com/thelinuxexperiment to save 10% off your first purchase of a website or domain using code thelinuxexperiment\n\nGrab a brand new laptop or desktop running Linux: https://www.tuxedocomputers.com/en#\n\n\n👏 SUPPORT THE CHANNEL:\nGet access to:\n- a Daily Linux News show\n- a weekly patroncast for more personal thoughts\n- polls on the next topics I cover,\n- your name in the credits\n\nYouTube: https://www.youtube.com/@thelinuxexp/join\nPatreon: https://www.patreon.com/thelinuxexperiment\n\nOr, you can donate whatever you want:\nhttps://paypal.me/thelinuxexp\nLiberapay: https://liberapay.com/TheLinuxExperiment/\n\n👕 GET TLE MERCH\nSupport the channel AND get cool new gear: https://the-linux-experiment.creator-spring.com/\n\n🎙️ LINUX AND OPEN SOURCE NEWS PODCAST:\nListen to the latest Linux and open source news, with more in depth coverage, and ad-free!  https://podcast.thelinuxexp.com\n\n🏆 FOLLOW ME ELSEWHERE:\nWebsite: https://thelinuxexp.com\nMastodon: https://mastodon.social/web/@thelinuxEXP\nPixelfed: https://pixelfed.social/TLENick\nPeerTube: https://tilvids.com/c/thelinuxexperiment_channel/videos\nDiscord: https://discord.gg/mdnHftjkja\n\n#linux #opensource #technews #linuxdesktop #linuxdistro \n\nTimecodes:\n00:00 Intro\n00:39 Sponsor: Squarespace\n01:40 Fedora wants to go all in on AI\n04:25 Ubuntu 24.04 LTS beta\n06:04 Explicit sync will fix Wayland on nvidia\n08:20 Proton buys Standard Notes\n09:43 DE updates to GNOME, KDE, elementary OS\n12:05 Gaming: League of Legends is gone\n15:09 Sponsor: Tuxedo Computers\n16:22 Support the channel\n \nFedora wants to go all in on AI\n\nhttps://communityblog.fedoraproject.org/strategy-2028-april-2024-update/\n \nUbuntu 24.04 LTS beta\n\nhttps://www.omgubuntu.co.uk/2024/04/ubuntu-24-04-beta-released\n\nExplicit sync will fix Wayland on nvidia\n\nhttps://zamundaaa.github.io/wayland/2024/04/05/explicit-sync.html\n\nhttps://www.phoronix.com/news/Explicit-GPU-Sync-XWayland-Go\n\nProton buys Standard Notes\n\nhttps://www.zdnet.com/home-and-office/work-life/proton-acquires-standard-notes-to-add-another-tool-to-its-growing-portfolio/\n\nDE updates to GNOME, KDE\n\nhttps://pointieststick.com/2024/04/05/this-week-in-kde-real-modifier-only-shortcuts-and-cropping-in-spectacle/\n\nhttps://thisweek.gnome.org/posts/2024/04/twig-142/\n\nGaming: League of Legends is gone\n\nhttps://www.gamingonlinux.com/2024/04/riot-games-talk-vanguard-anti-cheat-for-league-of-legends-and-why-its-a-no-for-linux/\n\nhttps://www.theverge.com/2024/4/11/24127545/discord-suyu-sudachi-server-shutdown-account-ban",
  "support": null,
  "subtitleLanguage": [],
  "icon": [
    {
      "type": "Image",
      "url": "https://tilvids.com/static/thumbnails/6182657f-d143-4889-9434-27fb0e1ceef8.jpg",
      "mediaType": "image/jpeg",
      "width": 280,
      "height": 157
    },
    {
      "type": "Image",
      "url": "https://tilvids.com/lazy-static/previews/c2af3c5a-9ec6-4a2b-8ff2-c574e5e56e4e.jpg",
      "mediaType": "image/jpeg",
      "width": 850,
      "height": 480
    }
  ],
  "url": [
    {
      "type": "Link",
      "mediaType": "text/html",
      "href": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6"
    },
    {
      "type": "Link",
      "mediaType": "application/x-mpegURL",
      "href": "https://tilvids.com/static/streaming-playlists/hls/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/c188f9cf-3b66-4b79-8bc8-72708979b71e-master.m3u8",
      "tag": [
        {
          "type": "Infohash",
          "name": "5514512fd7204cd1c6af6c02da33ae5c9a83cab2"
        },
        {
          "type": "Infohash",
          "name": "4bcba22af8a6b99e262da33bf027128476828c43"
        },
        {
          "type": "Infohash",
          "name": "353819b7605c291d79c8cb5dab21fcdd8d3d3ace"
        },
        {
          "type": "Link",
          "name": "sha256",
          "mediaType": "application/json",
          "href": "https://tilvids.com/static/streaming-playlists/hls/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/60874769-1abe-4d38-966f-32675c965890-segments-sha256.json"
        },
        {
          "type": "Link",
          "mediaType": "video/mp4",
          "href": "https://tilvids.com/static/streaming-playlists/hls/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/952a67c5-29eb-4fa0-a2d7-32781509d479-1080-fragmented.mp4",
          "height": 1080,
          "size": 180928284,
          "fps": 50
        },
        {
          "type": "Link",
          "rel": [
            "metadata",
            "video/mp4"
          ],
          "mediaType": "application/json",
          "href": "https://tilvids.com/api/v1/videos/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/metadata/562493",
          "height": 1080,
          "fps": 50
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent",
          "href": "https://tilvids.com/lazy-static/torrents/e2a9de50-0d3f-46bd-b326-0e4c8cd7a8be-1080-hls.torrent",
          "height": 1080
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
          "href": "magnet:?xs=https%3A%2F%2Ftilvids.com%2Flazy-static%2Ftorrents%2Fe2a9de50-0d3f-46bd-b326-0e4c8cd7a8be-1080-hls.torrent&xt=urn:btih:196bd2d8758e1212ebfa9d3f43eb66a1a6f65643&dn=Fedora+wants+AI%2C+Nvidia+%2B+Wayland+fixed%2C+Proton+buys+Standard+Notes%3A+Linux+%26+Open+Source+News&tr=https%3A%2F%2Ftilvids.com%2Ftracker%2Fannounce&tr=wss%3A%2F%2Ftilvids.com%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Ftilvids.com%2Fstatic%2Fstreaming-playlists%2Fhls%2F1c97fd94-5fb3-45e5-ad65-b52b722a64f6%2F952a67c5-29eb-4fa0-a2d7-32781509d479-1080-fragmented.mp4",
          "height": 1080
        },
        {
          "type": "Link",
          "mediaType": "video/mp4",
          "href": "https://tilvids.com/static/streaming-playlists/hls/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/75a91130-7efe-4e34-b343-e11e1a0803db-360-fragmented.mp4",
          "height": 360,
          "size": 56365565,
          "fps": 25
        },
        {
          "type": "Link",
          "rel": [
            "metadata",
            "video/mp4"
          ],
          "mediaType": "application/json",
          "href": "https://tilvids.com/api/v1/videos/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/metadata/562503",
          "height": 360,
          "fps": 25
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent",
          "href": "https://tilvids.com/lazy-static/torrents/8b9685dd-7485-4d5a-95fe-34bb024587a0-360-hls.torrent",
          "height": 360
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
          "href": "magnet:?xs=https%3A%2F%2Ftilvids.com%2Flazy-static%2Ftorrents%2F8b9685dd-7485-4d5a-95fe-34bb024587a0-360-hls.torrent&xt=urn:btih:d6a58d28ffd09b9ce12a7a54094020ab4b228b2b&dn=Fedora+wants+AI%2C+Nvidia+%2B+Wayland+fixed%2C+Proton+buys+Standard+Notes%3A+Linux+%26+Open+Source+News&tr=https%3A%2F%2Ftilvids.com%2Ftracker%2Fannounce&tr=wss%3A%2F%2Ftilvids.com%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Ftilvids.com%2Fstatic%2Fstreaming-playlists%2Fhls%2F1c97fd94-5fb3-45e5-ad65-b52b722a64f6%2F75a91130-7efe-4e34-b343-e11e1a0803db-360-fragmented.mp4",
          "height": 360
        },
        {
          "type": "Link",
          "mediaType": "video/mp4",
          "href": "https://tilvids.com/static/streaming-playlists/hls/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/89b4b150-d894-42ed-a02d-f6296bf7e63b-144-fragmented.mp4",
          "height": 144,
          "size": 27060941,
          "fps": 25
        },
        {
          "type": "Link",
          "rel": [
            "metadata",
            "video/mp4"
          ],
          "mediaType": "application/json",
          "href": "https://tilvids.com/api/v1/videos/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/metadata/562502",
          "height": 144,
          "fps": 25
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent",
          "href": "https://tilvids.com/lazy-static/torrents/78480b6e-28e2-43fb-8b76-3c3a1d30fe00-144-hls.torrent",
          "height": 144
        },
        {
          "type": "Link",
          "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
          "href": "magnet:?xs=https%3A%2F%2Ftilvids.com%2Flazy-static%2Ftorrents%2F78480b6e-28e2-43fb-8b76-3c3a1d30fe00-144-hls.torrent&xt=urn:btih:205e02f04302b581e8e2a3a11ae77da887f27ca1&dn=Fedora+wants+AI%2C+Nvidia+%2B+Wayland+fixed%2C+Proton+buys+Standard+Notes%3A+Linux+%26+Open+Source+News&tr=https%3A%2F%2Ftilvids.com%2Ftracker%2Fannounce&tr=wss%3A%2F%2Ftilvids.com%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Ftilvids.com%2Fstatic%2Fstreaming-playlists%2Fhls%2F1c97fd94-5fb3-45e5-ad65-b52b722a64f6%2F89b4b150-d894-42ed-a02d-f6296bf7e63b-144-fragmented.mp4",
          "height": 144
        }
      ]
    },
    {
      "type": "Link",
      "name": "tracker-http",
      "rel": [
        "tracker",
        "http"
      ],
      "href": "https://tilvids.com/tracker/announce"
    },
    {
      "type": "Link",
      "name": "tracker-websocket",
      "rel": [
        "tracker",
        "websocket"
      ],
      "href": "wss://tilvids.com:443/tracker/socket"
    }
  ],
  "likes": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/likes",
  "dislikes": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/dislikes",
  "shares": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/announces",
  "comments": "https://tilvids.com/videos/watch/1c97fd94-5fb3-45e5-ad65-b52b722a64f6/comments",
  "attributedTo": [
    {
      "type": "Person",
      "id": "https://tilvids.com/accounts/thelinuxexperiment"
    },
    {
      "type": "Group",
      "id": "https://tilvids.com/video-channels/thelinuxexperiment_channel"
    }
  ],
  "isLiveBroadcast": false,
  "liveSaveReplay": null,
  "permanentLive": null,
  "latencyMode": null,
  "peertubeLiveChat": false
}

Channel Actor (Group) (https://tilvids.com/video-channels/thelinuxexperiment_channel)

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/v1",
    {
      "RsaSignature2017": "https://w3id.org/security#RsaSignature2017"
    },
    {
      "pt": "https://joinpeertube.org/ns#",
      "sc": "http://schema.org/",
      "playlists": {
        "@id": "pt:playlists",
        "@type": "@id"
      },
      "support": {
        "@type": "sc:Text",
        "@id": "pt:support"
      },
      "icons": "as:icon"
    }
  ],
  "type": "Group",
  "id": "https://tilvids.com/video-channels/thelinuxexperiment_channel",
  "following": "https://tilvids.com/video-channels/thelinuxexperiment_channel/following",
  "followers": "https://tilvids.com/video-channels/thelinuxexperiment_channel/followers",
  "playlists": "https://tilvids.com/video-channels/thelinuxexperiment_channel/playlists",
  "inbox": "https://tilvids.com/video-channels/thelinuxexperiment_channel/inbox",
  "outbox": "https://tilvids.com/video-channels/thelinuxexperiment_channel/outbox",
  "preferredUsername": "thelinuxexperiment_channel",
  "url": "https://tilvids.com/video-channels/thelinuxexperiment_channel",
  "name": "The Linux Experiment",
  "endpoints": {
    "sharedInbox": "https://tilvids.com/inbox"
  },
  "publicKey": {
    "id": "https://tilvids.com/video-channels/thelinuxexperiment_channel#main-key",
    "owner": "https://tilvids.com/video-channels/thelinuxexperiment_channel",
    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7mWF3Il0lE+nWiArDK4B\n8Z9rUCYR/C9651CcqPFIpHFLkJgoAkYxeMqfCo7lbXil1abaQERjgAYAJtdfObvY\neqUrHejEHAClFIO5BilyTP8b02RVZX6xxtTNF7jUEePFI0xOtPtt3Yz+YP0c6rz6\noyCCpqTy8LRfDkD9RATQrYfFxZCQ2yo2SlCoymNrDjoVwPI0XMZWHyMthKcaVwAq\ni+dYd0pmNUxdY9V042tIg+YwR3mOYvkXCNqy1SDygcIY6N5kdqioFoKxMK3MFApK\nY7tkfZkZXLlBdzHjjtYGHictaZzNYl4HV6onx//A21w0A7dGimlYd5bYLwz/BteD\nTwIDAQAB\n-----END PUBLIC KEY-----"
  },
  "published": "2020-06-30T13:45:17.984Z",
  "icon": {
    "type": "Image",
    "mediaType": "image/jpeg",
    "height": 120,
    "width": 120,
    "url": "https://tilvids.com/lazy-static/avatars/13b0214b-edc0-4c5b-a04d-be648a3a370a.jpg"
  },
  "icons": [
    {
      "type": "Image",
      "mediaType": "image/jpeg",
      "height": 48,
      "width": 48,
      "url": "https://tilvids.com/lazy-static/avatars/1bbe97f1-d283-4db4-8bdd-e5320564aff9.jpg"
    },
    {
      "type": "Image",
      "mediaType": "image/jpeg",
      "height": 120,
      "width": 120,
      "url": "https://tilvids.com/lazy-static/avatars/13b0214b-edc0-4c5b-a04d-be648a3a370a.jpg"
    }
  ],
  "image": {
    "type": "Image",
    "mediaType": "image/jpeg",
    "height": 317,
    "width": 1920,
    "url": "https://tilvids.com/lazy-static/banners/1a8d6881-30c8-47cb-8576-7af62d869c45.jpg"
  },
  "summary": "I'm Nick, and I like to tinker with Linux stuff. I'll bumble through distro reviews, tutorials, and general helpful tidbits and impressions on Linux desktop environments, applications, and news. \n\nYou might see a bit of Linux gaming here and there, and some more personal opinion pieces, but in the end, it's more or less all about Linux and FOSS !\n\nIf you want to stay up to snuff, follow me on Mastodon: https://mastodon.social/@thelinuxEXP \n\nIf you can, consider supporting the channel here: \nhttps://www.patreon.com/thelinuxexperiment",
  "support": "Support the channel on Patreon: \nhttps://www.patreon.com/thelinuxexperiment\n\nSupport on Liberapay:\nhttps://liberapay.com/TheLinuxExperiment/",
  "attributedTo": [
    {
      "type": "Person",
      "id": "https://tilvids.com/accounts/thelinuxexperiment"
    }
  ]
}

To test this you can just insert the url in the search field. That will trigger mbin to process the activity as if it was sent to us.

Closes #162

To be able to handle the activities peertube sends these things needed to be added:
- extract the target magazine / group from the `attributedTo` property. It is an array with both the user and the channel (group) in it
- handle array as `url` property
- add `Video` as a supported entry type
@BentiGorlich BentiGorlich added enhancement New feature or request activitypub ActivityPub related issues backend Backend related issues and pull requests labels May 15, 2024
@BentiGorlich BentiGorlich self-assigned this May 15, 2024
@BentiGorlich BentiGorlich marked this pull request as draft May 15, 2024 14:59
@BentiGorlich
Copy link
Member Author

I noticed that there are a lot of weird issues with the header signature from tilvids on my server (activities that are sent by them) and I want to investigate what the exact issue is there

@BentiGorlich
Copy link
Member Author

As far as I can see the signature problems only occur, because tilvids has their cdn on another subdomain, but sends stuff as if it would come from the original domain. That could of course be a problem and something we should look at in another issue/PR, but I don't think that it will be problematic for the general PeerTube support, as it only uses the cdn to deliver updates on CacheFiles which is an AP entity that we do not support anyways and do not care about it either. That is a PeerTube <-> PeerTube thing

@BentiGorlich BentiGorlich marked this pull request as ready for review May 16, 2024 16:24
@BentiGorlich
Copy link
Member Author

As you can see it is working on GehirnEimer:

But I have to switch branches there

@BentiGorlich BentiGorlich added this to the v1.6.1 milestone May 31, 2024
@BentiGorlich
Copy link
Member Author

I asked for a better way to sync like/dislikes Chocobozzz/PeerTube#6400
SO far no result. My goto would be to introduce a new field for entries and posts: remote_like_count, remote_dislike_count and remote_boost_count. So only one request has to be made after getting an update activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
activitypub ActivityPub related issues backend Backend related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PeerTube Intergration
3 participants