| 1 | ################################################################################# | ||
| 2 | ####This Perl module represents the CPAN name space WebService::Jamendo::RSS.#### | ||
| 3 | ####################Written by Gerald L. Hevener, M.S.########################### | ||
| 4 | ##############AKA: jackl0phty in the whitehat hacker community.################## | ||
| 5 | #########This module is licensed under the same terms as Perl itself.############ | ||
| 6 | #########Maintainer's Email: hevenerg {[AT]} marshall {[DOT]} edu.############## | ||
| 7 | #After years of using free (as in beer) software, thought I'd try to give back. # | ||
| 8 | ################################################################################# | ||
| 9 | |||
| 10 | # declare package name | ||
| 11 | package WebService::Jamendo::RSS; | ||
| 12 | |||
| 13 | 3 | ▶ | use 5.006000; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 3 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 0 | ▶ | use XML::Twig; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 18 | use LWP::Simple; | ||
| 19 | |||
| 20 | require Exporter; | ||
| 21 | |||
| 22 | our @ISA = qw(Exporter); | ||
| 23 | |||
| 24 | # Items to export into callers namespace by default. Note: do not export | ||
| 25 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 26 | # Do not simply export all your public functions/methods/constants. | ||
| 27 | |||
| 28 | # This allows declaration use WebService::Jamendo::RSS ':all'; | ||
| 29 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||
| 30 | # will save memory. | ||
| 31 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 32 | |||
| 33 | ) ] ); | ||
| 34 | |||
| 35 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 36 | |||
| 37 | our @EXPORT = qw( | ||
| 38 | get_popular_albums_this_week get_latest_albums get_latest_albums_usa get_this_week_most_100_listened_to | ||
| 39 | get_jamendo_blog get_jamendo_forums download_popular_albums_this_week_xml get_jamendo_news | ||
| 40 | download_latest_albums_xml download_latest_albums_usa_xml download_this_week_most_100_listened_to_xml | ||
| 41 | download_jamendo_blog_xml download_jamendo_forums_xml download_jamendo_news_xml | ||
| 42 | ); | ||
| 43 | |||
| 44 | our $VERSION = '0.01'; | ||
| 45 | |||
| 46 | # declare variables for popular albums this week | ||
| 47 | my $popular_albums_this_week_url = "http://www.jamendo.com/en/rss/popular-albums"; | ||
| 48 | my $popular_albums_this_week_root; | ||
| 49 | my $popular_albums_this_week_xml; | ||
| 50 | my $popular_albums_this_week_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 51 | |||
| 52 | # declare variables for latest albums | ||
| 53 | my $latest_albums_url = "http://www.jamendo.com/en/rss/last-albums"; | ||
| 54 | my $latest_albums_root; | ||
| 55 | my $latest_albums_xml; | ||
| 56 | my $latest_albums_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 57 | |||
| 58 | # declare variables for latest albums in the USA | ||
| 59 | my $latest_albums_usa_url = "http://www.jamendo.com/en/rss/last-albums/USA"; | ||
| 60 | my $latest_albums_usa_root; | ||
| 61 | my $latest_albums_usa_xml; | ||
| 62 | my $latest_albums_usa_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 63 | |||
| 64 | # declare variables for this week most 100 listened to | ||
| 65 | my $this_week_most_100_listened_to_url = "http://www.jamendo.com/en/rss/top-track-week"; | ||
| 66 | my $this_week_most_100_listened_to_root; | ||
| 67 | my $this_week_most_100_listened_to_xml; | ||
| 68 | my $this_week_most_100_listened_to_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 69 | |||
| 70 | # declare variables for jamendo blog rss feed | ||
| 71 | my $jamendo_blog_url = "http://feeds.feedburner.com/JamendoBlogEnglish?format=xml"; | ||
| 72 | my $jamendo_blog_root; | ||
| 73 | my $jamendo_blog_xml; | ||
| 74 | my $jamendo_blog_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 75 | |||
| 76 | # declare variables for jamendo forums rss feed | ||
| 77 | my $jamendo_forums_url = "http://www.jamendo.com/fr/forums/discussions/?Feed=RSS2"; | ||
| 78 | my $jamendo_forums_root; | ||
| 79 | my $jamendo_forums_xml; | ||
| 80 | my $jamendo_forums_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 81 | |||
| 82 | # declare variables for jamendo news rss feed | ||
| 83 | my $jamendo_news_url = "http://www.jamendo.com/en/rss/newsfeed/bf0b52ca330f6ca9e88801e3f0c26c68775909"; | ||
| 84 | my $jamendo_news_root; | ||
| 85 | my $jamendo_news_xml; | ||
| 86 | my $jamendo_news_twig = new XML::Twig(TwigRoots => {'item' => 1, pretty_print => 'indented'}); | ||
| 87 | |||
| 88 | # preloaded methods go here. | ||
| 89 | ######################Begin Primary Subroutines########################## | ||
| 90 | |||
| 91 | sub get_popular_albums_this_week { | ||
| 92 | |||
| 93 | #Turn on strict and warnings. | ||
| 94 | use strict; | ||
| 95 | use warnings; | ||
| 96 | |||
| 97 | $popular_albums_this_week_twig->parsefile("popular_albums_this_week.xml"); | ||
| 98 | |||
| 99 | #set root of the twig (channel). | ||
| 100 | $popular_albums_this_week_root = $popular_albums_this_week_twig->root; | ||
| 101 | |||
| 102 | #get popular albums this week. | ||
| 103 | foreach my $popular_albums_this_week ($popular_albums_this_week_root->children('item')) { | ||
| 104 | |||
| 105 | print $popular_albums_this_week->first_child_text('title'); | ||
| 106 | print "\n"; | ||
| 107 | } | ||
| 108 | |||
| 109 | # sub get_popular_albums_this_week() | ||
| 110 | } | ||
| 111 | |||
| 112 | sub get_latest_albums { | ||
| 113 | |||
| 114 | #Turn on strict and warnings. | ||
| 115 | use strict; | ||
| 116 | use warnings; | ||
| 117 | |||
| 118 | #parse xml file for latest albums. | ||
| 119 | $latest_albums_twig->parsefile("latest_albums.xml"); | ||
| 120 | |||
| 121 | #set root of the twig (channel). | ||
| 122 | $latest_albums_root = $latest_albums_twig->root; | ||
| 123 | |||
| 124 | #get latest albums. | ||
| 125 | foreach my $latest_albums_titles ($latest_albums_root->children('item')) { | ||
| 126 | |||
| 127 | print $latest_albums_titles->first_child_text('title'); | ||
| 128 | print "\n"; | ||
| 129 | } | ||
| 130 | |||
| 131 | # sub get_latest_albums() | ||
| 132 | } | ||
| 133 | |||
| 134 | sub get_latest_albums_usa { | ||
| 135 | |||
| 136 | #Turn on strict and warnings. | ||
| 137 | use strict; | ||
| 138 | use warnings; | ||
| 139 | |||
| 140 | #parse xml file for latest albums in usa. | ||
| 141 | $latest_albums_usa_twig->parsefile("latest_albums_usa.xml"); | ||
| 142 | |||
| 143 | #set root of the twig (channel). | ||
| 144 | $latest_albums_usa_root = $latest_albums_usa_twig->root; | ||
| 145 | |||
| 146 | #get recent albums in usa. | ||
| 147 | foreach my $latest_albums_usa_titles ($latest_albums_usa_root->children('item')) { | ||
| 148 | |||
| 149 | print $latest_albums_usa_titles->first_child_text('title'); | ||
| 150 | print "\n"; | ||
| 151 | } | ||
| 152 | |||
| 153 | # sub get_latest_albums_usa() | ||
| 154 | } | ||
| 155 | |||
| 156 | sub get_this_week_most_100_listened_to { | ||
| 157 | |||
| 158 | #Turn on strict and warnings. | ||
| 159 | use strict; | ||
| 160 | use warnings; | ||
| 161 | |||
| 162 | #parse xml file for this week's most 100 listened to. | ||
| 163 | $this_week_most_100_listened_to_twig->parsefile("this_week_most_100_listened_to.xml"); | ||
| 164 | |||
| 165 | #set root of the twig (channel). | ||
| 166 | $this_week_most_100_listened_to_root = $this_week_most_100_listened_to_twig->root; | ||
| 167 | |||
| 168 | #get this week's most 100 listened to. | ||
| 169 | foreach my $this_week_most_100_listened_to_titles ($this_week_most_100_listened_to_root->children('item')) { | ||
| 170 | |||
| 171 | print $this_week_most_100_listened_to_titles->first_child_text('title'); | ||
| 172 | print "\n"; | ||
| 173 | } | ||
| 174 | |||
| 175 | # sub get_this_week_most_100_listened_to() | ||
| 176 | } | ||
| 177 | |||
| 178 | sub get_jamendo_blog { | ||
| 179 | |||
| 180 | #Turn on strict and warnings. | ||
| 181 | use strict; | ||
| 182 | use warnings; | ||
| 183 | |||
| 184 | #parse xml file for jamendo's primary blog. | ||
| 185 | $jamendo_blog_twig->parsefile("jamendo_blog.xml"); | ||
| 186 | |||
| 187 | #set root of the twig (channel). | ||
| 188 | $jamendo_blog_root = $jamendo_blog_twig->root; | ||
| 189 | |||
| 190 | #get jamendo's primary blog. | ||
| 191 | foreach my $jamendo_blog_titles ($jamendo_blog_root->children('item')) { | ||
| 192 | |||
| 193 | print $jamendo_blog_titles->first_child_text('title'); | ||
| 194 | print "\n"; | ||
| 195 | } | ||
| 196 | |||
| 197 | # sub get_jamendo_blog() | ||
| 198 | } | ||
| 199 | |||
| 200 | sub get_jamendo_forums { | ||
| 201 | |||
| 202 | #Turn on strict and warnings. | ||
| 203 | use strict; | ||
| 204 | use warnings; | ||
| 205 | |||
| 206 | #parse xml file for jamendo's forums. | ||
| 207 | $jamendo_forums_twig->parsefile("jamendo_forums.xml"); | ||
| 208 | |||
| 209 | #set root of the twig (channel). | ||
| 210 | $jamendo_forums_root = $jamendo_forums_twig->root; | ||
| 211 | |||
| 212 | #get jamendo's forums. | ||
| 213 | foreach my $jamendo_forums_titles ($jamendo_forums_root->children('item')) { | ||
| 214 | |||
| 215 | print $jamendo_forums_titles->first_child_text('title'); | ||
| 216 | print "\n"; | ||
| 217 | } | ||
| 218 | |||
| 219 | # sub get_jamendo_forums() | ||
| 220 | } | ||
| 221 | |||
| 222 | sub get_jamendo_news { | ||
| 223 | |||
| 224 | #Turn on strict and warnings. | ||
| 225 | use strict; | ||
| 226 | use warnings; | ||
| 227 | |||
| 228 | #parse xml file for jamendo's forums. | ||
| 229 | $jamendo_news_twig->parsefile("jamendo_news.xml"); | ||
| 230 | |||
| 231 | #set root of the twig (channel). | ||
| 232 | $jamendo_news_root = $jamendo_news_twig->root; | ||
| 233 | |||
| 234 | #get jamendo's news. | ||
| 235 | foreach my $jamendo_news_titles ($jamendo_news_root->children('item')) { | ||
| 236 | |||
| 237 | print $jamendo_news_titles->first_child_text('title'); | ||
| 238 | print "\n"; | ||
| 239 | } | ||
| 240 | |||
| 241 | # sub get_jamendo_news() | ||
| 242 | } | ||
| 243 | |||
| 244 | ######################End of primary subroutines########################## | ||
| 245 | |||
| 246 | #######Begin subroutines that download RSS feeds from Jamendo.com######### | ||
| 247 | |||
| 248 | sub download_popular_albums_this_week_xml { | ||
| 249 | |||
| 250 | #Turn on strict and warnings. | ||
| 251 | use strict; | ||
| 252 | use warnings; | ||
| 253 | |||
| 254 | #get xml using LWP::Simple. | ||
| 255 | $popular_albums_this_week_xml = get $popular_albums_this_week_url; | ||
| 256 | |||
| 257 | #get rid of non-ascii chars. | ||
| 258 | $popular_albums_this_week_xml =~ s/[^[:ascii:]]+//g; | ||
| 259 | |||
| 260 | #save XML to file. | ||
| 261 | open( my $POPULAR_ALBUMS_THIS_WEEK_FH, ">", "popular_albums_this_week.xml" ) or confess "Can't open file: $!"; | ||
| 262 | |||
| 263 | #print popular albums this week to file in PWD. | ||
| 264 | print $POPULAR_ALBUMS_THIS_WEEK_FH "$popular_albums_this_week_xml"; | ||
| 265 | |||
| 266 | close($POPULAR_ALBUMS_THIS_WEEK_FH); | ||
| 267 | |||
| 268 | # sub download_recent_videos_xml() | ||
| 269 | } | ||
| 270 | |||
| 271 | sub download_latest_albums_xml { | ||
| 272 | |||
| 273 | #Turn on strict and warnings. | ||
| 274 | use strict; | ||
| 275 | use warnings; | ||
| 276 | |||
| 277 | #get xml using LWP::Simple. | ||
| 278 | $latest_albums_xml = get $latest_albums_url; | ||
| 279 | |||
| 280 | #get rid of non-ascii chars. | ||
| 281 | $latest_albums_xml =~ s/[^[:ascii:]]+//g; | ||
| 282 | |||
| 283 | #save XML to file. | ||
| 284 | open( my $LATEST_ALBUMS_FH, ">", "latest_albums.xml" ) or confess "Can't open file: $!"; | ||
| 285 | |||
| 286 | #print latest albums to file in PWD. | ||
| 287 | print $LATEST_ALBUMS_FH "$latest_albums_xml"; | ||
| 288 | |||
| 289 | close($LATEST_ALBUMS_FH); | ||
| 290 | |||
| 291 | # sub download_latest_albums_xml() | ||
| 292 | } | ||
| 293 | |||
| 294 | sub download_latest_albums_usa_xml { | ||
| 295 | |||
| 296 | #Turn on strict and warnings. | ||
| 297 | use strict; | ||
| 298 | use warnings; | ||
| 299 | |||
| 300 | #get xml using LWP::Simple. | ||
| 301 | $latest_albums_usa_xml = get $latest_albums_usa_url; | ||
| 302 | |||
| 303 | #get rid of non-ascii chars. | ||
| 304 | $latest_albums_usa_xml =~ s/[^[:ascii:]]+//g; | ||
| 305 | |||
| 306 | #save XML to file. | ||
| 307 | open( my $LATEST_ALBUMS_USA_FH, ">", "latest_albums_usa.xml" ) or confess "Can't open file: $!"; | ||
| 308 | |||
| 309 | #print recent latest albums in usa to file in PWD. | ||
| 310 | print $LATEST_ALBUMS_USA_FH "$latest_albums_usa_xml"; | ||
| 311 | |||
| 312 | close($LATEST_ALBUMS_USA_FH); | ||
| 313 | |||
| 314 | # sub download_latest_albums_usa_xml(). | ||
| 315 | } | ||
| 316 | |||
| 317 | sub download_this_week_most_100_listened_to_xml { | ||
| 318 | |||
| 319 | #Turn on strict and warnings. | ||
| 320 | use strict; | ||
| 321 | use warnings; | ||
| 322 | |||
| 323 | #get xml using LWP::Simple. | ||
| 324 | $this_week_most_100_listened_to_xml = get $this_week_most_100_listened_to_url; | ||
| 325 | |||
| 326 | #get rid of non-ascii chars. | ||
| 327 | $this_week_most_100_listened_to_xml =~ s/[^[:ascii:]]+//g; | ||
| 328 | |||
| 329 | #save XML to file. | ||
| 330 | open( my $THIS_WEEK_MOST_100_LISTENED_TO_FH, ">", "this_week_most_100_listened_to.xml" ) or confess "Can't open file: $!"; | ||
| 331 | |||
| 332 | #print highest rated videos to file in PWD. | ||
| 333 | print $THIS_WEEK_MOST_100_LISTENED_TO_FH "$this_week_most_100_listened_to_xml"; | ||
| 334 | |||
| 335 | close($THIS_WEEK_MOST_100_LISTENED_TO_FH); | ||
| 336 | |||
| 337 | # sub download_this_week_most_100_listened_to_xml(). | ||
| 338 | } | ||
| 339 | |||
| 340 | sub download_jamendo_blog_xml { | ||
| 341 | #Turn on strict and warnings. | ||
| 342 | use strict; | ||
| 343 | use warnings; | ||
| 344 | |||
| 345 | #get xml using LWP::Simple. | ||
| 346 | $jamendo_blog_xml = get $jamendo_blog_url; | ||
| 347 | |||
| 348 | #get rid of non-ascii chars. | ||
| 349 | $jamendo_blog_xml =~ s/[^[:ascii:]]+//g; | ||
| 350 | |||
| 351 | #save XML to file. | ||
| 352 | open( my $JAMENDO_BLOG_FH, ">", "jamendo_blog.xml" ) or confess "Can't open file: $!"; | ||
| 353 | |||
| 354 | #print jamendo's blog to file in PWD. | ||
| 355 | print $JAMENDO_BLOG_FH "$jamendo_blog_xml"; | ||
| 356 | |||
| 357 | close($JAMENDO_BLOG_FH); | ||
| 358 | |||
| 359 | # sub download_jamendo_blog_xml. | ||
| 360 | } | ||
| 361 | |||
| 362 | sub download_jamendo_forums_xml { | ||
| 363 | #Turn on strict and warnings. | ||
| 364 | use strict; | ||
| 365 | use warnings; | ||
| 366 | |||
| 367 | #get xml using LWP::Simple. | ||
| 368 | $jamendo_forums_xml = get $jamendo_forums_url; | ||
| 369 | |||
| 370 | #get rid of non-ascii chars. | ||
| 371 | $jamendo_forums_xml =~ s/[^[:ascii:]]+//g; | ||
| 372 | |||
| 373 | #save XML to file. | ||
| 374 | open( my $JAMENDO_FORUMS_FH, ">", "jamendo_forums.xml" ) or confess "Can't open file: $!"; | ||
| 375 | |||
| 376 | #print jamendo's forums to file in PWD. | ||
| 377 | print $JAMENDO_FORUMS_FH "$jamendo_forums_xml"; | ||
| 378 | |||
| 379 | close($JAMENDO_FORUMS_FH); | ||
| 380 | |||
| 381 | # sub download_jamendo_blog_xml. | ||
| 382 | } | ||
| 383 | |||
| 384 | sub download_jamendo_news_xml { | ||
| 385 | |||
| 386 | #Turn on strict and warnings. | ||
| 387 | use strict; | ||
| 388 | use warnings; | ||
| 389 | |||
| 390 | #get xml using LWP::Simple. | ||
| 391 | $jamendo_news_xml = get $jamendo_news_url; | ||
| 392 | |||
| 393 | #get rid of non-ascii chars. | ||
| 394 | $jamendo_news_xml =~ s/[^[:ascii:]]+//g; | ||
| 395 | |||
| 396 | #save XML to file. | ||
| 397 | open( my $JAMENDO_NEWS_FH, ">", "jamendo_news.xml" ) or confess "Can't open file: $!"; | ||
| 398 | |||
| 399 | #print jamendo news to file in PWD. | ||
| 400 | print $JAMENDO_NEWS_FH "$jamendo_news_xml"; | ||
| 401 | |||
| 402 | close($JAMENDO_NEWS_FH); | ||
| 403 | |||
| 404 | # sub download_jamendo_news_xml(). | ||
| 405 | } | ||
| 406 | |||
| 407 | # Modules must return a true value | ||
| 408 | 1; | ||