• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

OpenTweenのfork


Commit MetaInfo

修訂be1780185197ceebb0ae1f0769b72dd4ab567099 (tree)
時間2012-02-22 19:47:10
作者Kimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

Merge remote-tracking branch 'sfjp/csharp-translation' into csharp-translation

Change Summary

差異

--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
22 *.user
33 bin
44 obj
5+*~
--- a/Tween/Connection/TwitVideo.vb
+++ /dev/null
@@ -1,105 +0,0 @@
1-Imports System.IO
2-Imports System.Text
3-Imports System.Net
4-
5-Public Class TwitVideo
6- Inherits HttpConnection
7-
8- Private Const ConsumerKey As String = "7c4dc004a88e821b02c87a0cde2fa85c"
9- Private multimediaExt() As String = {".avi", _
10- ".wmv", _
11- ".flv", _
12- ".m4v", _
13- ".mov", _
14- ".mp4", _
15- ".rm", _
16- ".mpeg", _
17- ".mpg", _
18- ".3gp", _
19- ".3g2"}
20- Private pictureExt() As String = {".jpg", _
21- ".jpeg", _
22- ".gif", _
23- ".png"}
24-
25- Private Const MaxPictureFileSize As Long = 10 * 1024 * 1024
26- Private Const MaxMultiMediaFileSize As Long = 20 * 1024 * 1024
27-
28- Public Function Upload(ByVal mediaFile As FileInfo, _
29- ByVal message As String, _
30- ByVal keyword As String, _
31- ByVal username As String, _
32- ByVal twitter_id As String, _
33- ByRef content As String) As HttpStatusCode
34- 'Message必須
35- If String.IsNullOrEmpty(message) Then Throw New ArgumentException("'Message' is required.")
36- 'Check filetype and size
37- If Array.IndexOf(multimediaExt, mediaFile.Extension.ToLower) > -1 Then
38- If mediaFile.Length > MaxMultiMediaFileSize Then Throw New ArgumentException("File is too large.")
39- ElseIf Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then
40- If mediaFile.Length > MaxPictureFileSize Then Throw New ArgumentException("File is too large.")
41- Else
42- Throw New ArgumentException("Service don't support this filetype.")
43- End If
44- 'Endpoint(URI+Token)
45- Const URLBASE As String = "http://api.twitvideo.jp/oauth/upload/"
46- Dim data As Byte() = Encoding.ASCII.GetBytes(ConsumerKey.Substring(0, 9) + username)
47- Dim bHash As Byte() = (New System.Security.Cryptography.MD5CryptoServiceProvider()).ComputeHash(data)
48- Dim url As String = URLBASE + BitConverter.ToString(bHash).ToLower.Replace("-", "")
49- 'Parameters
50- Dim param As New Dictionary(Of String, String)
51- param.Add("username", username)
52- If Not String.IsNullOrEmpty(twitter_id) Then param.Add("twitter_id", twitter_id)
53- If Not String.IsNullOrEmpty(keyword) Then param.Add("keyword", keyword)
54- param.Add("type", "xml")
55- param.Add("message", message)
56- Dim binary As New List(Of KeyValuePair(Of String, FileInfo))
57- binary.Add(New KeyValuePair(Of String, FileInfo)("media", mediaFile))
58- Me.InstanceTimeout = 60000 'タイムアウト60秒
59-
60- Dim req As HttpWebRequest = CreateRequest(PostMethod, _
61- New Uri(url), _
62- param, _
63- binary, _
64- False)
65- Return Me.GetResponse(req, content, Nothing, False)
66- End Function
67-
68- Public Function CheckValidExtension(ByVal ext As String) As Boolean
69- If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
70- Return True
71- End If
72- If Array.IndexOf(multimediaExt, ext.ToLower) > -1 Then
73- Return True
74- End If
75- Return False
76- End Function
77-
78- Public Function GetFileType(ByVal ext As String) As UploadFileType
79- If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
80- Return UploadFileType.Picture
81- End If
82- If Array.IndexOf(multimediaExt, ext.ToLower) > -1 Then
83- Return UploadFileType.MultiMedia
84- End If
85- Return UploadFileType.Invalid
86- End Function
87-
88- Public Function IsSupportedFileType(ByVal type As UploadFileType) As Boolean
89- Return type.Equals(UploadFileType.Picture) OrElse type.Equals(UploadFileType.MultiMedia)
90- End Function
91-
92- Public Function GetMaxFileSize(ByVal ext As String) As Long
93- If Array.IndexOf(multimediaExt, ext.ToLower) > -1 Then
94- Return MaxMultiMediaFileSize
95- ElseIf Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
96- Return MaxPictureFileSize
97- End If
98- Return -1
99- End Function
100-
101- Public Function GetFileOpenDialogFilter() As String
102- Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png|" + _
103- "Movie Files(*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2)|*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2"
104- End Function
105-End Class
--- a/Tween/Connection/TwitterPhoto.vb
+++ /dev/null
@@ -1,88 +0,0 @@
1-Imports System.IO
2-Imports System.Net
3-Imports System.Xml
4-
5-Public Class TwitterPhoto
6- Implements IMultimediaShareService
7-
8- Private pictureExt() As String = {".jpg", _
9- ".jpeg", _
10- ".gif", _
11- ".png"}
12-
13- Private Const MaxfilesizeDefault As Int64 = 3145728
14-
15- ' help/configurationにより取得されコンストラクタへ渡される
16- Private _MaxFileSize As Int64 = 3145728
17-
18- Private tw As Twitter
19-
20- Public Function CheckValidExtension(ext As String) As Boolean Implements IMultimediaShareService.CheckValidExtension
21- If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
22- Return True
23- End If
24- Return False
25- End Function
26-
27- Public Function CheckValidFilesize(ext As String, fileSize As Long) As Boolean Implements IMultimediaShareService.CheckValidFilesize
28- If Me.CheckValidExtension(ext) Then
29- Return fileSize <= _MaxFileSize
30- End If
31- Return False
32- End Function
33-
34- Public Function Configuration(ByVal key As String, ByVal value As Object) As Boolean Implements IMultimediaShareService.Configuration
35- If key = "MaxUploadFilesize" Then
36- Dim val As Int64
37- Try
38- val = Convert.ToInt64(value)
39- If val > 0 Then
40- _MaxFileSize = val
41- Else
42- _MaxFileSize = MaxfilesizeDefault
43- End If
44- Catch ex As Exception
45- _MaxFileSize = MaxfilesizeDefault
46- Return False 'error
47- End Try
48- Return True ' 正常に設定終了
49- End If
50- Return True ' 設定項目がない場合はとりあえずエラー扱いにしない
51- End Function
52-
53- Public Function GetFileOpenDialogFilter() As String Implements IMultimediaShareService.GetFileOpenDialogFilter
54- Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png"
55- End Function
56-
57- Public Function GetFileType(ext As String) As MyCommon.UploadFileType Implements IMultimediaShareService.GetFileType
58- If Me.CheckValidExtension(ext) Then
59- Return UploadFileType.Picture
60- End If
61- Return UploadFileType.Invalid
62- End Function
63-
64- Public Function IsSupportedFileType(type As MyCommon.UploadFileType) As Boolean Implements IMultimediaShareService.IsSupportedFileType
65- Return type.Equals(UploadFileType.Picture)
66- End Function
67-
68- Public Function Upload(ByRef filePath As String,
69- ByRef message As String,
70- ByVal reply_to As Long) As String Implements IMultimediaShareService.Upload
71- If String.IsNullOrEmpty(filePath) Then Return "Err:File isn't specified."
72- If String.IsNullOrEmpty(message) Then message = ""
73- Dim mediaFile As FileInfo
74- Try
75- mediaFile = New FileInfo(filePath)
76- Catch ex As NotSupportedException
77- Return "Err:" + ex.Message
78- End Try
79- If Not mediaFile.Exists Then Return "Err:File isn't exists."
80- If IsAnimatedGif(filePath) Then Return "Err:Don't support animatedGIF."
81-
82- Return tw.PostStatusWithMedia(message, reply_to, mediaFile)
83- End Function
84-
85- Public Sub New(ByVal twitter As Twitter)
86- tw = twitter
87- End Sub
88-End Class
--- /dev/null
+++ b/TweenCS/Connection/TwitVideo.cs
@@ -0,0 +1,138 @@
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>
7+// (c) 2011 spinor (@tplantd) <http://d.hatena.ne.jp/spinor/>
8+// All rights reserved.
9+//
10+// This file is part of OpenTween.
11+//
12+// This program is free software; you can redistribute it and/or modify it
13+// under the terms of the GNU General Public License as published by the Free
14+// Software Foundation; either version 3 of the License, or (at your option)
15+// any later version.
16+//
17+// This program is distributed in the hope that it will be useful, but
18+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+// for more details.
21+//
22+// You should have received a copy of the GNU General Public License along
23+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25+// Boston, MA 02110-1301, USA.
26+
27+using HttpStatusCode = System.Net.HttpStatusCode;
28+using FileInfo = System.IO.FileInfo;
29+using ArgumentException = System.ArgumentException;
30+using Array = System.Array;
31+using Encoding = System.Text.Encoding;
32+using BitConverter = System.BitConverter;
33+using System.Collections.Generic; // for Dictionary<TKey, TValue>, List<T>, KeyValuePair<TKey, TValue>
34+using HttpWebRequest = System.Net.HttpWebRequest;
35+using Uri = System.Uri;
36+using UploadFileType = MyCommon.UploadFileType;
37+
38+public class TwitVideo : HttpConnection
39+{
40+ private const string ConsumerKey = "7c4dc004a88e821b02c87a0cde2fa85c";
41+
42+ private string[] multimediaExt = new string[] { ".avi", ".wmv", ".flv", ".m4v", ".mov", ".mp4", ".rm", ".mpeg", ".mpg", ".3gp", ".3g2" };
43+
44+ private string[] pictureExt = new string[] { ".jpg", ".jpeg", ".gif", ".png" };
45+
46+ private const long MaxPictureFileSize = 10 * 1024 * 1024;
47+
48+ private const long MaxMultiMediaFileSize = 20 * 1024 * 1024;
49+
50+ public HttpStatusCode Upload( FileInfo mediaFile, string message, string keyword, string username, string twitter_id, ref string content )
51+ {
52+ // Message必須
53+ if ( string.IsNullOrEmpty( message ) )
54+ throw new ArgumentException( "'Message' is required." );
55+
56+ // Check filetype and size
57+ if ( Array.IndexOf( multimediaExt, mediaFile.Extension.ToLower ) > -1 )
58+ {
59+ if ( mediaFile.Length > this.MaxMultiMediaFileSize )
60+ throw new ArgumentException( "File is too large." );
61+ }
62+ else if ( Array.IndexOf( pictureExt, mediaFile.Extension.ToLower ) > -1 )
63+ {
64+ if ( mediaFile.Length > this.MaxPictureFileSize )
65+ throw new ArgumentException( "File is too large." );
66+ }
67+ else
68+ {
69+ throw new ArgumentException( "Service don't support this filetype." );
70+ }
71+
72+ // Endpoint(URI+Token)
73+ const string URLBASE = "http://api.twitvideo.jp/oauth/upload/";
74+ byte[] data = Encoding.ASCII.GetBytes( this.ConsumerKey.Substring( 0, 9 ) + username );
75+ byte[] dHash = ( new System.Security.Cryptography.MD5CryptoServiceProvider() ).ComputeHash( data );
76+ string url = URLBASE + BitConverter.ToString( bHash ).ToLower.Replace( "-", "" );
77+
78+ // Parameters
79+ Dictionary< string, string > param = new Dictionary< string, string >();
80+ param.Add( "username", username );
81+ if ( !string.IsNullOrEmpty( twitter_id ) )
82+ param.Add( "twitter_id", twitter_id );
83+ if ( !string.IsNullOrEmpty( keyword ) )
84+ param.Add( "keyword", keyword );
85+ param.Add( "type", "xml" );
86+ param.Add( "message", message );
87+ List< KeyValuePair< string, FileInfo > > binary = new List< KeyValuePair< string, FileInfo > >();
88+ binary.Add( new KeyValuePair< string, FileInfo >( "media", mediaFile ) );
89+ this.InstanceTimeout = 60000; // タイムアウト60秒
90+
91+ HttpWebRequest req = this.CreateRequest( HttpConnection.PostMethod, new Uri( url ), param, binary, false );
92+ return this.GetResponse( req, ref content, null, false )
93+ }
94+
95+ public bool CheckValidExtension( string ext )
96+ {
97+ if ( Array.IndexOf( this.pictureExt, ext.ToLower ) > -1 )
98+ return true;
99+
100+ if ( Array.IndexOf( this.multimediaExt, ext.ToLower ) > -1 )
101+ return true;
102+
103+ return false;
104+ }
105+
106+ UploadFileType GetFileType( string ext )
107+ {
108+ if ( Array.IndexOf( this.pictureExt, ext.ToLower ) > -1 )
109+ return UploadFileType.Picture;
110+
111+ if ( Array.IndexOf( this.multimediaExt, ext.ToLower ) > -1 )
112+ return UploadFileType.MultiMedia;
113+
114+ return UploadFileType.Invalid;
115+ }
116+
117+ bool IsSupportedFileType( UploadFileType type )
118+ {
119+ return type.Equals( UploadFileType.Picture ) || type.Equals( UploadFileType.MultiMedia );
120+ }
121+
122+ long GetMaxFileSize( string ext )
123+ {
124+ if ( Array.IndexOf( this.pictureExt, ext.ToLower ) > -1 )
125+ return this.MaxPictureFileSize;
126+
127+ if ( Array.IndexOf( this.multimediaExt, ext.ToLower ) > -1 )
128+ return this.MaxMultiMediaFileSize;
129+
130+ return -1;
131+ }
132+
133+ string GetFileOpenDialogFilter()
134+ {
135+ return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png|"
136+ + "Movie Files(*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2)|*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2";
137+ }
138+}
--- /dev/null
+++ b/TweenCS/Connection/TwitterPhoto.cs
@@ -0,0 +1,130 @@
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>
7+// (c) 2011 spinor (@tplantd) <http://d.hatena.ne.jp/spinor/>
8+// All rights reserved.
9+//
10+// This file is part of OpenTween.
11+//
12+// This program is free software; you can redistribute it and/or modify it
13+// under the terms of the GNU General Public License as published by the Free
14+// Software Foundation; either version 3 of the License, or (at your option)
15+// any later version.
16+//
17+// This program is distributed in the hope that it will be useful, but
18+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+// for more details.
21+//
22+// You should have received a copy of the GNU General Public License along
23+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25+// Boston, MA 02110-1301, USA.
26+
27+using Array = System.Array;
28+using Convert = System.Convert;
29+using FileInfo = System.IO.FileInfo;
30+
31+public class TwitterPhoto : IMultimediaShareService
32+{
33+ private string[] pictureExt = new string[] { ".jpg", ".jpeg", ".gif", ".png" };
34+
35+ private const long MaxfilesizeDefault = 3145728;
36+
37+ // help/configurationにより取得されコンストラクタへ渡される
38+ private long _MaxFileSize = 3145728;
39+
40+ private Twitter tw;
41+
42+ public bool CheckValidExtension( string ext )
43+ {
44+ if ( Array.IndexOf( this.pictureExt, ext.ToLower() ) > -1 )
45+ return true;
46+
47+ return false;
48+ }
49+
50+ public bool CheckValidFilesize( string ext, long fileSize )
51+ {
52+ if ( this.CheckValidExtension( ext ) )
53+ return fileSize <= this._MaxFileSize;
54+
55+ return false;
56+ }
57+
58+ public bool Configuration( string key, object value )
59+ {
60+ if ( key == "MaxUploadFilesize" )
61+ {
62+ long val;
63+ try
64+ {
65+ val = Convert.ToInt64( value );
66+ if ( val > 0 )
67+ this._MaxFileSize = val;
68+ else
69+ this._MaxFileSize = this.MaxfilesizeDefault;
70+ }
71+ catch ( Exception ex )
72+ {
73+ this._MaxFileSize = this.MaxfilesizeDefault;
74+ return false; // error
75+ }
76+ return true; // 正常に設定終了
77+ }
78+ return true; // 設定項目がない場合はとりあえずエラー扱いにしない
79+ }
80+
81+ public string GetFileOpenDialogFilter()
82+ {
83+ return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png";
84+ }
85+
86+ public MyCommon.UploadFileType GetFileType( string ext )
87+ {
88+ if ( this.CheckValidExtension( ext ) )
89+ return UploadFileType.Picture;
90+
91+ return UploadFileType.Invalid;
92+ }
93+
94+ public bool IsSupportedFileType( MyCommon.UploadFileType type )
95+ {
96+ return type.Equals( UploadFileType.Picture );
97+ }
98+
99+ public string Upload( ref string filePath, ref string message, long reply_to )
100+ {
101+ if ( string.IsNullOrEmpty( filePath ) )
102+ return "Err:File isn't specified.";
103+
104+ if ( string.IsNullOrEmpty( message ) )
105+ message = "";
106+
107+ FileInfo mediaFile;
108+ try
109+ {
110+ mediaFile = new FileInfo( filePath );
111+ }
112+ catch ( NotSupportedException ex )
113+ {
114+ return "Err:" + ex.Message;
115+ }
116+
117+ if ( !mediaFile.Exists )
118+ return "Err:File isn't exists.";
119+
120+ if ( MyCommon.IsAnimatedGif( filePath ) )
121+ return "Err:Don't support animatedGIF.";
122+
123+ return tw.PostStatusWithMedia( message, reply_to, mediaFile );
124+ }
125+
126+ public void New( Twitter twitter )
127+ {
128+ this.tw = twitter;
129+ }
130+}