Skip to content

Commit

Permalink
microformats2: convert audio and video properties to AS attachments
Browse files Browse the repository at this point in the history
for #102
  • Loading branch information
snarfed committed Feb 21, 2017
1 parent b8384bf commit fdfb457
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Changelog
* Source.get_activities(): start raising ValueError on bad argument values, notably invalid Facebook and Twitter ids and Instagram search queries.
* microformats2:
* Interpret `h-cite` and [`u-quotation-of` (experimental)](https://indieweb.org/quotation#How_to_markup) as attachments, e.g. for quote tweets.
* Convert [audio](http://indieweb.org/audio) and [video](http://indieweb.org/video) properties to AS attachments.
* Twitter:
* Linkify @-mentions and hashtags in `preview_create()`.
* Support creating quote tweets from attachments with Twitter URLs.
Expand Down
5 changes: 5 additions & 0 deletions granary/microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ def absolute_urls(prop):
for quote in mf2.get('children', []) + props.get('quotation-of', [])
if isinstance(quote, dict) and 'h-cite' in set(quote.get('type', []))]

# audio and video
for type in 'audio', 'video':
attachments.extend({'objectType': type, 'url': url}
for url in get_string_urls(props.get(type, [])))

obj = {
'id': prop.get('uid'),
'objectType': as_type,
Expand Down
12 changes: 12 additions & 0 deletions granary/test/testdata/note_with_audio_video.as-from-mf2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"objectType": "note",
"content": "something",
"attachments": [{
"objectType": "audio",
"url": "http://a/podcast.mp3"
}, {
"objectType": "video",
"url": "http://a/vidjo.mov"
}],
"stream": [{"url": "http://a/vidjo.mov"}]
}
8 changes: 8 additions & 0 deletions granary/test/testdata/note_with_audio_video.mf2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": ["h-entry"],
"properties": {
"content": "something",
"audio": ["http://a/podcast.mp3"],
"video": ["http://a/vidjo.mov"]
}
}

0 comments on commit fdfb457

Please sign in to comment.