1 ' OpenTween - Client of Twitter
2 ' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 ' (c) 2008-2011 Moz (@syo68k)
4 ' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 ' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 ' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
9 ' This file is part of OpenTween.
11 ' This program is free software; you can redistribute it and/or modify it
12 ' under the terms of the GNU General Public License as published by the Free
13 ' Software Foundation; either version 3 of the License, or (at your option)
16 ' This program is distributed in the hope that it will be useful, but
17 ' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 ' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 ' You should have received a copy of the GNU General Public License along
22 ' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23 ' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24 ' Boston, MA 02110-1301, USA.
30 Public Class PictureService
33 Public Function Upload(ByRef filePath As String, ByRef message As String, ByVal service As String) As String
36 file = New FileInfo(filePath)
37 Catch ex As NotSupportedException
38 Return "Err:" + ex.Message
40 If Not file.Exists Then Return "Err:File isn't exists."
41 Dim st As AppendSettingDialog = AppendSettingDialog.Instance
42 Dim ret As String = ""
43 Dim upResult As Boolean = False
46 ret = UpToTwitPic(file, message, upResult)
48 ret = UpToimgly(file, message, upResult)
50 ' ret = UpToTwitVideo(file, message, upResult)
52 ret = UpToyfrog(file, message, upResult)
54 ret = UpToPlixi(file, message, upResult)
56 If upResult Then filePath = ""
60 Public Function IsValidExtension(ByVal ext As String, ByVal service As String) As Boolean
61 Dim ret As Boolean = False
64 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
66 ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
68 ' ret = (New TwitVideo).CheckValidExtension(ext)
70 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
72 ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
77 Public Function GetFileOpenDialogFilter(ByVal service As String) As String
78 Dim ret As String = ""
81 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
83 ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
85 ' ret = (New TwitVideo).GetFileOpenDialogFilter
87 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
89 ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
94 Public Function GetFileType(ByVal ext As String, ByVal service As String) As UploadFileType
95 Dim ret As UploadFileType = UploadFileType.Invalid
98 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
100 ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
102 ' ret = (New TwitVideo).GetFileType(ext)
104 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
106 ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
111 Public Function IsSupportedFileType(ByVal type As UploadFileType, ByVal service As String) As Boolean
112 Dim ret As Boolean = False
115 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
117 ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
119 ' ret = (New TwitVideo).IsSupportedFileType(type)
121 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
123 ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
128 Public Function GetMaxFileSize(ByVal ext As String, ByVal service As String) As Long
132 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
134 ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
136 ' ret = (New TwitVideo).GetMaxFileSize(ext)
138 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
140 ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
145 Private Function UpToTwitPic(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
146 Dim content As String = ""
147 Dim ret As HttpStatusCode
149 Dim svc As New TwitPic(tw.AccessToken, tw.AccessTokenSecret)
151 ret = svc.Upload(file, message, content)
152 Catch ex As Exception
153 Return "Err:" + ex.Message
155 Dim url As String = ""
156 If ret = HttpStatusCode.OK Then
157 Dim xd As XmlDocument = New XmlDocument()
161 url = xd.SelectSingleNode("/image/url").InnerText
162 Catch ex As XmlException
163 Return "Err:" + ex.Message
166 Return "Err:" + ret.ToString
172 If message.Length + url.Length + 1 > 140 Then
173 message = message.Substring(0, 140 - url.Length - 1) + " " + url
177 Return tw.PostStatus(message, 0)
180 Private Function UpToyfrog(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
181 Dim content As String = ""
182 Dim ret As HttpStatusCode
184 Dim svc As New yfrog(tw.AccessToken, tw.AccessTokenSecret)
186 ret = svc.Upload(file, message, content)
187 Catch ex As Exception
188 Return "Err:" + ex.Message
190 Dim url As String = ""
191 If ret = HttpStatusCode.OK Then
192 Dim xd As XmlDocument = New XmlDocument()
196 url = xd.SelectSingleNode("/rsp/mediaurl").InnerText
197 Catch ex As XmlException
198 Return "Err:" + ex.Message
201 Return "Err:" + ret.ToString
207 If message.Length + url.Length + 1 > 140 Then
208 message = message.Substring(0, 140 - url.Length - 1) + " " + url
212 Return tw.PostStatus(message, 0)
215 Private Function UpToimgly(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
216 Dim content As String = ""
217 Dim ret As HttpStatusCode
219 Dim svc As New imgly(tw.AccessToken, tw.AccessTokenSecret)
221 ret = svc.Upload(file, message, content)
222 Catch ex As Exception
223 Return "Err:" + ex.Message
225 Dim url As String = ""
226 If ret = HttpStatusCode.OK Then
227 Dim xd As XmlDocument = New XmlDocument()
231 url = xd.SelectSingleNode("/image/url").InnerText
232 Catch ex As XmlException
233 Return "Err:" + ex.Message
236 Return "Err:" + ret.ToString
242 If message.Length + url.Length + 1 > 140 Then
243 message = message.Substring(0, 140 - url.Length - 1) + " " + url
247 Return tw.PostStatus(message, 0)
250 Private Function UpToPlixi(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
251 Dim content As String = ""
252 Dim ret As HttpStatusCode
254 Dim svc As New Plixi(tw.AccessToken, tw.AccessTokenSecret)
256 ret = svc.Upload(file, message, content)
257 Catch ex As Exception
258 Return "Err:" + ex.Message
260 Dim url As String = ""
261 If ret = HttpStatusCode.Created Then
262 Dim xd As XmlDocument = New XmlDocument()
266 url = xd.ChildNodes().Item(0).ChildNodes(2).InnerText
267 Catch ex As XmlException
268 Return "Err:" + ex.Message
271 Return "Err:" + ret.ToString
277 If message.Length + url.Length + 1 > 140 Then
278 message = message.Substring(0, 140 - url.Length - 1) + " " + url
282 Return tw.PostStatus(message, 0)
285 'Private Function UpToTwitVideo(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
286 ' Dim content As String = ""
287 ' Dim ret As HttpStatusCode
289 ' Dim svc As New TwitVideo
291 ' ret = svc.Upload(file, message, "", tw.Username, tw.UserIdNo, content)
292 ' Catch ex As Exception
293 ' Return "Err:" + ex.Message
295 ' Dim url As String = ""
296 ' If ret = HttpStatusCode.OK Then
297 ' Dim xd As XmlDocument = New XmlDocument()
299 ' xd.LoadXml(content)
300 ' Dim rslt As String = xd.SelectSingleNode("/rsp/@status").Value
301 ' If rslt = "ok" Then
303 ' url = xd.SelectSingleNode("/rsp/mediaurl").InnerText
305 ' Return "Err:" + xd.SelectSingleNode("/rsp/err/@msg").Value
307 ' Catch ex As XmlException
308 ' Return "Err:" + ex.Message
311 ' Return "Err:" + ret.ToString
314 ' resultUpload = True
317 ' If message.Length + url.Length + 1 > 140 Then
318 ' message = message.Substring(0, 140 - url.Length - 1) + " " + url
320 ' message += " " + url
322 ' Return tw.PostStatus(message, 0)
325 Public Sub New(ByVal twInstance As Twitter)