in reply to Winamp -> LiveJournal

I've been trying to figure out how to make the updates as seemless as possible. Part of the problem is that posting takes a good amount of time to resolve. Calling a delete and then an immediate post can still have a delay of upwards of 5 seconds!

Any thoughts on how to make this more atomic?

Cheers,
ibanix

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Replies are listed 'Best First'.
Re: Re: Winamp -> LiveJournal
by Bird (Pilgrim) on Dec 16, 2002 at 04:33 UTC

    ++ibanix, nice script!

    Having recently had the opportunity to work with LJ::Simple, and being a fellow LJer myself, I enjoyed the timeliness of this post. Since LJ has the option for "Current Music" with every post, I thought of another way you could implement it, which might also solve the slow update problem.

    Instead of posting a new entry with just your current musical selection, what if you modified the "Current Music" value of the most recent entry, keeping it current with whatever you are listening to? You could use the GetEntries() method with a $type of "one". Since the script is running continuously, you could store the $item_id and original "Current Music" value (which you entered manually when you first made the post), and if it detects a new post (the $item_id stored no longer matches the most recent post), it can reset the old post to the original music setting, store the new $item_id and current music, and off you go.

    ... After writing the first half of this post, I decided to go play with LJ::Simple for a bit and see if I could do what I was proposing. It turns out that the code I had in mind...

    my $entries = {}; $lj->GetEntries($entries, undef, 'one', -1); for my $item_id (keys %{$entries}) { $lj->Setprop_current_music($entries->{$item_id}, $music); $lj->PostEntry($entries->{$item_id}); }

    ...doesn't work. Apparently the hash returned by GetEntries isn't compatible with PostEntry. It looks like instead you'd have to copy all the properties from the GetEntries hash into a new entry and post that after deleting the old one. This, of course, no longer solves the problem of a delay between deleting and reposting. It even introduces a more significant issue, since the post you're deleting is an actual entry, instead of just the current music. I'm sure it can be done, and I'd like to play with it some more, but it's getting late and I've got to work in the morning. Thanks again for the great idea, this happened to be very on-topic for me at the moment. :)

      Yes, I found myself wishing that LJ::Simple had a ModifyEntry method, as it would have made all of this so much easier. I like your idea too, but I wanted to display the full ID3 tag info :-)

      This also still has the "delete & re-add" problem, I think. If you posted a new entry via the PostEntry method, you'd keep adding new entries.

      Maybe I'll have to grok the LJ::Simple source now... :-P

      Cheers,
      ibanix

      $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;