Author Topic: custom weblinks that direct to a specific webpage  (Read 4364 times)

hiccup

  • Sr. Member
  • ****
  • Posts: 7799
I am struggling a bit with custom weblinks.

As an example, suppose I want to visit rateyourmusic's webpage on the album 'Restless Ones' from 'The Heartless Bastards'

When I navigate to that page myself, I can see the url for that album is:
http://rateyourmusic.com/release/album/heartless_bastards/restless_ones/

But when I use something like this as a generated weblink:
http://rateyourmusic.com/release/album/<Artist>/<Album>

the result is a 404, and the url displays:
http://rateyourmusic.com/release/album/Heartless%20Bastards/Restless%20Ones

So both capitalization, and underscores don't match, which throws this error.
Is there a way to get that right?

I can imagine using virtual tags and regex might be a way to get there, but some other websites use + instead of _ as separators, so that might be bit complicated too.



P.s. doing something like this using the search option on the website works fine:
http://rateyourmusic.com/search?searchtype=l&searchterm=<Artist> <Album>

But I am curious if it would be possible to get direct links for this and a few other websites.

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
I just whipped this up pretty quick.  It works for Arctic Monkeys - Whatever People Say I Am, That's What I'm Not.  Try it out:

http://rateyourmusic.com/release/album/$lower($replace($replace($replace(<Artist>"/"<Album>," ",_),"'",),",",_))

Anyways, I raised the ire of rateyourmusic's flood detector used to detect scripts leading to a captcha page.  I guess they don't like scripts scrapping their site for information.  Heck, some people reported for being IP banned for using an mp3tag websource script for that very purpose.  Anyways, they're better sites for that like AMG, discogs and musicbrainz.

For other sites that use different separators, just use $replace like above.

PS:  And yes, it would have nicer to use regex rather than nested $replace functions, but the latter gets the job done and it is infinitely more readable to others ;)
Last Edit: April 14, 2016, 04:46:33 AM by ssri

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
Wouldn't just "$lower($replace(<Artist>"/"<Album>," ",_))" do it?  What am I missing?
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
What am I missing?
Punctuation marks lead to a 404 message.  Commas, like spaces, are replaced by underscores and other punctuation marks are simply excluded.  Your example would've led to a "404: File not found" from the example I used above.  My formula converts "Arctic Monkeys - Whatever People Say I Am, That's What I'm Not" to its proper RYM URL: https://rateyourmusic.com/release/album/arctic_monkeys/whatever_people_say_i_am__thats_what_im_not/

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
You will also need to escape ampersands. Might be better to do with regex after all.

I copied your formula and am not getting results, though.  The underscore replacement doesn't seem to be working.  I wonder if that's a bug?  (I think it is not replacing the space - I can get other characters to do the replacement.)
Last Edit: April 14, 2016, 06:18:29 AM by psychoadept
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
You will also need to escape ampersands. Might be better to do with regex after all.

I copied your formula and am not getting results, though.  The underscore replacement doesn't seem to be working.  I wonder if that's a bug?  (I think it is not replacing the space - I can get other characters to do the replacement.)
Works fine on my end: https://youtu.be/VnPvP5bTlR8

As I said, it works for my example.  And yes, ampersands need to be escaped, as do periods, quotation marks, etc, etc.  If others find additional characters that need to be excluded or replaced with underscores, they are free to add them.  Or there might be custom titles that need to be replaced, i.e. those appended by "EP".  Thankfully AMG, discogs and musicbee are plenty enough for me. 

And you are right, it would have been much cleaner (and easier) to use regex.  I thought there is no regex function here, only one that outputs "T" or "F".

hiccup

  • Sr. Member
  • ****
  • Posts: 7799
I just whipped this up pretty quick.  It works for Arctic Monkeys - Whatever People Say I Am, That's What I'm Not.  Try it out:

Thanks ssri!

A quick test shows that your formula seems to work quite well already.
There are probably some more characters that will need to be remapped for RYM, such as & and -
But I should be able to figure that out now.

You are also correct about the sensitive flood detector of RYM. Yesterday when trying some stuff out, I was 'reprimanded' already after maybe 5 tries. Do you think using the 'search' option instead of the 'direct link' option would make a difference in that aspect?

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
And you are right, it would have been much cleaner (and easier) to use regex.  I thought there is no regex function here, only one that outputs "T" or "F".

No, you're right.  I think it's Picard that I was remembering having an $Rreplace function.  It's been request for MB but not implemented.
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
Thanks ssri!

A quick test shows that your formula seems to work quite well already.
There are probably some more characters that will need to be remapped for RYM, such as & and -
But I should be able to figure that out now.

You are also correct about the sensitive flood detector of RYM. Yesterday when trying some stuff out, I was 'reprimanded' already after maybe 5 tries. Do you think using the 'search' option instead of the 'direct link' option would make a difference in that aspect?
You're welcome.  To add more escaped characters, just do:

http://rateyourmusic.com/release/album/$lower($replace($replace($replace($replace(<Artist>"/"<Album>," ",_),"'",),",",_),"X",Y))

a simpler way of looking at it:  http://rateyourmusic.com/release/album/$lower($replace(...,"X",Y))

... = $replace($replace(<Artist>"/"<Album>," ",_),"'",),",",_)
X = punctuation mark or any other characters
Y = (empty space) or underscore, as most of the time punctuation marks are omitted but some like periods or commas are replaced by an underscore.

As for the search function, one can do that but it will take more effort from users to find whichever album they're looking for (scanning the search results).  Also, I don't know if RYM implemented any similar flood protection for search queries (again, I seldom if ever use that site).  In the end, I would recommend to try both approaches and see which one works out the best for you.
Last Edit: April 14, 2016, 07:35:47 PM by ssri