Verified Commit f726b5e1 authored by Eliot Berriot's avatar Eliot Berriot 💬

See #578: Added twitter:* meta tags to detect tracks and albums players automatically on more sites

parent a6f12d36
......@@ -387,6 +387,10 @@ class TrackActivitySerializer(activity_serializers.ModelSerializer):
return "Audio"
def get_embed_url(type, id):
return settings.FUNKWHALE_EMBED_URL + "?type={}&id={}".format(type, id)
class OembedSerializer(serializers.Serializer):
format = serializers.ChoiceField(choices=["json"])
url = serializers.URLField()
......@@ -473,10 +477,7 @@ class OembedSerializer(serializers.Serializer):
data[
"html"
] = '<iframe width="{}" height="{}" scrolling="no" frameborder="no" src="{}"></iframe>'.format(
data["width"],
data["height"],
settings.FUNKWHALE_EMBED_URL
+ "?type={}&id={}".format(embed_type, embed_id),
data["width"], data["height"], get_embed_url(embed_type, embed_id)
)
return data
......
......@@ -6,6 +6,20 @@ from django.urls import reverse
from funkwhale_api.common import utils
from . import models
from . import serializers
def get_twitter_card_metas(type, id):
return [
{"tag": "meta", "property": "twitter:card", "content": "player"},
{
"tag": "meta",
"property": "twitter:player",
"content": serializers.get_embed_url(type, id),
},
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
]
def library_track(request, pk):
......@@ -72,6 +86,8 @@ def library_track(request, pk):
),
}
)
# twitter player is also supported in various software
metas += get_twitter_card_metas(type="track", id=obj.pk)
return metas
......@@ -131,6 +147,8 @@ def library_album(request, pk):
),
}
)
# twitter player is also supported in various software
metas += get_twitter_card_metas(type="album", id=obj.pk)
return metas
......
......@@ -3,6 +3,7 @@ import urllib.parse
from django.urls import reverse
from funkwhale_api.common import utils
from funkwhale_api.music import serializers
def test_library_track(spa_html, no_api_auth, client, factories, settings):
......@@ -68,6 +69,14 @@ def test_library_track(spa_html, no_api_auth, client, factories, settings):
)
),
},
{"tag": "meta", "property": "twitter:card", "content": "player"},
{
"tag": "meta",
"property": "twitter:player",
"content": serializers.get_embed_url("track", id=track.id),
},
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
]
metas = utils.parse_meta(response.content.decode())
......@@ -122,6 +131,14 @@ def test_library_album(spa_html, no_api_auth, client, factories, settings):
)
),
},
{"tag": "meta", "property": "twitter:card", "content": "player"},
{
"tag": "meta",
"property": "twitter:player",
"content": serializers.get_embed_url("album", id=album.id),
},
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
]
metas = utils.parse_meta(response.content.decode())
......
Added twitter:* meta tags to detect tracks and albums players automatically on more sites (#578)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment