Changeset 879d772


Ignore:
Timestamp:
May 18, 2007 9:17:37 PM (8 years ago)
Author:
olivier <>
Branches:
master, crem, crem2, crem3, dev, dev2, diadems, dj1.6, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, forma, generic, instru_search, lam, lam2, mapsv3, merge, nlivemulti, production, release/1.4.4, sabiod, search, security, server, social, storage, telecaster, test, video
Children:
294e691
Parents:
3815c51
git-author:
olivier <> (18/05/2007 21:17:37)
git-committer:
olivier <> (18/05/2007 21:17:37)
Message:
  • added collection playlists in m3u and xspf formats
  • embedded flash mp3 player in both collection and item displays.

Remark: there are two players available, you can switch them in the templates

  • other fixes
Location:
telemeta
Files:
8 added
8 edited

Legend:

Unmodified
Added
Removed
  • telemeta/htdocs/css/telemeta.css

    r3815c51 r879d772  
    3737#quick_search_pattern { } 
    3838 
    39 .item_visualization { 
     39.item_visualization, #collection_player { 
    4040  clear: right; 
    4141  float: right; 
    4242  padding: 1ex; 
    4343  margin-top: 1em; 
     44  margin-left: 1em; 
    4445} 
    4546.item_visualization select { width: 200px; } 
    4647.item_visualization img { width: 300px; border: solid 1px black; } 
    47  
    4848 
    4949/* Styles for tabular listings (stolen from trac) */ 
  • telemeta/models.py

    r3815c51 r879d772  
    1212from django.core.exceptions import ObjectDoesNotExist 
    1313from django.core import validators 
     14from django.conf import settings 
    1415 
    1516import telemeta 
     
    128129        return resource 
    129130 
     131    def has_mediafile(self): 
     132        "Tell wether this collection has any media files attached to its items" 
     133        items = self.items.all() 
     134        for item in items: 
     135            if item.file: 
     136                return True 
     137        return False 
     138 
    130139    def __str__(self): 
    131140        #return self.title 
     
    216225        return resource 
    217226 
     227    def get_duration(self): 
     228        if self.file: 
     229            import wave 
     230            media = wave.open(settings.MEDIA_ROOT + "/" + self.file, "rb") 
     231            duration = media.getnframes() / media.getframerate() 
     232            media.close() 
     233        else: 
     234            duration = 0 
     235 
     236        return duration 
     237 
    218238    def __str__(self): 
    219239        return self.title 
  • telemeta/templates/base.html

    r3815c51 r879d772  
    55<link rel="stylesheet" type="text/css" href="/css/telemeta.css" /> 
    66{% block extra_style %}{% endblock %} 
     7{% block extra_javascript %}{% endblock %} 
    78</head> 
    89{% load i18n %} 
  • telemeta/templates/collection_detail.html

    r01bf9f7 r879d772  
    11{% extends "base.html" %} 
    22{% load telemeta_utils %} 
     3 
     4{% block extra_javascript %} 
     5<script src="/js/swfobject.js" type="text/javascript"></script> 
     6{% endblock %} 
    37 
    48{% block submenu %} 
     
    913{% block content %} 
    1014{% if object %} 
     15    {% if object.has_mediafile %} 
     16    <div id="collection_player"> 
     17      <p><b>Listen to this collection</b> 
     18      (<a href="{% url telemeta-collection-m3u object.id|urlencode %}">M3U</a>, 
     19      <a href="{% url telemeta-collection-xspf object.id|urlencode %}">XSPF</a>)</p> 
     20      {% if 0 %} {# Use 1/0 for alternate player #} 
     21        <!-- This is the XSPF Web Music Player, under the BSD license,  
     22          from: http://musicplayer.sourceforge.net/--> 
     23        <object type="application/x-shockwave-flash" width="300" height="200" 
     24          data="/swf/xspf_player.swf?playlist_url={% url telemeta-collection-xspf object.id|urlencode %}"> 
     25          <param name="movie"  
     26            value="/swf/xspf_player.swf?playlist_url={% url telemeta-collection-xspf object.id|urlencode %}" /> 
     27        </object> 
     28      {% else %} 
     29        <!-- This is Jeroen Wijering's Flash MP3 Player,  
     30          under CC Attribution-NonCommercial-ShareAlike 2.0 license 
     31          from: http://www.jeroenwijering.com/?item=Flash_MP3_Player--> 
     32        <p id="collection_player_c"> 
     33          <a href="http://www.macromedia.com/go/getflashplayer">Get Flash</a> to see this player. 
     34        </p> 
     35        <script type="text/javascript"> 
     36          var so = new SWFObject('/swf/mp3player.swf','playlist','300','200','7'); 
     37          so.addVariable("file","{% url telemeta-collection-xspf object.id|urlencode %}"); 
     38          so.addVariable("displayheight","0"); 
     39          so.write('collection_player_c'); 
     40        </script>  
     41      {% endif %} 
     42    </div>       
     43    {% endif %} 
     44 
    1145    <h3>Collection: {{ object.title }}</h3> 
    1246    <ul> 
     
    1953    {% endfor %} 
    2054    </ul> 
     55 
    2156    <hr> 
    2257    <h4>Items</h4> 
    23     <ul> 
    24     {% for item in object.items.all %} 
    25         <li><b>{{ item.creator }}</b> - {{ item.title }} 
    26             <a href="{% url telemeta-item-detail item.id|urlencode %}">View</a> 
    27             <a href="#">Edit</a> 
    28             </li> 
    29     {% endfor %} 
    30     </ul> 
     58    {% with object.items.all as items %} 
     59    {% if items %} 
     60      <ul> 
     61      {% for item in items %} 
     62          <li><b>{{ item.creator }}</b> - {{ item.title }} 
     63              <a href="{% url telemeta-item-detail item.id|urlencode %}">View</a> 
     64              <a href="#">Edit</a> 
     65              </li> 
     66      {% endfor %} 
     67      </ul> 
     68    {% else %} 
     69      <p>No items</p> 
     70    {% endif %} 
     71    {% endwith %} 
    3172{% else %} 
    3273    <p>No such collection</p> 
  • telemeta/templates/mediaitem_detail.html

    r01bf9f7 r879d772  
    11{% extends "base.html" %} 
    22{% load telemeta_utils %} 
     3 
     4{% block extra_javascript %} 
     5<script src="/js/swfobject.js" type="text/javascript"></script> 
     6{% endblock %} 
    37 
    48{% block submenu %} 
     
    913{% block content %} 
    1014{% if item %} 
     15  {% if item.file %}   
    1116    <div class="item_visualization"> 
     17      {% if 0 %} {# Use 1/0 for alternate player #} 
     18        <!-- This is the XSPF Web Music Player, under the BSD license,  
     19          from: http://musicplayer.sourceforge.net/--> 
     20        <object type="application/x-shockwave-flash" width="300" height="20" 
     21          data="/swf/xspf_player_slim.swf?playlist_url={% url telemeta-item-xspf item.id|urlencode %}"> 
     22          <param name="movie"  
     23            value="/swf/xspf_player_slim.swf?playlist_url={% url telemeta-item-xspf item.id|urlencode %}" /> 
     24        </object><br/> 
     25      {% else %}       
     26        <!-- This is Jeroen Wijering's Flash MP3 Player,  
     27          under CC Attribution-NonCommercial-ShareAlike 2.0 license 
     28          from: http://www.jeroenwijering.com/?item=Flash_MP3_Player--> 
     29        <p id="item_player_c"> 
     30          <a href="http://www.macromedia.com/go/getflashplayer">Get Flash</a> to see this player. 
     31        </p> 
     32        <script type="text/javascript"> 
     33          var so = new SWFObject('/swf/mp3player.swf','line','300','20','7'); 
     34          so.addVariable("file","{% url telemeta-item-export item.id|urlencode,"MP3" %}"); 
     35          so.addVariable("type","mp3"); 
     36          so.write('item_player_c'); 
     37        </script> 
     38      {% endif %} 
     39 
    1240      <img src="{% url telemeta-item-visualize item.id|urlencode,visualizer_id %}"> 
    1341      <form method="GET"> 
     
    2149      </form> 
    2250    </div> 
    23     <h3>Item: {{ item.title }}</h3> 
    24     <ul> 
    25     {% for field in item.to_dict|tolist %} 
    26         {% ifnotequal field.name "id" %} 
    27         {% ifnotequal field.name "title" %} 
    28         {% ifnotequal field.name "file" %} 
     51  {% endif %}     
    2952 
    30         <li><b>{{ field.name }}</b> :  
    31             {% ifequal field.name "collection" %} 
    32             <a href="{% url telemeta-collection-detail field.value.id|urlencode %}"> 
    33                 {{ field.value }}</a> 
    34             {% else %} 
    35             {{ field.value }} 
    36             {% endifequal %} 
    37             </li> 
     53  <h3>Item: {{ item.title }}</h3> 
     54  <ul> 
     55  {% for field in item.to_dict|tolist %} 
     56      {% ifnotequal field.name "id" %} 
     57      {% ifnotequal field.name "title" %} 
     58      {% ifnotequal field.name "file" %} 
    3859 
    39         {% endifnotequal %} 
    40         {% endifnotequal %} 
    41         {% endifnotequal %} 
    42     {% endfor %} 
    43     </ul> 
    44     Download: 
    45     {% for format in export_formats %} 
    46         <a href="{% url telemeta-item-export item.id|urlencode,format %}">{{ format }}</a> 
    47     {% endfor %} 
     60      <li><b>{{ field.name }}</b> :  
     61          {% ifequal field.name "collection" %} 
     62          <a href="{% url telemeta-collection-detail field.value.id|urlencode %}"> 
     63              {{ field.value }}</a> 
     64          {% else %} 
     65          {{ field.value }} 
     66          {% endifequal %} 
     67          </li> 
     68 
     69      {% endifnotequal %} 
     70      {% endifnotequal %} 
     71      {% endifnotequal %} 
     72  {% endfor %} 
     73  </ul> 
     74  Download: 
     75  {% for format in export_formats %} 
     76      <a href="{% url telemeta-item-export item.id|urlencode,format %}">{{ format }}</a> 
     77  {% endfor %} 
    4878{% else %} 
    4979    <p>No such item</p> 
  • telemeta/templatetags/telemeta_utils.py

    r01bf9f7 r879d772  
    1717    return list         
    1818 
     19@register.filter 
     20def mul(value, arg): 
     21    "Multiply a numeric value" 
     22    return value * arg         
    1923 
     24 
  • telemeta/urls.py

    r3815c51 r879d772  
    4040        {'format': 'dublin_core_xml'}, 
    4141        name="telemeta-item-dublincore-xml"), 
    42     url(r'^items/(?P<item_id>' + i_ex + ')/download/(?P<format>[0-9A-Z]+)/$',  
     42    url(r'^items/(?P<item_id>' + i_ex + ')/download.(?P<format>[0-9A-Z]+)$',  
    4343        web_view.item_export, 
    4444        name="telemeta-item-export"), 
     
    4646        web_view.item_visualize, 
    4747        name="telemeta-item-visualize"), 
     48    url(r'^items/(?P<item_id>' + i_ex + ')/item_xspf.xml$',  
     49        web_view.item_playlist,  
     50        dict(template="mediaitem_xspf.xml", mimetype="application/xspf+xml"), 
     51        name="telemeta-item-xspf"), 
    4852 
    4953    # collections 
     
    6367        dict(all_collections, template_name="collection_detail_dc.html"), 
    6468        name="telemeta-collection-dublincore"), 
     69    url(r'^collections/(?P<collection_id>' + c_ex + ')/collection_xspf.xml$',  
     70        web_view.collection_playlist,  
     71        dict(template="collection_xspf.xml", mimetype="application/xspf+xml"), 
     72        name="telemeta-collection-xspf"), 
     73    url(r'^collections/(?P<collection_id>' + c_ex + ')/collection.m3u$', 
     74        web_view.collection_playlist,  
     75        dict(template="collection.m3u", mimetype="audio/mpegurl"), 
     76        name="telemeta-collection-m3u"), 
    6577 
    6678    # search 
     
    94106    (r'^images/(?P<path>.*)$', 'django.views.static.serve',  
    95107        {'document_root': './telemeta/htdocs/images'}), 
     108    (r'^js/(?P<path>.*)$', 'django.views.static.serve',  
     109        {'document_root': './telemeta/htdocs/js'}), 
     110    (r'^swf/(?P<path>.*)$', 'django.views.static.serve',  
     111        {'document_root': './telemeta/htdocs/swf'}), 
    96112) 
  • telemeta/views/web.py

    r3815c51 r879d772  
    191191 
    192192        return self.edit_enumeration(request, enumeration_id) 
    193  
    194          
    195      
    196      
    197  
    198      
     193   
     194    def collection_playlist(self, request, collection_id, template, mimetype): 
     195        collection = MediaCollection.objects.get(id__exact=collection_id) 
     196        if not collection: 
     197            raise Http404 
     198 
     199        template = loader.get_template(template) 
     200        context = Context({'collection': collection, 'host': request.META['HTTP_HOST']}) 
     201        return HttpResponse(template.render(context), mimetype=mimetype) 
     202 
     203    def item_playlist(self, request, item_id, template, mimetype): 
     204        item = MediaItem.objects.get(id__exact=item_id) 
     205        if not item: 
     206            raise Http404 
     207 
     208        template = loader.get_template(template) 
     209        context = Context({'item': item, 'host': request.META['HTTP_HOST']}) 
     210        return HttpResponse(template.render(context), mimetype=mimetype) 
     211 
     212         
     213     
     214     
     215 
     216     
Note: See TracChangeset for help on using the changeset viewer.