diff --git a/images/podcast_16x16.png b/images/podcast_16x16.png new file mode 100755 index 0000000..e0e1d2c Binary files /dev/null and b/images/podcast_16x16.png differ diff --git a/index.html b/index.html old mode 100644 new mode 100755 index 516d933..655e31c --- a/index.html +++ b/index.html @@ -38,6 +38,7 @@ +
+
+ + + +
+
+
+
+
+
+
+
+
  • Podcasts
+
    +
    +
    + + + +
    +
    +
    Reset diff --git a/js/app.js b/js/app.js old mode 100644 new mode 100755 index 32a22f8..ca36046 --- a/js/app.js +++ b/js/app.js @@ -85,6 +85,10 @@ function loadTabContent(tab) { if (debug) { console.log("TAG PLAYLIST"); } loadPlaylists(); break; + case '#tabPodcasts': + if (debug) { console.log("TAG PODCAST"); } + loadPodcasts(); + break; case '#tabPreferences': break; default: diff --git a/js/libs/api.js b/js/libs/api.js old mode 100644 new mode 100755 index 92f1916..91166ed --- a/js/libs/api.js +++ b/js/libs/api.js @@ -688,3 +688,117 @@ function getPlaylist(id, action, appendto) { } }); } + +function loadPodcasts(refresh) { + if (debug) { console.log("LOAD PODCASTS"); } + if (refresh) { + $('#ChannelsContainer').empty(); + } + var content = $('#ChannelsContainer').html(); + if (content === "") { + // Load Podcasts + $.ajax({ + url: baseURL + '/getPodcasts.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp', + method: 'GET', + dataType: 'jsonp', + timeout: 10000, + success: function (data) { + var playlists = []; + if (data["subsonic-response"].podcasts.channel.length > 0) { + podcasts = data["subsonic-response"].podcasts.channel; + } else { + podcasts[0] = data["subsonic-response"].podcasts.channel; + } + $.each(podcasts, function (i, podcast) { + var albumId = (podcast.episode === undefined || podcast.episode.length <= 0) ? "0" : podcast.episode[0].parent; + + var html = ""; + html += '
  • '; + html += '' + podcast.title + ''; + html += '
    '; + html += '
    '; + html += '
    '; + html += '
  • '; + $(html).appendTo("#ChannelsContainer"); + }); + } + }); + } +} +function getPodcast(id, action, appendto) { + $.ajax({ + url: baseURL + '/getPodcasts.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp', + method: 'GET', + dataType: 'jsonp', + timeout: 10000, + success: function (data) { + var channels = data["subsonic-response"].podcasts.channel; + + // we hope that the result is ordered by id + var channel = channels[id - 1]; + + if(channel === undefined || channel.id != id){ + // sometimes we have to do some extra work. + for (var i = 0; i < channels.length; i++) { + if(podcasts[i].id == id) + { + channel = channels[i]; + break; + } + } + } + + if (channel.episode !== undefined) { + if (appendto === '#PodcastContainer tbody') { + $(appendto).empty(); + var header = generatePodcastHeaderHTML(); + $("#PodcastContainer thead").html(header); + } + if (action === 'autoplay') { + $(appendto).empty(); + } + + var children = channel.episode; + + var rowcolor; + var html; + var count = children.length; + $.each(children, function (i, child) { + + if(child.status == "skipped") return; // Skip podcasts that are not yet downloaded + + if (i % 2 === 0) { + rowcolor = 'even'; + } else { + rowcolor = 'odd'; + } + var date = parseDate(child.publishDate); + + var time = secondsToTime(child.duration); + html = generatePodcastHTML(rowcolor, child.streamId, child.parent, date, child.title, child.artist, child.album, child.coverArt, child.userRating, time['m'], time['s']); + $(html).appendTo(appendto); + }); + updateMessage(count + ' Songs'); + if (appendto === '#CurrentPlaylistContainer tbody') { + updateMessage(children.length + ' Song(s) Added'); + } + if (action === 'autoplay') { + autoPlay(); + } + } else { + if (appendto === '#PodcastContainer tbody') { + $(appendto).empty(); + } + } + } + }); +} +function parseDate(date) { + // input: "2012-09-23 20:00:00.0" + var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; + var parts = date.split(" "); + var dateParts = parts[0].split("-"); + var month = parseInt(dateParts[1], 10) - 1; + var date = months[month] + " " + dateParts[2] + ", " + dateParts[0]; + return date; +} diff --git a/js/libs/generators.js b/js/libs/generators.js old mode 100644 new mode 100755 index 28be025..9c0ea59 --- a/js/libs/generators.js +++ b/js/libs/generators.js @@ -57,7 +57,33 @@ function generateSongHTML(rowcolor, childid, parentid, track, title, artist, alb html += ''; return html; } - +function generatePodcastHeaderHTML() { + var html; + html = 'PublishedTitleArtistAlbumTime'; + return html; +} +function generatePodcastHTML(rowcolor, childid, parentid, published, title, artist, album, coverart, rating, m, s) { + var html; + html = ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += '' + published + ''; + html += '' + title + ''; + html += '' + artist + ''; + var coverartSrc; + if (coverart == undefined) { + coverartSrc = 'images/albumdefault_25.jpg'; + } else { + coverartSrc = baseURL + '/getCoverArt.view?v=' + version + '&c=' + applicationName + '&f=jsonp&size=25&id=' + coverart; + } + html += '' + album + ''; + html += '' + m + ':' + s + ''; + html += ''; + return html; +} function refreshRowColor(el) { $.each($(el + ' tr.song'), function (i) { $(this).removeClass('even odd'); diff --git a/js/ui-load.js b/js/ui-load.js old mode 100644 new mode 100755 index d594760..c0b86c2 --- a/js/ui-load.js +++ b/js/ui-load.js @@ -46,7 +46,7 @@ function resizeContent() { } } var tabwidth = $('.tabcontent').width(); - $('#AlbumContainer, #TrackContainer, #CurrentPlaylistContainer').css({ 'width': (tabwidth - smwidth - 30) + 'px' }); + $('#AlbumContainer, #TrackContainer, #PodcastContainer, #CurrentPlaylistContainer').css({ 'width': (tabwidth - smwidth - 30) + 'px' }); $('#CurrentPlaylistContainer').css({ 'width': (tabwidth - 30) + 'px' }); $('#player').css({ 'width': tabwidth + 'px' }); } @@ -63,5 +63,6 @@ function resizeSMSection(x) { var ulwidth = newsmwidth + 6; $('#AlbumContainer').css({ 'margin-left': ulwidth + 'px' }); $('#TrackContainer').css({ 'margin-left': ulwidth + 'px' }); + $('#PodcastContainer').css({ 'margin-left': ulwidth + 'px' }); } -} \ No newline at end of file +} diff --git a/js/ui-ready.js b/js/ui-ready.js old mode 100644 new mode 100755 index a0fc391..bfa4870 --- a/js/ui-ready.js +++ b/js/ui-ready.js @@ -339,6 +339,14 @@ resizeSMSection(-50); return false; }); + $('#action_IncreaseWidthPodcasts').click(function () { + resizeSMSection(50); + return false; + }); + $('#action_DecreaseWidthPodcasts').click(function () { + resizeSMSection(-50); + return false; + }); $('#action_SelectAll').click(function () { $('#Albums tr.song').each(function () { $(this).addClass('selected'); @@ -434,6 +442,29 @@ getPlaylist($(this).parent().parent().attr("id"), '', '#CurrentPlaylistContainer tbody'); return false; }); + $('#ChannelsContainer li.item').live('click', function () { + $('#AutoChannelsContainer li').removeClass('selected'); + $('#ChannelsContainer li').removeClass('selected'); + $(this).addClass('selected'); + getPodcast($(this).attr("id"), '', '#PodcastContainer tbody'); + }); + $('#ChannelsContainer li.item a.play').live('click', function () { + getPodcast($(this).parent().parent().attr("id"), 'autoplay', '#CurrentPlaylistContainer tbody'); + return false; + }); + $('#ChannelsContainer li.item a.download').live('click', function (event) { + var itemid = $(this).parent().parent().attr('albumid'); + downloadItem(itemid, 'item'); + return false; + }); + $('#ChannelsContainer li.item a.add').live('click', function () { + getPodcast($(this).parent().parent().attr("id"), '', '#CurrentPlaylistContainer tbody'); + return false; + }); + $('#action_RefreshPodcasts').click(function () { + loadPodcasts(true); + return false; + }); $('#action_RefreshPlaylists').click(function () { loadPlaylists(true); return false; @@ -653,4 +684,4 @@ } }).disableSelection(); -}); // End document.ready \ No newline at end of file +}); // End document.ready diff --git a/style/Style.css b/style/Style.css old mode 100644 new mode 100755 index 0635f55..bbdd38e --- a/style/Style.css +++ b/style/Style.css @@ -313,7 +313,7 @@ ul.mainlist li.item a.add:hover { margin: 5px 5px 5px 206px; } -#TrackContainer +#TrackContainer, #PodcastContainer { margin: 5px 5px 5px 206px; } @@ -471,6 +471,10 @@ table.songlist tr.song td.track width: 40px; text-align: right; } +table.songlist tr.song td.published +{ + width: 80px; +} table.songlist tr.song td.title { } @@ -1154,4 +1158,4 @@ fieldset legend { font-size: 12px; -} \ No newline at end of file +}