<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libmtp: getplaylist.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>getplaylist.c</h1><div class="fragment"><pre class="fragment"> <span class="preprocessor">#include "common.h"</span> <span class="preprocessor">#include <stdlib.h></span> <span class="preprocessor">#include <limits.h></span> <span class="keyword">static</span> uint32_t dump_playlist(<a name="_a0"></a><a class="code" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> *device, <a name="_a1"></a><a class="code" href="structLIBMTP__playlist__struct.html">LIBMTP_playlist_t</a> *pl) { uint32_t i; printf(<span class="stringliteral">"Number of items: %u\n"</span>, pl-><a name="a2"></a><a class="code" href="structLIBMTP__playlist__struct.html#a868f74d17f319549b7e14d9f95826c6f">no_tracks</a>); <span class="keywordflow">if</span>(pl-><a class="code" href="structLIBMTP__playlist__struct.html#a868f74d17f319549b7e14d9f95826c6f">no_tracks</a> > 0) { <span class="keywordflow">for</span>(i=0;i<pl-><a class="code" href="structLIBMTP__playlist__struct.html#a868f74d17f319549b7e14d9f95826c6f">no_tracks</a>;i++) { <a name="_a3"></a><a class="code" href="structLIBMTP__track__struct.html">LIBMTP_track_t</a> *track; track = <a name="a4"></a><a class="code" href="group__tracks.html#ga93aaa8ce0db15dff891a4e0c8e5fd094">LIBMTP_Get_Trackmetadata</a>(device, pl-><a name="a5"></a><a class="code" href="structLIBMTP__playlist__struct.html#aaa520f5654349df19e4be8cf6f96a6f7">tracks</a>[i]); <span class="keywordflow">if</span> (track != NULL) { printf(<span class="stringliteral">" %u: %s - %s\n"</span>, pl-><a class="code" href="structLIBMTP__playlist__struct.html#aaa520f5654349df19e4be8cf6f96a6f7">tracks</a>[i], track-><a name="a6"></a><a class="code" href="structLIBMTP__track__struct.html#ae0706099f555fa7a36d55f7d7afce45b">artist</a>, track-><a name="a7"></a><a class="code" href="structLIBMTP__track__struct.html#a08f9a52cac093232f14543bbd87d586d">title</a>); <a name="a8"></a><a class="code" href="group__tracks.html#gafeb0d51f0d25ef2389b786f8d319e88f">LIBMTP_destroy_track_t</a>(track); } <span class="keywordflow">else</span> { printf(<span class="stringliteral">" %u: INVALID TRACK REFERENCE!\n"</span>, pl-><a class="code" href="structLIBMTP__playlist__struct.html#aaa520f5654349df19e4be8cf6f96a6f7">tracks</a>[i]); <a name="a9"></a><a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device); <a name="a10"></a><a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device); } } } <span class="keywordflow">return</span> 0; } <span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <a class="code" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> *device; <a class="code" href="structLIBMTP__playlist__struct.html">LIBMTP_playlist_t</a> *playlist; uint32_t id; <span class="keywordtype">char</span> *endptr; fprintf(stdout, <span class="stringliteral">"libmtp version: "</span> LIBMTP_VERSION_STRING <span class="stringliteral">"\n\n"</span>); <span class="comment">// We need file ID</span> <span class="keywordflow">if</span> ( argc != 2 ) { fprintf(stderr, <span class="stringliteral">"Just a playlist ID is required\n"</span>); <span class="keywordflow">return</span> 1; } <span class="comment">// Sanity check playlist ID</span> <span class="keywordtype">id</span> = strtoul(argv[1], &endptr, 10); <span class="keywordflow">if</span> ( *endptr != 0 ) { fprintf(stderr, <span class="stringliteral">"illegal value %s\n"</span>, argv[1]); <span class="keywordflow">return</span> 1; } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ! <span class="keywordtype">id</span> ) { fprintf(stderr, <span class="stringliteral">"bad playlist id %u\n"</span>, <span class="keywordtype">id</span>); <span class="keywordflow">return</span> 1; } <a name="a11"></a><a class="code" href="group__internals.html#gaaca880ea9ab434e8cf1a1051128318ef">LIBMTP_Init</a>(); device = <a name="a12"></a><a class="code" href="group__basic.html#gacd19150fce8688a56746c5b4e57be3ff">LIBMTP_Get_First_Device</a>(); <span class="keywordflow">if</span> (device == NULL) { printf(<span class="stringliteral">"No devices. Connect/replug device and try again.\n"</span>); exit (0); } playlist = <a name="a13"></a><a class="code" href="group__playlists.html#ga463909ddaa9e0e26055aa21f4d895598">LIBMTP_Get_Playlist</a>(device,<span class="keywordtype">id</span>); <span class="keywordflow">if</span> (playlist != NULL) { dump_playlist(device,playlist); } <a name="a14"></a><a class="code" href="group__playlists.html#ga8d6ce37c43c3cbbac49de849d8aafe77">LIBMTP_destroy_playlist_t</a>(playlist); <a name="a15"></a><a class="code" href="group__basic.html#ga55377eb5a8ff6ce2b1a557356fe12039">LIBMTP_Release_Device</a>(device); printf(<span class="stringliteral">"OK.\n"</span>); exit (0); } </pre></div> </div> <hr size="1"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> </body> </html>