Commits

Anonymous committed 5569c70

first commit.

Comments (0)

Files changed (7)

+application: libraplanet-gae
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /shoutcast/.*
+  script: shoutcast.py
+
+- url: /mixitagmaker/get/.*
+  script: mixitagmaker.py
+
+- url: /mixitagmaker/post/.*
+  script: mixitagmaker.py
+
+- url: /mixitagmaker.html
+  static_files: mixitagmaker.html
+  upload: /mixitagmaker.html
+
+- url: .*
+  script: index.py
+#!/usr/bin/env python
+# coding=UTF-8
+# Copyright 2007 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import cgi
+import urllib
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import util
+
+
+#--------------------------------------------------------------------------------------------------
+# entry class
+#--------------------------------------------------------------------------------------------------
+class MainHandler(webapp.RequestHandler):
+
+  def get(self):
+    self.response.out.write('Hellow world!')
+    self.response.out.write('<br>')
+    self.response.out.write('GAE in libraplanet.net')
+    self.response.out.write('<p>')
+    self.response.out.write('<a href="./shoutcast/">shoutcast検索</a>')
+    self.response.out.write('</p>')
+    self.response.out.write('<p>')
+    self.response.out.write('<a href="./mixitagmaker/get/">mixitagmaker (GET)</a>')
+    self.response.out.write('</p>')
+    self.response.out.write('<p>')
+    self.response.out.write('<a href="./mixitagmaker/post/">mixitagmaker (POST)</a>')
+    self.response.out.write('</p>')
+
+
+#--------------------------------------------------------------------------------------------------
+# entry method
+#--------------------------------------------------------------------------------------------------
+def main():
+  application = webapp.WSGIApplication([('/', MainHandler)],
+                                       debug=True)
+  util.run_wsgi_app(application)
+
+#--------------------------------------------------------------------------------------------------
+# entry point
+#--------------------------------------------------------------------------------------------------
+if __name__ == '__main__':
+  main()
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run.  If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED").  If you want to manage some indexes
+# manually, move them above the marker line.  The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
+��sample text
+
+youtube - desktop
+http://www.youtube.com/watch?v=lqZB7nf4TXw&feature=player_embedded
+
+niconico - desktop
+http://www.nicovideo.jp/watch/sm374021
+
+youtube - mobile
+http://m.youtube.com/watch?desktop_uri=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyzC4hFK5P3g&v=yzC4hFK5P3g&gl=JP
+
+niconico - mobile
+http://m.nicovideo.jp/watch/sm2876719?cp_in=watch_sc&uid=NULLGWDOCOMO&DCMPAKEHO=ON&guid=ON

mixitagmaker.html

+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+		<title>mixi tag maker α版</title>
+	</head>
+	<body bgcolor="#666666" id="top">
+		<p>
+			<h2>
+				<font color="#ffbb33">mixi</font> <font color="#ffffff">tag maker α版</font>
+			</h2>
+			<a href="#manual">▼マニュアルへ▼</a>
+		</p>
+		<form action="./" method="$proc">
+			<p>
+				<font color="#ffffff">
+					<h5>[動画URLを含むテキストを入力]</h5>
+				</font>
+				<textarea  type="text" name="box_input" cols="50" rows="5">$box_input</textarea>
+				<br>
+				<input type="submit" value="変換">
+			</p>
+		</form>
+		<p>
+			<font color="#ffffff">
+				<h5>[変換後のテキスト]</h5>
+			</font>
+			<textarea  type="text" name="box_output" cols="50" rows="5">$box_output</textarea>
+		</p>
+		<p>
+			<font color="#ffffff">
+				<h5>[プレビュー]</h5>
+				$preview_output
+			</font>
+			</textarea>
+		</p>
+			<br>
+			<br>
+		<hr>
+			<br>
+			<br>
+		<p>
+			<font color="#ffffff">
+			<h3 id="manual">◇マニュアル◇</h3>
+			<br>
+			<br>
+			<h5>-概要-</h5>
+			動画サイトのURLをmixiの日記等に張り付けられる動画コントロールに変換するCGIです。
+			入力されたテキストからURLを走査し、対応する動画コントロールのタグへ一括変換します。
+			改行でリストアップするなどすれば、複数のURLを一括で変換が行えます。
+			また、変換しなかったテキストもそのまま出力するので、編集した日記のプリプロセスとしても利用できます。
+			<br>
+			<br>
+			  (例)<br>
+			  http://www.youtube.com/watch?v=****<br>
+			    ↓  ↓<br>
+			  &lt;externalvideo src="YT:****"&gt;<br>
+			<br>
+			<br>
+			携帯電話から動画を含む日記を投稿したい!と言うときなどを想定。
+			<br>
+			<br>
+			<h5>-対応動画サイト-</h5>
+			・youtube<br>
+			 www.youtube.com<br>
+			 m.youtube.com<br>
+			・niconico<br>
+			 www.nicovideo.jp<br>
+			 m.nicovideo.jp<br>
+			<br>
+			<br>
+			<h5>-使い方-</h5>
+			・上のテキストボックスにサイトのURL入りのテキストを入力します。<br>
+			URLは<font color="#ff0000">行頭で始まっている</font>必要があります。<br>
+			行頭で始まっていなかったり、パラメータの不正などで変換出来なかったURLは<font color="#ff0000">そのまま出力</font>されます。
+			<br>
+			・[変換]ボタンを押します。
+			<br>
+			・下のテキストボックスに変換後のテキストが出力されます。
+			また、その下にプレビューが表示されます。環境に応じて好きな方から、変換後のテキストをコピーしてください。
+			<br>
+			・変換後のテキストを使って日記を投稿してください。。
+			<br>
+			<br>
+		</p>
+		<p>
+			<font color="#ffffff">
+			<a href="#top">▲topへ▲</a>
+			</font>
+		</p>
+		<p>
+			<font color="#c0c0c0">
+			auther takumi
+			</font>
+		</p>
+		<font color="#ffffff">$trace</font>
+	</body>
+</html>
+#!/usr/bin/env python
+# coding=UTF-8
+#
+# Copyright 2007 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import cgi
+import urllib
+from urlparse import urlparse
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import util
+
+
+#--------------------------------------------------------------------------------------------------
+# get process class
+#--------------------------------------------------------------------------------------------------
+class MainHandlerByGet(webapp.RequestHandler):
+  def get(self):
+    mainProc(self.response, 'GET')
+
+#--------------------------------------------------------------------------------------------------
+# post process class
+#--------------------------------------------------------------------------------------------------
+class MainHandlerByPost(webapp.RequestHandler):
+  def get(self):
+    mainProc(self.response, 'POST')
+  def post(self):
+    mainProc(self.response, 'POST')
+
+#--------------------------------------------------------------------------------------------------
+# main process
+#--------------------------------------------------------------------------------------------------
+def mainProc(response, proc):
+  f = cgi.FieldStorage();
+  box_input = f.getfirst('box_input', '').strip()
+  box_output = ""
+  for line in box_input.splitlines():
+      try:
+        if line.startswith('http://'):
+          box_output += toControlTag(line)
+        elif line.startswith('https://'):
+          box_output += toControlTag(line)
+        else:
+          box_output += line
+      except:
+        box_output += line
+      finally:
+        box_output += '\n'
+  preview_output = toView(box_output);
+  trace = ""
+  html = open('mixitagmaker.html').read()
+  html = html.replace('$box_input', box_input)
+  html = html.replace('$box_output', box_output)
+  html = html.replace('$preview_output', preview_output)
+  html = html.replace('$proc', proc)
+  html = html.replace('$trace', str(trace))
+  response.out.write(html)
+
+def toView(str):
+  str = cgi.escape(str)
+  ret = ""
+  for s in str.splitlines():
+    ret += s
+    ret += '<br>'
+  return ret
+
+#--------------------------------------------------------------------------------------------------
+# getQuery
+#--------------------------------------------------------------------------------------------------
+def getQuery(str):
+  ret = {}
+  params = str.split('&')
+  for param in params:
+    ss = param.split('=', 1)
+    ret[ss[0]]=ss[1]
+
+  return ret
+
+#--------------------------------------------------------------------------------------------------
+# getLastPath
+#--------------------------------------------------------------------------------------------------
+def getLastPath(str):
+  list = str.split('/')
+  list.reverse()
+  return list[0]
+
+#--------------------------------------------------------------------------------------------------
+# toControlTag
+#--------------------------------------------------------------------------------------------------
+def toControlTag(url):
+  type = ""
+  id = ""
+  p = urlparse(url)
+  site = str(p.netloc)
+  if site == 'www.youtube.com' or site == 'm.youtube.com':
+    type = "YT"
+    id = getQuery(p.query)['v']
+  elif site == 'www.nicovideo.jp' or site == 'm.nicovideo.jp':
+    type = "NC"
+    id = getLastPath(p.path)
+  ret = '<externalvideo src="' + type + ':' + id +  '">'
+  return ret
+
+#--------------------------------------------------------------------------------------------------
+# entry method
+#--------------------------------------------------------------------------------------------------
+def main():
+  application = webapp.WSGIApplication([('/mixitagmaker/get/', MainHandlerByGet),
+                                        ('/mixitagmaker/post/', MainHandlerByPost)
+                                       ],
+                                       debug=True)
+  util.run_wsgi_app(application)
+
+
+#--------------------------------------------------------------------------------------------------
+# entry point
+#--------------------------------------------------------------------------------------------------
+if __name__ == '__main__':
+  main()
+#!/usr/bin/env python
+# coding=UTF-8
+# Copyright 2007 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+import cgi
+import urllib
+import xml.etree.ElementTree as tree
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import util
+from google.appengine.api import urlfetch
+from xml.sax.saxutils import escape
+
+#--------------------------------------------------------------------------------------------------
+# entry class
+#--------------------------------------------------------------------------------------------------
+class MainHandler(webapp.RequestHandler):
+
+  def get(self):
+    USE_TUNEIN=True
+
+    f=cgi.FieldStorage();
+    title='testshout libraplanet-gea'
+    keyword=urllib.quote(f.getfirst('search', '').strip());
+
+    server = 'yp.shoutcast.com'
+    target = 'http://' + server + '/sbin/newxml.phtml?'
+    query = {'search':keyword}
+    url = target + urllib.urlencode(query)
+    blank= '&nbsp;'
+
+    if keyword != "":
+      xml = urlfetch.fetch(url).content
+      dom = tree.fromstring(xml)
+      if USE_TUNEIN:
+        tunein = 'http://' + server + dom.findall('tunein')[0].get('base')
+      else:
+        tunein = 'http://yp.shoutcast.com/sbin/shoutcast-playlist.pls'
+      list = dom.findall('station')
+    else:
+      list = []
+      tunein = 'http://yp.shoutcast.com/sbin/shoutcast-playlist.pls'
+
+    self.response.out.write('<html>\n')
+    self.response.out.write('	<head>\n')
+    self.response.out.write('		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n')
+    self.response.out.write('		<title>' + title + '</title>\n')
+    self.response.out.write('	</head>\n')
+    self.response.out.write('	<body>\n')
+    self.response.out.write('		<h1>SHOUTcast検索</h1>\n')
+    self.response.out.write('		<h3>sakuSHOUT for Google App Engine at python.</h3>\n')
+    self.response.out.write('		<form action="./" method="GET">\n')
+    self.response.out.write('			検索キーワード<input type="text" name="search" value="' + urllib.unquote(keyword) + '" size="30"><input type="submit" value="search!"><br>\n')
+    self.response.out.write('			<a href="' + url + '" target="_blank">' + url + '</a>\n')
+    self.response.out.write('		</form>\n')
+
+    for elements in list:
+      self.response.out.write('		<table border="1">\n')
+      if False:
+        #debug code
+        self.response.out.write('			<tr>\n')
+        self.response.out.write('				<td> ' + blank + 'debug' + '</td>\n')
+        self.response.out.write('				<td> ' + blank + escape(str(elements)) + '</td>\n')
+        self.response.out.write('			</tr>\n')
+        self.response.out.write('			<tr>\n')
+      self.response.out.write('				<td> ' + blank + '名' + '</td>\n')
+      self.response.out.write('				<td> ' + blank + elements.get('name', '') + '</td>\n')
+      self.response.out.write('			</tr>\n')
+      self.response.out.write('			<tr>\n')
+      self.response.out.write('				<td> ' + blank + 'MimeType' + '</td>\n')
+      self.response.out.write('				<td> ' + blank + elements.get('mt', '') + '</td>\n')
+      self.response.out.write('			</tr>\n')
+      self.response.out.write('			<tr>\n')
+      self.response.out.write('				<td> ' + blank + 'ジャンル' + '</td>\n')
+      self.response.out.write('				<td> ' + blank + elements.get('genre', '') + '</td>\n')
+      self.response.out.write('			</tr>\n')
+      self.response.out.write('			<tr>\n')
+      self.response.out.write('				<td> ' + blank + 'Now Playing' + '</td>\n')
+      self.response.out.write('				<td> ' + blank + elements.get('ct', '') + '</td>\n')
+      self.response.out.write('			</tr>\n')
+      self.response.out.write('			<tr>\n')
+      self.response.out.write('				<td> ' + blank + 'ダウンロードリンク' + '</td>\n')
+      if USE_TUNEIN:
+        self.response.out.write('				<td> <a href="' + tunein + '?id=' + elements.get('id', '') + '">tune!</a>\n')
+      else:
+        self.response.out.write('				<td> <a href="' + tunein + '?rn=' + elements.get('id', '') + '&file=filename.pls">tune!</a>\n')
+      self.response.out.write('			</tr>\n')
+      self.response.out.write('			<tr>\n')
+      self.response.out.write('		</table>\n')
+
+    self.response.out.write('	</body>\n')
+    self.response.out.write('</html>\n')
+
+#--------------------------------------------------------------------------------------------------
+# entry method
+#--------------------------------------------------------------------------------------------------
+def main():
+  application = webapp.WSGIApplication([('/shoutcast/', MainHandler)],
+                                       debug=True)
+  util.run_wsgi_app(application)
+
+#--------------------------------------------------------------------------------------------------
+# entry point
+#--------------------------------------------------------------------------------------------------
+if __name__ == '__main__':
+  main()