"use strict";

var $        = require("jquery");
var Plugin   = require("../modules/Plugin");
var Utils    = require("../modules/Utilities");
var bandcamp = Object.create(Plugin);

bandcamp.init("bandcamp", "Bandcamp");

bandcamp.scrape = function () {
    var discover, info, isTrack, isAlbum, pageTitle;

    discover = window.location.hash === "#discover";
    isTrack = window.location.pathname.split("/")[1] === "track";
    isAlbum = window.location.pathname.split("/")[1] === "album";

    info = {
        stopped: !$(".inline_player .playbutton").hasClass("playing")
    };

    if (!info.stopped) {

        if (discover) {
            info.artist = $("#detail_body_container .itemsubtext a").text();
        } else {
            info.artist = $("span[itemprop=byArtist]").text();
        }

        if (isTrack) {
            info.album = $("#name-section h3 span a span").text();
        } else if (isAlbum) {
            info.album = $("#name-section > h2").text().trim();
        } else if (discover) {
            info.album = $("div.itemtext a").filter(function (i, e) { 
                return e.href.match(/album/)}).text().trim();
        }

        info.title    = $(".track_info .title").first().text();
        info.duration = Utils.calculateDuration($(".inline_player .track_info .time_total").text());
        info.elapsed  = Utils.calculateDuration($(".inline_player .track_info .time_elapsed").text());

        if (!info.title) {
            info.title = $(".trackTitle").first().text();
        }
    }

    return info;
};

module.exports = bandcamp;
@@ -6,17 +6,19 @@
 strict%22;
-%0A
+%0D%0A%0D
 %0Avar $  
@@ -43,16 +43,17 @@
 query%22);
+%0D
 %0Avar Plu
@@ -89,16 +89,17 @@
 lugin%22);
+%0D
 %0Avar Uti
@@ -138,16 +138,17 @@
 ities%22);
+%0D
 %0Avar ban
@@ -177,17 +177,19 @@
 Plugin);
-%0A
+%0D%0A%0D
 %0Abandcam
@@ -219,17 +219,19 @@
 dcamp%22);
-%0A
+%0D%0A%0D
 %0Abandcam
@@ -254,16 +254,17 @@
 ion () %7B
+%0D
 %0A    var
@@ -300,21 +300,12 @@
 lbum
-, pageTitle;%0A
+;%0D%0A%0D
 %0A   
@@ -353,16 +353,17 @@
 scover%22;
+%0D
 %0A    isT
@@ -420,16 +420,17 @@
 %22track%22;
+%0D
 %0A    isA
@@ -487,17 +487,19 @@
 %22album%22;
-%0A
+%0D%0A%0D
 %0A    inf
@@ -503,16 +503,17 @@
 info = %7B
+%0D
 %0A       
@@ -578,16 +578,19 @@
 ng%22)
+%0D
 %0A    %7D;
-%0A
+%0D%0A%0D
 %0A   
@@ -610,17 +610,19 @@
 opped) %7B
-%0A
+%0D%0A%0D
 %0A       
@@ -629,32 +629,33 @@
  if (discover) %7B
+%0D
 %0A            inf
@@ -707,32 +707,33 @@
 text a%22).text();
+%0D
 %0A        %7D else 
@@ -733,16 +733,17 @@
 %7D else %7B
+%0D
 %0A       
@@ -789,32 +789,33 @@
 rtist%5D%22).text();
+%0D
 %0A        %7D%0A%0A    
@@ -800,33 +800,35 @@
 xt();%0D%0A        %7D
-%0A
+%0D%0A%0D
 %0A        if (isT
@@ -834,16 +834,17 @@
 Track) %7B
+%0D
 %0A       
@@ -894,32 +894,33 @@
 a span%22).text();
+%0D
 %0A        %7D else 
@@ -933,16 +933,17 @@
 Album) %7B
+%0D
 %0A       
@@ -990,32 +990,33 @@
 ).text().trim();
+%0D
 %0A        %7D else 
@@ -1030,16 +1030,17 @@
 cover) %7B
+%0D
 %0A       
@@ -1102,16 +1102,17 @@
 i, e) %7B 
+%0D
 %0A       
@@ -1165,16 +1165,17 @@
 .trim();
+%0D
 %0A       
@@ -1172,25 +1172,27 @@
 ;%0D%0A        %7D
-%0A
+%0D%0A%0D
 %0A        inf
@@ -1235,32 +1235,33 @@
 .first().text();
+%0D
 %0A        info.du
@@ -1345,16 +1345,17 @@
 text());
+%0D
 %0A       
@@ -1449,17 +1449,19 @@
 text());
-%0A
+%0D%0A%0D
 %0A       
@@ -1479,16 +1479,17 @@
 title) %7B
+%0D
 %0A       
@@ -1538,16 +1538,17 @@
 .text();
+%0D
 %0A       
@@ -1553,15 +1553,18 @@
    %7D
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A   
@@ -1580,12 +1580,15 @@
 nfo;
+%0D
 %0A%7D;
-%0A
+%0D%0A%0D
 %0Amod

remove unused pageTitle variable