|
1 | 1 | # -*- encoding: utf-8 -*- |
2 | 2 | # https://dev.twitch.tv/docs/v5/reference/videos/ |
3 | 3 |
|
4 | | -from twitch import keys |
5 | | -from twitch.api.parameters import BroadcastType, Period |
| 4 | +from twitch import keys, methods |
| 5 | +from twitch.api.parameters import BroadcastType, Period, Language |
6 | 6 | from twitch.queries import V5Query as Qry |
7 | 7 | from twitch.queries import HiddenApiQuery as HQry |
| 8 | +from twitch.queries import UploadsQuery as UQry |
8 | 9 | from twitch.queries import query |
9 | 10 |
|
10 | 11 |
|
@@ -38,6 +39,63 @@ def get_followed(limit=10, offset=0, broadcast_type=BroadcastType.HIGHLIGHT): |
38 | 39 | return q |
39 | 40 |
|
40 | 41 |
|
| 42 | +# required scope: channel_editor |
| 43 | +@query |
| 44 | +def create(channel_id, title, description=None, game=None, language=None, tag_list=None): |
| 45 | + q = Qry('videos/', method=methods.POST) |
| 46 | + q.add_param(keys.CHANNEL_ID, channel_id) |
| 47 | + q.add_param(keys.TITLE, title) |
| 48 | + q.add_param(keys.DESCRIPTION, description) |
| 49 | + q.add_param(keys.GAME, game) |
| 50 | + if language is not None: |
| 51 | + q.add_param(keys.LANGUAGE, Language.validate(language)) |
| 52 | + q.add_param(keys.TAG_LIST, tag_list) |
| 53 | + return q |
| 54 | + |
| 55 | + |
| 56 | +# required scope: channel_editor |
| 57 | +@query |
| 58 | +def update(video_id, title=None, description=None, game=None, language=None, tag_list=None): |
| 59 | + q = Qry('videos/{video_id}', method=methods.PUT) |
| 60 | + q.add_urlkw(keys.VIDEO_ID, video_id) |
| 61 | + q.add_param(keys.TITLE, title) |
| 62 | + q.add_param(keys.DESCRIPTION, description) |
| 63 | + q.add_param(keys.GAME, game) |
| 64 | + if language is not None: |
| 65 | + q.add_param(keys.LANGUAGE, Language.validate(language)) |
| 66 | + q.add_param(keys.TAG_LIST, tag_list) |
| 67 | + return q |
| 68 | + |
| 69 | + |
| 70 | +# required scope: channel_editor |
| 71 | +@query |
| 72 | +def delete(video_id): |
| 73 | + q = Qry('videos/{video_id}', method=methods.DELETE) |
| 74 | + q.add_urlkw(keys.VIDEO_ID, video_id) |
| 75 | + return q |
| 76 | + |
| 77 | + |
| 78 | +# requires upload token |
| 79 | +@query |
| 80 | +def upload_part(video_id, part, upload_token, content_length, data): |
| 81 | + q = UQry('upload/{video_id}', method=methods.PUT) |
| 82 | + q.set_headers({'Content-Length': content_length, 'Content-Type': 'application/octet-stream'}) |
| 83 | + q.add_urlkw(keys.VIDEO_ID, video_id) |
| 84 | + q.add_param(keys.PART, part) |
| 85 | + q.add_param(keys.UPLOAD_TOKEN, upload_token) |
| 86 | + q.add_bin(data) |
| 87 | + return q |
| 88 | + |
| 89 | + |
| 90 | +# requires upload token |
| 91 | +@query |
| 92 | +def complete_upload(video_id, upload_token): |
| 93 | + q = UQry('upload/{video_id}/complete', method=methods.POST) |
| 94 | + q.add_urlkw(keys.VIDEO_ID, video_id) |
| 95 | + q.add_param(keys.UPLOAD_TOKEN, upload_token) |
| 96 | + return q |
| 97 | + |
| 98 | + |
41 | 99 | # required scope: none |
42 | 100 | # undocumented / unsupported |
43 | 101 | @query |
|
0 commit comments