Skip to content

Instantly share code, notes, and snippets.

@timtan
Last active January 12, 2023 13:23
Show Gist options
  • Save timtan/e02784030c112ded07b70d119bd02e9d to your computer and use it in GitHub Desktop.
Save timtan/e02784030c112ded07b70d119bd02e9d to your computer and use it in GitHub Desktop.

GliaStudio provides 2 APIs:

Video Creation API: Submit a video creation video

Job Status API: Check video creation status

驗證

合作廠商會於gliacloud 取得一段長度為 40的 hash token, 如 4852cb43656e01f9f7ebfdf548faab789378d58d 在使用api時, 於header 加入 token 資訊即可使用

example

add token in api request header

...
Authorization: Token 4852cb43656e01f9f7ebfdf548faab789378d58d
...

sample code python

import requests
headers = {"Authorization": "Token 4852cb43656e01f9f7ebfdf548faab789378d58d"}

api_url = "http://api.gliastudio.gliacloud.com/api/job"
requests.post(api_url, headers)

API

video create api

影片生成 api

path: /api/job/ method: POST content-type: application/json playload:

{
    'task': 'preview', # action
    'data': {} # video data
}

create video field

key desc sample
task create video action(可選\預設preview) preview(低畫質)
data 影片素材資訊 註解1

data fields (註解1)

影片素材資訊

    'data': {
        'article_url': '{{ article url|required }}',
        'article_content': '{{ article content | option}}',
        'article_html': '{{article html| option}}'
        'title': '{{ video title | option }}',
        'cover_image': '{{image url| option}}',
        'media_files': ['{{ video/image url|option }}'],
        'theme': '{{ theme|option }}',
        'meta_fields': {{ addition meta data for create video(dict)| option }}
   }
key desc sample
article_url 文章來源 url(必填) http://www.nownews.com/n/2016/11/17/2308745
article_content 文章 content(可選, 和article_html 則一即可) Georgia Gov. Nathan Deal and Atlanta Mayor Kasim...
article_html 文章 html(可選, 和article_content則一即可) <html><head></head>....</html>
title 影片title(可選) Anthem expected to confirm 1,000-job Midtown expansion Wednesday
cover_image cover image(可選) "http://media.bizj.us/view/img/5711821/midtown-atlanta-skyline-3-april-2015*750xx4928-2772-0-254.jpg"
media_files 額外素材(可選, 目前支援 youtube 影片連結(非短網址 20分鐘以內), 和直連 link) ["https://www.youtube.com/watch?v=Z1bAjbUTDpo", "http://media.bizj.us/view/img/5711821/midtown-atlanta-skyline-3-april-2015*750xx4928-2772-0-254.jpg"]
theme 影片theme(可選 註解2, 預設機器自動辨識) finance
meta_fields 額外資訊, 包含theme 特化欄位 {}

theme & meta data

finance

field_name: stock_info

key desc sample
market 股票市場 NASDAQ
ticker 股碼 AAPL
company_name 公司名稱 Apple

sample meta_field:

meta_fields ={
  'stock_info': {
    'market': 'NASDAQ',
    'ticker': 'AAPL',
    'company_name': 'APPLE'
  }
}

Response

content-type: application/json status_code: 200

{
    "id": {{video id}},
    "status": "processing",
}

sample code

    playload = {
        'task': 'preview',
        'data': {
            'article_url': 'http://www.bizjournals.com/atlanta/news/2016/10/25/anthem-expected-to-confirm-1-000-job-midtown.html',
            'article_content': '''Georgia Gov. Nathan Deal and Atlanta Mayor Kasim Reed are expected to announce an economic development project Monday morning.
That company is said to be Anthem Inc. (NYSE: ANTM), which plans to open a technology center in Midtown that could create “several thousand” jobs over time.''',
            'article_html': '''<html><head></head><title>Anthem expected to confirm 1,000-job Midtown expansion Wednesday</title><body>Georgia Gov. Nathan Deal and Atlanta Mayor Kasim Reed are expected to announce an economic development project Monday morning.
That company is said to be Anthem Inc. (NYSE: ANTM), which plans to open a technology center in Midtown that could create “several thousand” jobs over time.</body>''',
            'title': 'Anthem expected to confirm 1,000-job Midtown expansion Wednesday',
            'media_files': ['http://media.bizj.us/view/img/5711821/midtown-atlanta-skyline-3-april-2015*750xx4928-2772-0-254.jpg'],
            'cover_image': 'http://media.bizj.us/view/img/5711821/midtown-atlanta-skyline-3-april-2015*750xx4928-2772-0-254.jpg',
            'theme': 'bizjournals-atlanta',
            'meta_fields': {
                'stock_info': {
                    'market': 'NASDAQ',
                    'ticker': 'AAPL',
                    'company_name': 'APPLE'
                },
            }
        }
    }
    api = "https://api.gliastudio.gliacloud.com/api/job/"
    headers = {"Authorization": "Token 4852cb43656e01f9f7ebfdf548faab789378d58d"}
    requests.post(api, json=playload, headers=headers)

video create status api

確認video create status api

path: /api/job/{{video id}}/ method: GET

影片生成中 response

content-type: application/json status_code: 200

{
    "id": {{video id}},
    "status": "processing",
}

影片生成失敗 response

content-type: application/json status_code: 200

{
    "id": "{{video id}}",
    "status": "fail",
}

影片生成完成 response

content-type: application/json status_code: 200

{
    "id": "{{video id}}",
    "file_url": "http://api.gliastudio.gliacloud.com/media/videos/113_final.mp4",
    "status": "done"
}

找不到影片 response

content-type: application/json status_code: 404

{ 
    "status": "fail"
    "message": "{{video id}} is not exists",
}

伺服器錯誤 response

content-type: application/json status_code: 500

{
    "message": "internal server error",
    "status": "fail",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment