From 4772a69dc3cc9e0d33fabc507495c8d2b342d329 Mon Sep 17 00:00:00 2001 From: Niall Smart Date: Wed, 22 Dec 2010 17:42:30 -0800 Subject: [PATCH 1/3] Add scrapers for Rdio/MOG/YouTube. --- scrapers/mog.com.js | 27 +++++++++++++++++++++++++++ scrapers/rdio.com.js | 38 ++++++++++++++++++++++++++++++++++++++ scrapers/youtube.com.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 scrapers/mog.com.js create mode 100644 scrapers/rdio.com.js create mode 100644 scrapers/youtube.com.js diff --git a/scrapers/mog.com.js b/scrapers/mog.com.js new file mode 100644 index 0000000..094549b --- /dev/null +++ b/scrapers/mog.com.js @@ -0,0 +1,27 @@ +/** + * MOG.com Playgrub Scraper + * Created by: Niall Smart + * Version: 0.1 + * + * Notes: + * + * This scraper will work on MOG.com playlist pages. + */ +Playgrub.source.url = 'http://.*\.mog.com.*'; +Playgrub.source.error = 'Check your MOG page - only playlist pages are supported.' +Playgrub.source.scrape = function() { + + $(".song-title").each(function() { + var artist = $(this).find('a:last-child').text(); + var song = $(this).find('a:first-child').text(); + + artist = $.trim(artist); + song = $.trim(song); + + if (artist && song) { + Playgrub.playlist.add_track(artist, song); + } + }); +} + +Playgrub.source.start(); diff --git a/scrapers/rdio.com.js b/scrapers/rdio.com.js new file mode 100644 index 0000000..383c8b8 --- /dev/null +++ b/scrapers/rdio.com.js @@ -0,0 +1,38 @@ +/** + * Rdio.com Playgrub Scraper + * Created by: Niall Smart + * Version: 0.1 + * + * Notes: + * + * This scraper will work on Rdio.com artist/album/playlist pages. + */ +Playgrub.source.url = 'http://.*\.rdio.com.*'; +Playgrub.source.error = 'Check your Rdio page - only artist, album and playlist pages are supported.' +Playgrub.source.scrape = function() { + + var albumArtist; + var ah = $("div.album_header"); + + if (ah.size() > 0) { + albumArtist = ah.find("a.mini_header").text(); + } + + $("div.track").each(function() { + var artist = $(this).find('div.album_info > a:first-child').text(); + var song = $(this).find('div.title_info').text(); + + if (!artist) { + artist = albumArtist; + } + + artist = $.trim(artist); + song = $.trim(song); + + if (artist && song) { + Playgrub.playlist.add_track(artist, song); + } + }); +} + +Playgrub.source.start(); diff --git a/scrapers/youtube.com.js b/scrapers/youtube.com.js new file mode 100644 index 0000000..f8fc673 --- /dev/null +++ b/scrapers/youtube.com.js @@ -0,0 +1,33 @@ +/** + * YouTube.com Playgrub Scraper + * Created by: Niall Smart + * Version: 0.1 + * + * Notes: + * + * This scraper will work on YouTube Disco and YouTube playlist pages (in "Play All" mode) + */ +Playgrub.source.url = 'http://.*\.youtube.com.*'; +Playgrub.source.error = 'Check your YouTube page - only YouTube Disco/playlist playback pages are supported.' +Playgrub.source.scrape = function() { + + var quicklist = $("#quicklist"); + + if (quicklist.size() == 0) { + return; + } + + quicklist.find("ol.video-list li.quicklist-item").each(function() { + var title = $(this).find("span.title > span").clone(); + title.children().remove(); + title = title.text().split(" - "); + var artist = title[0]; + var song = title[1]; + + if (artist && song) { + Playgrub.playlist.add_track(artist, song); + } + }); +} + +Playgrub.source.start(); From 32c7bb621aea00f563247689e7593ec44c7d3481 Mon Sep 17 00:00:00 2001 From: Niall Smart Date: Wed, 31 Aug 2011 15:10:12 -0700 Subject: [PATCH 2/3] Update YouTube scraper to support latest default and "Cosmic Panda" markup. --- scrapers/youtube.com.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scrapers/youtube.com.js b/scrapers/youtube.com.js index f8fc673..d3f5c41 100644 --- a/scrapers/youtube.com.js +++ b/scrapers/youtube.com.js @@ -8,26 +8,26 @@ * This scraper will work on YouTube Disco and YouTube playlist pages (in "Play All" mode) */ Playgrub.source.url = 'http://.*\.youtube.com.*'; -Playgrub.source.error = 'Check your YouTube page - only YouTube Disco/playlist playback pages are supported.' +Playgrub.source.error = 'Check YouTube page - no playlist found.' Playgrub.source.scrape = function() { - var quicklist = $("#quicklist"); - - if (quicklist.size() == 0) { - return; - } - - quicklist.find("ol.video-list li.quicklist-item").each(function() { - var title = $(this).find("span.title > span").clone(); - title.children().remove(); - title = title.text().split(" - "); + var addByTitle = function(title) { + var title = $(this).attr("title").split(" - ") var artist = title[0]; var song = title[1]; if (artist && song) { Playgrub.playlist.add_track(artist, song); } - }); + } + + /* regular playlist */ + + $("#playlist-bar .playlist-bar-item a[title]").each(addByTitle); + + /* cosmic panda playlist */ + + $("#watch-tray-playlist .watch-tray-playlist-item a[title]").each(addByTitle); } Playgrub.source.start(); From 8ecf6e74b8075985a901e62f9247ca6b7b9c4908 Mon Sep 17 00:00:00 2001 From: Niall Smart Date: Wed, 31 Aug 2011 15:12:38 -0700 Subject: [PATCH 3/3] fix whitespace --- scrapers/youtube.com.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scrapers/youtube.com.js b/scrapers/youtube.com.js index d3f5c41..1bc0951 100644 --- a/scrapers/youtube.com.js +++ b/scrapers/youtube.com.js @@ -11,7 +11,7 @@ Playgrub.source.url = 'http://.*\.youtube.com.*'; Playgrub.source.error = 'Check YouTube page - no playlist found.' Playgrub.source.scrape = function() { - var addByTitle = function(title) { + var addByTitle = function(title) { var title = $(this).attr("title").split(" - ") var artist = title[0]; var song = title[1]; @@ -19,7 +19,7 @@ Playgrub.source.scrape = function() { if (artist && song) { Playgrub.playlist.add_track(artist, song); } - } + } /* regular playlist */