News:

HOT TIP! In the command editor, you can ctrl-click and drag an item to create a copy of it.

Main Menu

Regex help to extract artist, song from web page

Started by xtermin8r, May 22, 2014, 12:18:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xtermin8r

Dear Voxinator

I'm struggling to construct the regex pattern that extracts the artist and song name for another mpc xperiment I'm doing.
the url in question http://localhost:13579/info.html

<p id="mpchc_np">&laquo; MPC-HC v1.7.3.0 &bull; Snap - The Power &bull; 00:00:00/00:04:24 &bull; 19.4 MB &raquo;</p>


I'm trying to extract Snap as artist and The Power as song, so that I can ask Jarvis to tell me who the artist is, and tell me the song name.

the only thing I could come up with is &bull;(.*?)(.*?)&bull which gives me Snap - The Power

thanks in advance.
Neural Net Based Artificial Intelligence.

nime5ter

How consistent is the pattern?

Does <p id="mpchc_np">&laquo; MPC-HC v1.7.3.0 &bull; always precede the song name?

Is the artist name always separated from the song name by " - "?

Does a bullet ("&bull;") always appear after the band name?
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

#2
e.g. the following gets the info you want, but you may run into problems depending on pattern variability


<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.5.1-->
<command id="1151" name="get song info" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
 <action>
   <cmdType>Results.SetLastResult</cmdType>
   <params>
     <param>&lt;p id="mpchc_np"&gt;&amp;laquo; MPC-HC v1.7.3.0 &amp;bull; Snap - The Power &amp;bull; 00:00:00/00:04:24 &amp;bull; 19.4 MB &amp;raquo;&lt;/p&gt;</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.RegEx</cmdType>
   <params>
     <param>&amp;bull;\s(.*?).-.(.*?)&amp;bull;</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>OSD.ShowText</cmdType>
   <params>
     <param>Artist: {Match.1.1}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>OSD.AddText</cmdType>
   <params>
     <param>Song: {Match.1.2}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
</command>


In the above, {Match.{i}.1} will always be the artist, and {Match.{i}.2} will be the song, if the pattern is consistent throughout.

[edited to correct which is artist and which is song.  :biglaugh]
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

xtermin8r

Quote from: nime5ter on May 22, 2014, 12:55:11 PM
How consistent is the pattern?

Does <p id="mpchc_np">&laquo; MPC-HC v1.7.3.0 &bull; always precede the song name?
yes

QuoteIs the artist name always separated from the song name by " - "?
not always

QuoteDoes a bullet ("&bull;") always appear after the band name?
yes always after the full artist song name
Neural Net Based Artificial Intelligence.

nime5ter

Quote from: xtermin8r on May 22, 2014, 01:01:21 PM
not always

That will be a problem. Are there a set number of possibilities? Is it a public web page that I can look at?
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

xtermin8r

Thank you nime5ter. Its exactly what I needed, if artist name and song are not separated by a - I guess i will have to manually insert it into the file name.
Neural Net Based Artificial Intelligence.

nime5ter

Yeah, I was just about to say, if it's your own library, then the best thing would be if you could rename the files in a consistent way.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

xtermin8r

Quote from: nime5ter on May 22, 2014, 01:04:50 PM
That will be a problem. Are there a set number of possibilities? Is it a public web page that I can look at?

it's not a public web page, it's the web page of media player classic, i could upload the html if you like
Neural Net Based Artificial Intelligence.

nime5ter

If you like, sure. But it seems like it would make more sense, and be more reliable, if you could create consistent file names and then work with that.

The above obviously won't work perfectly if you have file names with more than one " - " in the name.

TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

xtermin8r

Quote from: nime5ter on May 22, 2014, 01:14:57 PM
If you like, sure. But it seems like it would make more sense, and be more reliable, if you could create consistent file names and then work with that.
Personally i think there is no need to upload it (waste of digital space)  :biglaugh, the relevent info is in the first post.
I agree, it would be more reliable if file names are consistent and include a "-" between the artist and song name.

QuoteThe above obviously won't work perfectly if you have file names with more than one " - " in the name.
True, I will have to use other methods to get rid of any extra "-" in the name.




Neural Net Based Artificial Intelligence.

nime5ter

Quote from: xtermin8r on May 22, 2014, 01:26:35 PM
True, I will have to use other methods to get rid of any extra "-" in the name.

Or use a more unique character to separate song and artist in your file names.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

Looks like it is just returning the filename.

I recommend you use a proper music management program like MediaMonkey.  It is free and can't be beat. Even if you don't want to use it to play your music for some reason, you can still use it to organise your music, maintain proper tags, album art etc. And it can then organise your files with predictable path and filename formats.