Attachment 'YouTube-0.5.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 u"""
   3     MoinMoin - YouTube macro Version 0.5
   4                Displays an embedded object with the wanted video or
   5                displays a list of videos (videobar).
   6 
   7     <<YouTube(id="YouTubeID", keyword="keyword")>>
   8     Default is to use the current pagename as keyword.
   9 
  10     Examples:
  11      * <<YouTube>>
  12      * <<YouTube(id=2SXKM-dLJV8)>>
  13      * <<YouTube(keyword="iron maiden")>>
  14 
  15     @copyright: 2008 by MarcelHäfner (http://moinmo.in/MarcelHäfner),
  16                 2010 by ThomasWaldmann (http://moinmo.in/ThomasWaldmann)
  17     @license: GNU GPL, see COPYING for details.
  18 
  19     Attention! The "keyword" part is created with the "Google AJAX Search API Tools".
  20     Licence Information can be viewed under: http://code.google.com/intl/de-DE/apis/ajaxsearch/terms.html
  21 
  22     @TODO:
  23      * Change the hardcoded https string into http/https depending on the requested url.
  24      * Don't use the google ajax stuff.
  25      * Check if youtube videos are disabled (mimetypes_xss).
  26 
  27 """
  28 
  29 from MoinMoin import wikiutil
  30 
  31 
  32 def macro_YouTube(macro, id, keyword):
  33     request = macro.request
  34     _ = request.getText
  35     html = u""
  36 
  37     if id is None and keyword is None:
  38         # default: keyword will be used and default to current page name
  39         keyword = macro.formatter.page.page_name
  40 
  41     if keyword is not None:
  42         # for the videobar to display the flash videos (keyword)
  43         parameters = {
  44             "keyword":  wikiutil.escape(keyword),
  45             "msg_youtubelink": _("View the related videos on YouTube."),
  46         }
  47         html = u"""
  48         <div class="youtube youtube_keyword">
  49             <!-- ++Begin Video Bar Wizard Generated Code++ -->
  50               <!--
  51               // Created with a Google AJAX Search Wizard
  52               // http://code.google.com/apis/ajaxsearch/wizards.html
  53               -->
  54 
  55               <!--
  56               // The Following div element will end up holding the actual videobar.
  57               // You can place this anywhere on your page.
  58               -->
  59               <div id="videoBar-bar">
  60                 <span style="color:#676767;font-size:11px;margin:10px;padding:4px;">Loading...</span>
  61               </div>
  62 
  63               <!-- Ajax Search Api and Stylesheet
  64               // Note: If you are already using the AJAX Search API, then do not include it
  65               //       or its stylesheet again.
  66               -->
  67               <script src="https://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-vbw"
  68                 type="text/javascript"></script>
  69               <style type="text/css">
  70                 @import url("https://www.google.com/uds/css/gsearch.css");
  71               </style>
  72 
  73               <!-- Video Bar Code and Stylesheet -->
  74               <script type="text/javascript">
  75                 window._uds_vbw_donotrepair = true;
  76               </script>
  77               <script src="https://www.google.com/uds/solutions/videobar/gsvideobar.js?mode=new"
  78                 type="text/javascript"></script>
  79               <style type="text/css">
  80                 @import url("https://www.google.com/uds/solutions/videobar/gsvideobar.css");
  81               </style>
  82 
  83               <style type="text/css">
  84                 .playerInnerBox_gsvb .player_gsvb {
  85                   width : 320px;
  86                   height : 260px;
  87                 }
  88               </style>
  89               <script type="text/javascript">
  90                 function LoadVideoBar() {
  91 
  92                 var videoBar;
  93                 var options = {
  94                     largeResultSet : !true,
  95                     horizontal : true,
  96                     autoExecuteList : {
  97                       cycleTime : GSvideoBar.CYCLE_TIME_MEDIUM,
  98                       cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
  99                       executeList : ["%(keyword)s"]
 100                     }
 101                   }
 102 
 103                 videoBar = new GSvideoBar(document.getElementById("videoBar-bar"),
 104                                           GSvideoBar.PLAYER_ROOT_FLOATING,
 105                                           options);
 106                 }
 107                 // arrange for this function to be called during body.onload
 108                 // event processing
 109                 GSearch.setOnLoadCallback(LoadVideoBar);
 110               </script>
 111             <!-- ++End Video Bar Wizard Generated Code++ -->
 112             <p class="youtube_link" style="display:none;">
 113                 <a href="http://www.youtube.com/results?search_query=%(keyword)s">%(msg_youtubelink)s</a>
 114             </p>
 115         </div>
 116         """ % parameters
 117 
 118     if id is not None:
 119         # for the embedded flashplayer to play a single video (id)
 120         parameters = {
 121             "id":  wikiutil.escape(id),
 122             "msg_youtubelink": _("View the video on YouTube."),
 123         }
 124         html = u"""
 125         <div class="youtube youtube_id">
 126 
 127             <object width="425" height="344">
 128                 <param name="movie" value="http://www.youtube.com/v/%(id)s&rel=0&fs=1"></param>
 129                 <param name="rel" value="0"></param>
 130                 <param name="allowFullScreen" value="true"></param>
 131                 <embed src="http://www.youtube.com/v/%(id)s&fs=1&rel=0"
 132                     type="application/x-shockwave-flash"
 133                     allowfullscreen="true"
 134                     rel="false"
 135                     width="425" height="344">
 136                 </embed>
 137             </object>
 138 
 139             <p class="youtube_link" style="display:none;">
 140                 <a href="http://www.youtube.com/v/%(id)s&fs=1&rel=0">%(msg_youtubelink)s</a>
 141             </p>
 142 
 143         </div>
 144         """ % parameters
 145 
 146     return macro.formatter.rawHTML(html)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-11-30 17:28:46, 0.8 KB) [[attachment:YouTube-0.0.2.py]]
  • [get | view] (2009-10-18 15:05:59, 5.2 KB) [[attachment:YouTube-0.4.py]]
  • [get | view] (2010-05-19 21:23:36, 5.5 KB) [[attachment:YouTube-0.5.py]]
  • [get | view] (2011-01-29 10:49:40, 5.6 KB) [[attachment:YouTube-0.6.py]]
  • [get | view] (2009-10-18 15:06:13, 175.1 KB) [[attachment:youtube_singlevideo.png]]
  • [get | view] (2009-10-18 15:18:09, 299.2 KB) [[attachment:youtube_videobar.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.