static double rb_random_by_age_and_rating_get_entry_weight (RBRandomPlayOrder *rorder, RhythmDB *db, RhythmDBEntry *entry) { time_t now; gulong last_play; gulong seconds_since_last_play = 0; gdouble rating; RhythmDBEntry *playing_entry; /* This finds the log of the number of seconds since the last play. * It handles never played automatically, since now-0 is a valid * argument to log(). */ time (&now); playing_entry = rb_play_order_get_playing_entry (RB_PLAY_ORDER (rorder)); if (playing_entry != entry) { last_play = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_LAST_PLAYED); seconds_since_last_play = now - last_play; } if (playing_entry != NULL) rhythmdb_entry_unref (playing_entry); /* The lowest weight should be 0. */ if (seconds_since_last_play < 1) seconds_since_last_play = 1; rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING); /* treat unrated as 2.5 for the purposes of probabilities */ if (rating < 0.01) rating = 2.5; return log (seconds_since_last_play) * (rating + 1.0); }
static double rb_random_by_rating_get_entry_weight (RBRandomPlayOrder *rorder, RhythmDB *db, RhythmDBEntry *entry) { double rating; rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING); if (rating < 0.01) rating = 2.5; return rating; }
static LIBMTP_track_t * transfer_track (RBMtpSource *source, LIBMTP_mtpdevice_t *device, RhythmDBEntry *entry, const char *filename, guint64 filesize, const char *mimetype) { LIBMTP_track_t *trackmeta = LIBMTP_new_track_t (); GDate d; int ret; trackmeta->title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE); trackmeta->album = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM); trackmeta->artist = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ARTIST); trackmeta->genre = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_GENRE); trackmeta->filename = g_path_get_basename (filename); if (rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE) > 0) { /* Entries without a date returns 0, g_date_set_julian don't accept that */ g_date_set_julian (&d, rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE)); trackmeta->date = gdate_to_char (&d); } trackmeta->tracknumber = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER); trackmeta->duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION) * 1000; trackmeta->rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING) * 20; trackmeta->usecount = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_PLAY_COUNT); trackmeta->filesize = filesize; if (mimetype == NULL) { mimetype = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MIMETYPE); } trackmeta->filetype = mimetype_to_filetype (source, mimetype); rb_debug ("using libmtp filetype %d (%s) for source media type %s", trackmeta->filetype, LIBMTP_Get_Filetype_Description (trackmeta->filetype), mimetype); #ifdef HAVE_LIBMTP_030 ret = LIBMTP_Send_Track_From_File (device, filename, trackmeta, NULL, NULL); #else ret = LIBMTP_Send_Track_From_File (device, filename, trackmeta, NULL, NULL, 0); #endif rb_debug ("LIBMTP_Send_Track_From_File (%s) returned %d", filename, ret); if (ret != 0) { report_libmtp_errors (device, TRUE); LIBMTP_destroy_track_t (trackmeta); return NULL; } if (strcmp (trackmeta->album, _("Unknown")) != 0) { add_track_to_album (source, trackmeta->album, trackmeta); } return trackmeta; }
static void prepare_encoder_sink_cb (RBEncoderFactory *factory, const char *stream_uri, GObject *sink, RBMtpSource *source) { RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (source); RhythmDBEntry *entry; RhythmDB *db; LIBMTP_track_t *track; char **bits; char *extension; LIBMTP_filetype_t filetype; gulong track_id; GDate d; char **folder_path; /* make sure this stream is for a file on our device */ if (g_str_has_prefix (stream_uri, "xrbmtp://") == FALSE) return; /* extract the entry ID, extension, and MTP filetype from the URI */ bits = g_strsplit (stream_uri + strlen ("xrbmtp://"), "/", 3); track_id = strtoul (bits[0], NULL, 0); extension = g_strdup (bits[1]); filetype = strtoul (bits[2], NULL, 0); g_strfreev (bits); db = get_db_for_source (source); entry = rhythmdb_entry_lookup_by_id (db, track_id); g_object_unref (db); if (entry == NULL) { g_free (extension); return; } track = LIBMTP_new_track_t (); track->title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE); track->album = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM); track->artist = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ARTIST); track->genre = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_GENRE); /* build up device filename */ track->filename = g_strdup_printf ("%s - %s.%s", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST), rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE), extension); g_free (extension); /* construct folder path: artist/album */ folder_path = g_new0 (char *, 3); folder_path[0] = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM_ARTIST); if (folder_path[0] == NULL || folder_path[0][0] == '\0') { g_free (folder_path[0]); folder_path[0] = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ARTIST); } folder_path[1] = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM); /* ensure the filename is safe for FAT filesystems and doesn't contain slashes */ sanitize_for_mtp (track->filename); sanitize_for_mtp (folder_path[0]); sanitize_for_mtp (folder_path[1]); if (rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE) > 0) { g_date_set_julian (&d, rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE)); track->date = gdate_to_char (&d); } track->tracknumber = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER); track->duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION) * 1000; track->rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING) * 20; track->usecount = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_PLAY_COUNT); track->filetype = filetype; g_object_set (sink, "device-thread", priv->device_thread, "folder-path", folder_path, "mtp-track", track, NULL); rhythmdb_entry_unref (entry); g_strfreev (folder_path); g_hash_table_insert (priv->track_transfer_map, g_strdup (stream_uri), track); }
RBDAAPRecord * rb_daap_record_new (RhythmDBEntry *entry) { RBDAAPRecord *record = NULL; record = RB_DAAP_RECORD (g_object_new (RB_TYPE_DAAP_RECORD, NULL)); /* When browsing, entry will be NULL because we will pull * the metadata from the DAAP query. When sharing, entry will * point to an existing entry from the Rhythmbox DB. */ if (entry) { gchar *ext; record->priv->filesize = rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE); record->priv->location = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION); record->priv->title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE); record->priv->artist = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ARTIST); record->priv->album = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM); /* Since we don't support album id's on Rhythmbox, "emulate" it */ record->priv->albumid = (gintptr) rhythmdb_entry_get_refstring (entry, RHYTHMDB_PROP_ALBUM); record->priv->genre = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_GENRE); /* FIXME: Support transcoding: */ /* FIXME: we should use RHYTHMDB_PROP_MIMETYPE instead */ ext = strrchr (record->priv->location, '.'); if (ext == NULL) { ext = "mp3"; } else { ext++; } record->priv->mediakind = DMAP_MEDIA_KIND_MUSIC; record->priv->real_format = g_strdup (ext); record->priv->format = g_strdup (record->priv->real_format); /* Only support songs */ record->priv->mediakind = 1; record->priv->track = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER); record->priv->duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION); record->priv->rating = (gint) rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING); record->priv->year = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_YEAR); record->priv->firstseen = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_FIRST_SEEN); record->priv->mtime = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_MTIME); record->priv->disc = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DISC_NUMBER); record->priv->bitrate = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_BITRATE); } return record; }