users_dump_rdf.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. include '../nixtape/config.php';
  3. include '../nixtape/database.php';
  4. include '../nixtape/utils/linkeddata.php';
  5. function htmlnumericentities($str)
  6. {
  7. return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
  8. }
  9. $username = $argv[1];
  10. if (! $username)
  11. {
  12. die("Must provide a username.\n");
  13. }
  14. try {
  15. $user = new User($username);
  16. } catch (Exception $e) {
  17. die("No such user.\n");
  18. }
  19. $scrobbles = $user->getScrobbles(10000);
  20. print "<rdf:RDF
  21. xmlns=\"http://purl.org/ontology/mo/\"
  22. xmlns:bio=\"http://purl.org/vocab/bio/0.1/\"
  23. xmlns:dc=\"http://purl.org/dc/terms/\"
  24. xmlns:foaf=\"http://xmlns.com/foaf/0.1/\"
  25. xmlns:gob=\"http://purl.org/ontology/last-fm/\"
  26. xmlns:mo=\"http://purl.org/ontology/mo/\"
  27. xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"
  28. xmlns:sioc=\"http://rdfs.org/sioc/ns#\"
  29. xmlns:rss=\"http://purl.org/rss/1.0/\"
  30. xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
  31. xmlns:geo=\"http://www.w3.org/2003/01/geo/wgs84_pos#\"
  32. xml:lang=\"en\">\n";
  33. while ($s = array_shift($scrobbles))
  34. {
  35. printf("
  36. <gob:ScrobbleEvent rdf:about=\"%s\">
  37. <gob:user rdf:resource=\"%s\" />
  38. <gob:track_played>
  39. <Track rdf:about=\"%s\" dc:title=\"%s\">
  40. <foaf:maker>
  41. <MusicArtist rdf:about=\"%s\" foaf:name=\"%s\" />
  42. </foaf:maker>
  43. </Track>
  44. </gob:track_played>
  45. <dc:date rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">%s</dc:date>
  46. </gob:ScrobbleEvent>
  47. <Record about=\"%s\">
  48. <track rdf:resource=\"%s\" />
  49. </Record>\n",
  50. htmlnumericentities($s['id']),
  51. htmlnumericentities($user->id),
  52. htmlnumericentities($s['id_track']),
  53. htmlnumericentities($s['track']),
  54. htmlnumericentities($s['id_artist']),
  55. htmlnumericentities($s['artist']),
  56. htmlnumericentities($s['timeiso']),
  57. htmlnumericentities($s['id_album']),
  58. htmlnumericentities($s['id_track'])
  59. );
  60. }
  61. print "</rdf:RDF>\n";