It is currently May 3rd, 2024, 2:24 pm

youtube regex help please

Get help with creating, editing & fixing problems with skins
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

youtube regex help please

Post by kylejdb »

so i took a week off before school starts to prepare, part of which is fixing up my rainmeter skin with some school friendly additions. so i want a youtube feed, which i have successfully created. BUT! i want a previous and next button so i can view more than my 10 results without taking up more screen space. the problem is that in the RSS feed for page 1 results, the 'previous' link section is totally missing, while present in page 2 and beyond. im having trouble writing a regex to work for both conditions. i brushed up a bit on regex's last night and tried to get it working with some if/then/else tricks, but after 4 hours of tinkering, couldn't get it working properly. i plan on getting up to speed on rainmeter this week, as i've been uninvolved for a few months and have been super inspired to make some cool configs lately, but i dont have the time or desire to throw proficiency in regex in there as well. so i would greatly appreciate anyone's help with this. here is the concerned section (in context) on page 1 and page 2, followed by the relevent regex section sans my failed attempt at if/then/else :P

Code: Select all

<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/hauensteincenter'/><link rel='alternate' type='text/html' href='http://www.youtube.com/profile_videos?user=HauensteinCenter'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=1&max-results=10&orderby=updated'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=11&max-results=10&orderby=updated'/><author>

Code: Select all

<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/hauensteincenter'/><link rel='alternate' type='text/html' href='http://www.youtube.com/profile_videos?user=HauensteinCenter'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=11&max-results=10&orderby=updated'/><link rel='previous' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=1&max-results=10&orderby=updated'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=21&max-results=10&orderby=updated'/><author>
this does not include my if then else attempt because i didn't save it last night since i have an otherwise working regex. i had it in between the title and name captures.

Code: Select all

(?siU).*<title type='text'>(.*)</title>.*<name>(.*)</name>.*<entry><id>.*<title.*>(.*)</title>.*<content type='text'.*>(.*)<.*link rel='alternate' type='text/html' href='(.*)/>.*<media:thumbnail url='(.*)' .*</entry>.*
Last edited by Kaelri on August 17th, 2011, 4:49 pm, edited 1 time in total.
Reason: Added [code] tags.
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: youtube regex help please

Post by FlyingHyrax »

Is it possible to link to the feed you are using?
Also, perhaps you could simply use multiple WebParser measures for the various pages, instead of trying to use If actions?
(I'm sort of guessing because I don't know quite how this Youtube feed is structured.)

JSMorely is, I think, the resident Regular Expression ninja, he might have some more helpful input for you.
Flying Hyrax on DeviantArt
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

Re: youtube regex help please

Post by kylejdb »

http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=1&max-results=10&orderby=updated
is the link. i have 10 results per page, so the index # can be changed to 11 to get to 'my' page 2 and so on, although i dont think it really matters so long as it's page 2. as far as using different measures, i dont think im tracking.. lol. my brains not fired up yet today. :confused:
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: youtube regex help please

Post by Kaelri »

The best approach here is to use a "look ahead" function in the RegExp, which looks like this:

Code: Select all

(?siU)(?(?=<link.*rel='previous')<link.*rel='previous'.*href='(.*)')
If it finds the "previous" link in the feed, it will return the URL for the appropriate string index. If not, the index will be left blank.
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

Re: youtube regex help please

Post by kylejdb »

Kaelri wrote:The best approach here is to use a "look ahead" function in the RegExp, which looks like this:

Code: Select all

(?siU)(?(?=<link.*rel='previous')<link.*rel='previous'.*href='(.*)')
If it finds the "previous" link in the feed, it will return the URL for the appropriate string index. If not, the index will be left blank.

Code: Select all

http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=11&max-results=10&orderby=updated

Code: Select all

(?siU).*<title type='text'>(.*)</title>.*(?(?=<link.*rel='previous')<link.*rel='previous'.*href='(.*)'.*<link.*rel='next'.*href='(.*)').*<name>(.*)</name>.*
thank you very much. it didnt quite work for me in rainregexp. when used alone it found the correct capture but assigned it stringindex 12, leaving all others blank. when i pasted it into my regex as above, it returns empty values for me when on page 1 or 2 but it has a correct stringindex. it does return something tho, which is better than i was able to achieve so thank you! :). i added to it so that i can capture both the previous and next address's, and am pretty sure i did so correctly, i get 2 empty values now. but it still doesnt work correctly. thank you for the fast help guys.
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

Re: youtube regex help please

Post by kylejdb »

so i messed with it a bit more last night, and still can't figure out why the captures arent being captured. the expression looks good and accurate to me, but of course im not skilled in regex, so i really don't know. if i use this expression by itself, i get results, but they are indexed as entry 17 and 18, all others are blank. if i use it with my existing expression, i seem to break it because i get empty strings returned. any more help would be greatly appreciated.

Code: Select all

(?siU)(?(?=<link rel='previous')<link rel='previous'.*href='(.*)'.*<link rel='next'.*href='(.*)')
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

Re: youtube regex help please

Post by kylejdb »

oh man! i guess a new day is all i needed :P. i woke up, took a look at it after i posted for more help, and fixed it! it seems i needed to bring the parser engine to just before where lookahead is to to query. this is what i did for anyone that may be curious. thanks for putting me in the right direction kaelri.

Code: Select all

(?siU).*<title type='text'>(.*)</title>.*<link rel='self'.*href='.*'/>(?(?=<link rel='previous')<link rel='previous'.*href='(.*)'.*<link rel='next'.*href='(.*)').*<name>(.*)</name>.*
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: youtube regex help please

Post by Kaelri »

No problem. I'm still not entirely sure why that works, though, or why the earlier one didn't. I'll have to play with that some more.
User avatar
GHOST®
Posts: 55
Joined: March 11th, 2011, 6:33 pm
Location: Garden City, MI

Re: youtube regex help please

Post by GHOST® »

kylejdb wrote:so i took a week off before school starts to prepare, part of which is fixing up my rainmeter skin with some school friendly additions. so i want a youtube feed, which i have successfully created. BUT! i want a previous and next button so i can view more than my 10 results without taking up more screen space. the problem is that in the RSS feed for page 1 results, the 'previous' link section is totally missing, while present in page 2 and beyond. im having trouble writing a regex to work for both conditions. i brushed up a bit on regex's last night and tried to get it working with some if/then/else tricks, but after 4 hours of tinkering, couldn't get it working properly. i plan on getting up to speed on rainmeter this week, as i've been uninvolved for a few months and have been super inspired to make some cool configs lately, but i dont have the time or desire to throw proficiency in regex in there as well. so i would greatly appreciate anyone's help with this. here is the concerned section (in context) on page 1 and page 2, followed by the relevent regex section sans my failed attempt at if/then/else :P

Code: Select all

<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/hauensteincenter'/><link rel='alternate' type='text/html' href='http://www.youtube.com/profile_videos?user=HauensteinCenter'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=1&max-results=10&orderby=updated'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=11&max-results=10&orderby=updated'/><author>

Code: Select all

<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/hauensteincenter'/><link rel='alternate' type='text/html' href='http://www.youtube.com/profile_videos?user=HauensteinCenter'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=11&max-results=10&orderby=updated'/><link rel='previous' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=1&max-results=10&orderby=updated'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/HauensteinCenter/uploads?start-index=21&max-results=10&orderby=updated'/><author>
this does not include my if then else attempt because i didn't save it last night since i have an otherwise working regex. i had it in between the title and name captures.

Code: Select all

(?siU).*<title type='text'>(.*)</title>.*<name>(.*)</name>.*<entry><id>.*<title.*>(.*)</title>.*<content type='text'.*>(.*)<.*link rel='alternate' type='text/html' href='(.*)/>.*<media:thumbnail url='(.*)' .*</entry>.*
I for one am highly interested in a skin like this!! Any chance you'll be posting after you have it refined?? or should I divert from my many already diverted from projects and try to recreate your wheel on my own?? ;o)

Normally I'd just try things on my own, but RegX hurts my brain. ;op
"Do you want to be healed, now? Or would you prefer to bleed to death so I can try my hand at resurrection?"