Le 26/08/2011 10:54, Martin Hamant a écrit :
> Hi romain,
>
> Le 17/08/2011 02:11, Romain Beauxis a écrit :
>>> add_timeout + http.get + insert_metadata :-)
>>> Something like this:
>>>
>>> # A source
>>> s = (...)
>>>
>>> # Attach metadata insertion hooks
>>> x = insert_metadata(s)
>>> insert = fst(x)
>>> s = snd(x)
>>>
>>> # A reference to the latest metadata
>>> latest_meta = ref []
>>>
>>> # A function to update metadata
>>> def update_meta() =
>>>   data = http.get(...)
>>>   m = (..parse data here..)
>>>   if m != !latest_meta then
>>>     latest_meta := m
>>>     insert_metadata(m)
>> Shut, sorry you should have read this for the previous line:
>>        insert(m)
>>
>>>   end
>>>   # Restart in 10. seconds
>>>   10.
>>> end
>>>
>>> # Start polling now
>>> add_timeout(0., update_meta)
>>>
>>> I have not tested this code but I think it should be close to working
>>> and also close to what you describe :-
>
> Yes ! It's close to working but I have questions:
> I wrote this code:
>
> (...)
>     s0 =
>     if source_device == "pulse" then
>           input.pulseaudio(client='#{stream_name}')
>     else
>         input.alsa(device="#{source_device}")
>     end
>
>     # Attach metadata insertion hooks
>     x = insert_metadata(s0)
>     insert = fst(x)
>     s = snd(x)
>
>     # A reference to the latest metadata
>     latest_meta = ref []
>
>     # A function to update metadata
>     def update_meta() =
>       data = http.get("http://myserver.com/titles";)
>         # debug
>       print(snd(data))
>       m = snd(data)
>       if m != !latest_meta then
>         latest_meta := m
>         insert(m)
>       end
>       # Restart in 10. seconds
>       10.
>     end
>
>     # Start polling now
>     add_timeout(0., update_meta)
>
> Of course there is a type error at  "if m != !latest_meta" , because I 
> have a string vs a [] ...
> Then I understand that in insert(m), m should be a [], and that's why 
> you wrote lastest_meta = ref []
>
> So, How do I convert my string m to something like [] ?

I was totally far from it.
Found the trick !


     x = insert_metadata(s0)
     insert = fst(x)
     s = snd(x)

     # A reference to the latest metadata
     latest_meta = ref []

     # A function to update metadata
     def update_meta() =
       data = http.get("bla/titles")
        m = [("title", snd(data))] # <= this is the right type of m !!
       if m != !latest_meta then
         latest_meta := m
         insert(m)
         print("new metadata !")
       end
       # Restart in 10. seconds
       10.
     end

     # Start polling now
     add_timeout(0., update_meta)

:D

------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to