Use .cast ext and application/x-asciicast media type

Closes #224
This commit is contained in:
Marcin Kulik
2017-12-01 22:48:24 +01:00
parent 4286e8f480
commit fe75b4e06c
3 changed files with 10 additions and 5 deletions

View File

@@ -206,7 +206,7 @@ Playing from HTTP(S) URL:
asciinema play http://example.com/demo.cast
Playing from asciicast page URL (requires `<link rel="alternate"
type="application/asciicast+json" href="....json">` in page's HTML):
type="application/x-asciicast" href="/my/ascii.cast">` in page's HTML):
asciinema play https://asciinema.org/a/22124
asciinema play http://example.com/blog/post.html

View File

@@ -19,14 +19,16 @@ class Parser(html.parser.HTMLParser):
self.url = None
def handle_starttag(self, tag, attrs_list):
# look for <link rel="alternate" type="application/asciicast+json" href="https://...json">
# look for <link rel="alternate" type="application/x-asciicast" href="https://...cast">
if tag == 'link':
attrs = {}
for k, v in attrs_list:
attrs[k] = v
if attrs.get('rel') == 'alternate' and attrs.get('type') == 'application/asciicast+json':
self.url = attrs.get('href')
if attrs.get('rel') == 'alternate':
type = attrs.get('type')
if type == 'application/asciicast+json' or type == 'application/x-asciicast':
self.url = attrs.get('href')
def open_url(url):
@@ -57,7 +59,7 @@ def open_url(url):
url = parser.url
if not url:
raise LoadError("""<link rel="alternate" type="application/asciicast+json" href="..."> not found in fetched HTML document""")
raise LoadError("""<link rel="alternate" type="application/x-asciicast" href="..."> not found in fetched HTML document""")
return open_url(url)

View File

@@ -17,6 +17,9 @@ Example file:
[6.541828, "o", "Bye!"]
```
Suggested file extension is `.cast`, suggested media type is
`application/x-asciicast`.
## Header
asciicast header is JSON-encoded object containing recording meta-data.