]> git.parisson.com Git - telemeta.git/commitdiff
Link TM Item with TimeSide Item
authorThomas Fillon <thomas@parisson.com>
Wed, 30 Mar 2016 10:28:19 +0000 (12:28 +0200)
committerThomas Fillon <thomas@parisson.com>
Wed, 30 Mar 2016 10:28:19 +0000 (12:28 +0200)
telemeta/models/item.py
telemeta/templates/telemeta/mediaitem_detail.html
telemeta/views/item.py

index 3345dcee97a6b4a4140fa8551ec1b1480f144d4f..7e084c4d22b5438234f1b211db5b54547ceb20ca 100644 (file)
@@ -193,9 +193,11 @@ class MediaItem(MediaResource):
         source = None
         if self.file and os.path.exists(self.file.path):
             source = self.file.path
+            source_type = 'file'
         elif self.url:
             source = self.url
-        return source
+            source_type = 'url'
+        return source, source_type
 
     @property
     def instruments(self):
index 2fa27eb99a1f4f512f6c7e7d602d107e0d7d7140..0f67a33be64cd0505341b8d2f71ad6630800c740 100644 (file)
     </a>
     {% endblock dublincore %}
 
+    {% block TimeSide %}
+    <a href="{% url "timeside-item-detail" ts_item_id %}">
+      <button type="button" class="btn btn-default" style="float:left;margin-top:0.5em;margin-bottom:1em">
+        TimeSide
+      </button>
+    {% endblock TimeSide %}
+    </a>
+
+
 {% endif %}
 
 
index 7df111b47e4f042c9a82884fc242243fec6f12ed..640a8053333a874de77cf8671ed1d44c1753003e 100644 (file)
@@ -25,6 +25,8 @@
 from telemeta.views.core import *
 from telemeta.views.marker import *
 import timeside.core
+from timeside.server import models as TS_models
+import timeside.server.models as TS_models
 
 
 class ItemBaseMixin(TelemetaBaseMixin):
@@ -35,6 +37,8 @@ class ItemBaseMixin(TelemetaBaseMixin):
     analyzers = timeside.core.processor.processors(timeside.core.api.IAnalyzer)
     value_analyzers = timeside.core.processor.processors(timeside.core.api.IValueAnalyzer)
 
+
+
     export_enabled = getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True)
     export_formats = getattr(settings, 'TELEMETA_DOWNLOAD_FORMATS', ('mp3', 'wav'))
     default_grapher_id = getattr(settings, 'TIMESIDE_DEFAULT_GRAPHER_ID', ('waveform_simple'))
@@ -247,7 +251,7 @@ class ItemView(ItemBaseMixin):
             image_file = old_image_file
 
         if not self.cache_data.exists(image_file):
-            source = item.get_source()
+            source, _ = item.get_source()
             if source:
                 path = self.cache_data.dir + os.sep + image_file
                 decoder = timeside.core.get_processor('file_decoder')(source)
@@ -309,7 +313,7 @@ class ItemView(ItemBaseMixin):
 
         mime_type = encoder.mime_type()
         file = public_id + '.' + encoder.file_extension()
-        source = item.get_source()
+        source, _ = item.get_source()
 
         flag = MediaItemTranscodingFlag.objects.filter(item=item, mime_type=mime_type)
         if not flag:
@@ -605,10 +609,15 @@ class ItemDetailView(ItemViewMixin, DetailView):
             analyzers_sub = []
             graphers_sub = []
 
-            source = item.get_source()
+            source, _ = item.get_source()
+
             if source:
-                decoder  = timeside.core.get_processor('file_decoder')(source)
-                pipe = decoder
+                print '***************************'
+                print source
+                print '***************************'
+
+                decoder = timeside.core.get_processor('file_decoder')(source)
+                pipe = decoder = timeside.core.get_processor('file_decoder')(source)
 
                 for analyzer in self.value_analyzers:
                     subpipe = analyzer()
@@ -694,6 +703,14 @@ class ItemDetailView(ItemViewMixin, DetailView):
 
         previous, next = self.item_previous_next(item)
 
+        # Corresponding TimeSide Item
+        source, source_type = item.get_source()
+        if source:
+            ts_item, c = TS_models.Item.objects.get_or_create(**{source_type: source})
+            if c:
+                ts_item.title = item.title
+                ts_item.save()
+
         self.item_analyze(item)
 
         #FIXME: use mimetypes.guess_type
@@ -731,6 +748,11 @@ class ItemDetailView(ItemViewMixin, DetailView):
         context['format'] = item_format
         context['private_extra_types'] = private_extra_types.values()
         context['site'] = 'http://' + Site.objects.all()[0].name
+        if ts_item:
+            context['ts_item_id'] = ts_item.pk
+        else:
+            context['ts_item_id'] = None
+
         return context