zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# -*- coding: utf-8 -*-
 
import re
import sys
from .base import AipBase
from .base import base64
from .base import json
from .base import urlencode
from .base import quote
 
 
class AipImageCensor(AipBase):
    """
        Aip ImageCensor
    """
 
    __imageCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined'
 
    __textCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined'
 
    __voiceCensorUserDefinedUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/voice_censor/v3/user_defined"
 
    __videoCensorUserDefinedUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/video_censor/v2/user_defined"
 
    __videoCensorSubmitUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/video_censor/v1/video/submit"
 
    __videoCensorPullUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/video_censor/v1/video/pull"
 
    __asyncVoiceSubmitUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/async_voice/submit"
 
    __asyncVoicePullUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/async_voice/pull"
 
    __liveConfigSaveUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/live/v1/config/save"
 
    __liveConfigStopUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/live/v1/config/stop"
 
    __liveConfigViewUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/live/v1/config/view"
 
    __liveAuditPullUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/live/v1/audit/pull"
 
    def imageCensorUserDefined(self, image):
        """
            imageCensorUserDefined
        """
 
        data = {}
 
        isUrl = image[0:4] == 'http'
        if not isUrl:
            data['image'] = base64.b64encode(image).decode()
        else:
            data['imgUrl'] = image
 
        return self._request(self.__imageCensorUserDefinedUrl, data)
 
    def textCensorUserDefined(self, text):
        """
            textCensorUserDefined
        """
 
        data = {}
 
        data['text'] = text
 
        return self._request(self.__textCensorUserDefinedUrl, data)
 
    def voiceCensorUserDefined(self, voice, rate, fmt, options=None):
        """
            voiceCensorUserDefined
        """
        data = {}
        options = options or {}
        data['base64'] = base64.b64encode(voice).decode()
        data['fmt'] = fmt
        data['rate'] = rate
        data.update(options)
        return self._request(self.__voiceCensorUserDefinedUrl, data)
 
    def voiceUrlCensorUserDefined(self, voice, rate, fmt, options=None):
        """
            voiceCensorUserDefined
        """
        data = {}
        options = options or {}
        data['url'] = voice
        data['fmt'] = fmt
        data['rate'] = rate
        data.update(options)
        return self._request(self.__voiceCensorUserDefinedUrl, data)
 
    def videoCensorUserDefined(self, name, videoUrl, extId, options=None):
        """
            videoCensorUserDefined
        """
        data = {}
        options = options or {}
        data['name'] = name
        data['videoUrl'] = videoUrl
        data['extId'] = extId
        data.update(options)
        return self._request(self.__videoCensorUserDefinedUrl, data)
 
    def videoCensorSubmit(self, url, extId, options=None):
        """
            videoCensorSubmit
        """
        data = {}
        options = options or {}
        data['url'] = url
        data['extId'] = extId
        data.update(options)
        return self._request(self.__videoCensorSubmitUrl, data)
 
    def videoCensorPull(self, taskId, options=None):
        """
            videoCensorPull
        """
        data = {}
        options = options or {}
        data['taskId'] = taskId
        data.update(options)
        return self._request(self.__videoCensorPullUrl, data)
 
    def asyncVoiceSubmit(self, url, fmt, rate, options=None):
        """
            asyncVoiceSubmit
        """
        data = {}
        options = options or {}
        data['url'] = url
        data['fmt'] = fmt
        data['rate'] = rate
        data.update(options)
        return self._request(self.__asyncVoiceSubmitUrl, data)
 
    def asyncVoiceTaskPull(self, taskId, options=None):
        """
            asyncVoiceTaskPull
        """
        data = {}
        options = options or {}
        data['taskId'] = taskId
        data.update(options)
        return self._request(self.__asyncVoicePullUrl, data)
 
    def asyncVoiceAudioPull(self, audioId, options=None):
        """
            asyncVoiceAudioPull
        """
        data = {}
        options = options or {}
        data['audioId'] = audioId
        data.update(options)
        return self._request(self.__asyncVoicePullUrl, data)
 
    def liveConfigSave(self, streamUrl, streamType, extId, startTime, endTime, streamName, options=None):
        """
            liveConfigSave
        """
        data = {}
        options = options or {}
        data['streamUrl'] = streamUrl
        data['streamType'] = streamType
        data['extId'] = extId
        data['startTime'] = startTime
        data['endTime'] = endTime
        data['streamName'] = streamName
        data.update(options)
        return self._request(self.__liveConfigSaveUrl, data)
 
    def liveConfigStop(self, taskId, options=None):
        """
            liveConfigStop
        """
        data = {}
        options = options or {}
        data['taskId'] = taskId
        data.update(options)
        return self._request(self.__liveConfigStopUrl, data)
 
    def liveConfigView(self, taskId, options=None):
        """
            liveConfigView
        """
        data = {}
        options = options or {}
        data['taskId'] = taskId
        data.update(options)
        return self._request(self.__liveConfigViewUrl, data)
 
    def liveAuditPull(self, taskId, options=None):
        """
            liveAuditPull
        """
        data = {}
        options = options or {}
        data['taskId'] = taskId
        data.update(options)
        return self._request(self.__liveAuditPullUrl, data)