]> git.sesse.net Git - vlc/commitdiff
Preliminary album art support code for the HTTP interface.
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 19 Aug 2007 14:11:50 +0000 (14:11 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 19 Aug 2007 14:11:50 +0000 (14:11 +0000)
modules/control/http/http.c
share/http/dialogs/main
share/http/js/functions.js

index c1fe71ec1eaa85d2b73d5f505ab4fbe338e6202c..4b01b21eec186a00a191d0f2090c24df283f667b 100644 (file)
@@ -82,6 +82,12 @@ vlc_module_end();
  * Local prototypes
  *****************************************************************************/
 static void Run          ( intf_thread_t *p_intf );
+int  E_(ArtCallback)( httpd_handler_sys_t *p_args,
+                          httpd_handler_t *p_handler, char *_p_url,
+                          uint8_t *_p_request, int i_type,
+                          uint8_t *_p_in, int i_in,
+                          char *psz_remote_addr, char *psz_remote_host,
+                          uint8_t **pp_data, int *pi_data );
 
 /*****************************************************************************
  * Local functions
@@ -338,6 +344,21 @@ static int Open( vlc_object_t *p_this )
 
     E_(ParseDirectory)( p_intf, psz_src, psz_src );
 
+    /* FIXME: we're leaking h */
+    httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) );
+    if( !h )
+    {
+        msg_Err( p_intf, "not enough memory to allocate album art handler" );
+        goto failed;
+    }
+    h->file.p_intf = p_intf;
+    h->file.file = NULL;
+    h->file.name = NULL;
+    /* TODO: use ACL and login/password stuff here too */
+    h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
+                                     "/art", NULL, NULL, NULL,
+                                     E_(ArtCallback), h );
+    TAB_APPEND( p_sys->i_handlers, p_sys->pp_handlers, h->p_handler );
 
     if( p_sys->i_files <= 0 )
     {
@@ -892,3 +913,68 @@ int  E_(HandlerCallback)( httpd_handler_sys_t *p_args,
 
     return VLC_SUCCESS;
 }
+
+int  E_(ArtCallback)( httpd_handler_sys_t *p_args,
+                          httpd_handler_t *p_handler, char *_p_url,
+                          uint8_t *_p_request, int i_type,
+                          uint8_t *_p_in, int i_in,
+                          char *psz_remote_addr, char *psz_remote_host,
+                          uint8_t **pp_data, int *pi_data )
+{
+    uint8_t *p_data = NULL;
+    int i_data = 0;
+    char *psz_art = NULL;
+    intf_thread_t *p_intf = p_args->file.p_intf;
+    intf_sys_t *p_sys = p_intf->p_sys;
+
+    if( p_sys->p_input )
+    {
+        psz_art = input_item_GetArtURL( input_GetItem( p_sys->p_input ) );
+    }
+
+    if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) )
+    {
+        FILE *f;
+        char *psz_ext;
+        char *psz_header;
+        int i_header_size;
+
+        if( ( f = utf8_fopen( psz_art + strlen( "file://" ), "r" ) ) == NULL )
+        {
+            msg_Dbg( p_intf, "Couldn't open album art file %s",
+                     psz_art + strlen( "file://" ) );
+            Callback404( &p_args->file, (char**)pp_data, pi_data );
+            free( psz_art );
+            return VLC_SUCCESS;
+        }
+
+        E_(FileLoad)( f, &p_data, &i_data );
+
+        fclose( f );
+
+        psz_ext = strrchr( psz_art, '.' );
+        if( psz_ext ) psz_ext++;
+
+#define HEADER  "Content-Type: image/%s\n" \
+                "Content-Length: %d\n" \
+                "\n"
+        i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data );
+#undef HEADER
+
+        *pi_data = i_header_size + i_data;
+        *pp_data = (uint8_t*)malloc( *pi_data );
+        memcpy( *pp_data, psz_header, i_header_size );
+        memcpy( *pp_data+i_header_size, p_data, i_data );
+        free( psz_header );
+        free( p_data );
+    }
+    else
+    {
+        msg_Dbg( p_intf, "No album art found" );
+        Callback404( &p_args->file, (char**)pp_data, pi_data );
+    }
+
+    free( psz_art );
+
+    return VLC_SUCCESS;
+}
index 30fde00ef300592c4c06cb4c1b09647baaa57bd4..49086d4d34abb9d608a46abc8c66cf1b1cfc5054 100644 (file)
@@ -106,6 +106,7 @@ sout and playlist .
     <img src="images/slider_left.png" alt="slider left" /><span id="progressbar" style="background-image: url( 'images/slider_bar.png' ); width: 408px; height:16px; position:absolute;" onclick="slider_seek( event, this );" onmousemove="slider_move( event, this );"><img src="images/slider_point.png" alt="slider point" style="position:relative; left:0px;" id="main_slider_point" onmousedown="slider_down( event, this );" onmouseup="slider_up( event, this.parentNode );" onmouseout="slider_up( event, this.parentNode );"/></span><img src="images/slider_right.png" alt="slider right" style="position:relative;left:408px;" />
     <br/>
     <span id="nowplaying">(?)</span>
+    <img id="albumart" alt="Album art" src="/art" style="float: right" onclick="refresh_albumart();"/>
   </div>
 </div>
 
index 5b0eee4576a72b9bb5f847a15ebfdcdaa076eb5f..7f2db21ab2ca17b14aa7b061838b443ceb2b79e7 100644 (file)
@@ -1039,7 +1039,12 @@ function browse_path( p )
     hide( 'browse' );
     document.getElementById( value( 'browse_dest' ) ).focus();
 }
-
+function refresh_albumart()
+{
+    var now = new Date();
+    var albumart = document.getElementById( 'albumart' );
+    albumart.src = '/art?timestamp=' + now.getTime();
+}
 /**********************************************************************
  * Periodically update stuff in the interface
  *********************************************************************/
@@ -1053,9 +1058,15 @@ function loop_refresh_playlist()
     /* setTimeout( 'loop_refresh_playlist()', 10000 ); */
     update_playlist();
 }
+function loop_refresh_albumart()
+{
+    setTimeout( 'loop_refresh_albumart()', 10000 );
+    refresh_albumart();
+}
 function loop_refresh()
 {
     setTimeout( 'loop_refresh_status()', 1 );
     setTimeout( 'loop_refresh_playlist()', 1 );
+    setTimeout( 'loop_refresh_albumart()', 1 );
 }