b0x4it Posted November 18, 2011 Share Posted November 18, 2011 How can I extract MP3 URLs from a text that is in the clipboard? I tried this with no luck: #include <Array.au3> ;Only for _ArrayDisplay $gs_Html = ClipGet() $aString = StringRegExp($gs_Html, "http://(.*)/.*\.mp3", 3) _ArrayDisplay($aString) Any suggestion would be appreciated! Link to comment Share on other sites More sharing options...
Varian Posted November 18, 2011 Share Posted November 18, 2011 (edited) This would work: #include <Array.au3> $sText = 'http://google.com/Song1.mp3' & @LF $sText &= 'http://google.com/Song2.mp3' $iArray = StringRegExp($sText, '(?im)http:// .* / (.*.mp3)', 3) If Not @error Then _ArrayDisplay($iArray) EDIT...You may need to popup this snippet to read the code..the site thinks that it is a media link EDIT EDIT: I had to add a space after the http://, .*, & /..remove them to run the code Edited November 18, 2011 by Varian Link to comment Share on other sites More sharing options...
somdcomputerguy Posted November 18, 2011 Share Posted November 18, 2011 Another way to skin the cat.. #include <String.au3> Local $Start = "http://", $End = ".mp3", _ $String = "This is just text before the URL you want http://example.com/asong.mp3.", _ $Array = _StringBetween($String, $Start, $End) MsgBox(0, "", $Start & $Array[0] & $End) - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 Thank you for your replies, but none of them extracts the correct urls. The method in the first reply extracts urls like this: [0]|01%20-%20Ghara%20Nabood%20-%20Alireza%20Talischi.mp3">01 - Ghara Nabood - Alireza Talischi.mp3 and the second method exracts urls like this: [1]|intbaran.in/Albums/1390/Aban/index.php?icon=mp3" alt="" /> <a href="http://intbaran.in/Albums/1390/Aban/2/Minor/Minor%20Music%20Group%20-%20Top%2010/02%20-%20Alireza%20Talischi%20-%20Taghvim any suggestion? Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 (edited) Try the regular expression way but exclude results that contain a ? as those will be php arguments to the URI and not links directly to an MP3 file.What is the address of the webpage? Edited November 19, 2011 by gruntydatsun Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 Try the regular expression way but exclude results that contain a ? as those will be php arguments to the URI and not links directly to an MP3 file.What is the address of the webpage?Thanks for your reply. I tried to learn regular expression, but I couldn't. The web site is :http://www.musicbaran.org/modules.php?name=News&file=article&sid=8077I appreciate if you can fix it for me.Also do you have any document or web page with very simple tutorial and examples of regular expression?Thanks Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 I'll try. Not much of an expert but I've been learning too. That is one aggressively designed website lol ! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2011 Moderators Share Posted November 19, 2011 b0x4it, gruntydatsun,I have used this site to learn what little I know about SREs - everyone I have pointed to it in the past has found it very useful. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 (edited) #include <IE.au3> #include <String.au3> #include <Array.au3> $oIE = _IECreate ("http://www.musicbaran.org/modules.php?name=News&file=article&sid=8077",0,0) ;create IE instance and load Webmail $text = _IEBodyReadHTML($oIE) _IEQuit($oIE) $array = StringRegExp($text,'a href="(http://.*.mp3"',3) _ArrayDisplay($array) the regex split out is: ' a h r e f = " ( h t t p : / / . * . m p 3 ) " ' Sorry about the constant updating but it was replacing the h t t p : / / . * . m p 3 with media tags and showing a media player interface. Edited November 19, 2011 by gruntydatsun Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 Thanks for all the replies, but I don't want to use IE, as the purpose is that to be able to do this on any web page that the source code is in the clipboard. Any other solution? Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 #include <Array.au3> $text = ClipGet() $array = StringRegExp($text,'a href="(http://.*.mp3"',3) _ArrayDisplay($array) Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 Thanks for the reply, but something is wrong with the code. It does not run! Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 (edited) Typo. This works. i left out the closing bracket after the mp3 bit. sick of trying to get this onto the page without the media player stuff popping up. answer is attached below:Extract_MP3_URLS_From_Page.au3 Edited November 19, 2011 by gruntydatsun Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 thanks for the reply. It works for most cases but in some cases it extracts urls incorrectly like this: [0]|http://yaser3h.persiangig.com/audio/Shahriyar%20Ebrahimi%20-%20Aye%20yaas.mp3">لینک دانلود شهریار ابراهیمی</a> - </font></font></font></font></font><a href="http://yaser3h.persiangig.com/audio/Farzad%20Farzin%20-%20Midoonam.mp3 any suggestion? thanks in advance Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 hi box4it, it should capture that one, fits the pattern. What is the URL is doesn't work on? Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 hi box4it, it should capture that one, fits the pattern.What is the URL is doesn't work on?The web page is:http://www.musicbaran.org/modules.php?name=News&file=article&sid=8077it should findhttp://yaser3h.persiangig.com/audio/Shahriyar%20Ebrahimi%20-%20Aye%20yaas.mp3as well as http://yaser3h.persiangig.com/audio/Farzad%20Farzin%20-%20Midoonam.mp3instead of this one:[0]|http://yaser3h.persiangig.com/audio/Shahriyar%20Ebrahimi%20-%20Aye%20yaas.mp3">لینک دانلود شهریار ابراهیمی</a> - </font></font></font></font></font><a href="any idea? Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 Sorry this is the url: http://www.ganja2music123.com/modules.php?name=News&file=article&sid=2555 Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 hi box4it, http://yaser3h.per siangig.c om /audio/ is using relative addressing in the background, not absolute so no http: or domain for the regex to match in the link. My brain is dead. Awake too long. Need sleep. Link to comment Share on other sites More sharing options...
b0x4it Posted November 19, 2011 Author Share Posted November 19, 2011 sure, thanks for all your help. I'm trying to find a way using _StringBetween function. good night Link to comment Share on other sites More sharing options...
gruntydatsun Posted November 19, 2011 Share Posted November 19, 2011 The bad link is wrapped in some non-English character set. Maybe the regex is choking on that or something? Not sure. Wait till the smart people get online and they wil probably help you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now