Permalink
Browse files

Merge pull request #13 from botho/master

Add recently added sorting & Add last updated date time in the footer

Please note: active development has moved to the v2 branch. I am including this pull as several people have expressed a desire for similar functionality.
Thanks botho!
  • Loading branch information...
2 parents d2c0464 + 7115986 commit 9ed857bc47d568a7ccf42dfa8e20119dbca24683 @Dachande663 committed Jul 19, 2011
Showing with 17 additions and 4 deletions.
  1. +5 −0 assets/js/plex.js
  2. +10 −3 cli.php
  3. +2 −1 index.html
View
@@ -16,6 +16,7 @@ var PLEX = {
filter_timeout: false,
filter_delay: 350,
popup_visible: false,
+ last_updated: "none",
load_data: function(aData) {
@@ -25,6 +26,7 @@ var PLEX = {
});
PLEX.total_items = aData.total_items;
PLEX.section_display_order = aData.section_display_order;
+ PLEX.last_updated = aData.last_updated;
PLEX.data_loaded = true;
}, // end func: load_data
@@ -326,6 +328,7 @@ var PLEX = {
switch(arg_new_sort_key) {
case "release": new_sort_key = "release"; break;
case "rating": new_sort_key = "rating"; break;
+ case "addedAt": new_sort_key = "addedAt"; break;
}
if(new_sort_key == PLEX.current_sort_key) {
@@ -526,6 +529,7 @@ var PLEX = {
}
PLEX._total_items = $("#total_items");
+ PLEX._last_updated = $("#last_updated");
PLEX._sections_list = $("#plex_section_list");
PLEX._sorts_list = $("#plex_sort_list");
PLEX._genre_list_section = $("#plex_genre_list_section").hide();
@@ -543,6 +547,7 @@ var PLEX = {
PLEX._popup_container = $("#popup-container");
PLEX._total_items.text(number_format(PLEX.total_items));
+ PLEX._last_updated.text(PLEX.last_updated);
PLEX.display_sections_list();
$("li", PLEX._sections_list).click(function(){
View
13 cli.php
@@ -106,7 +106,7 @@
plex_log('Analysing media items in section...');
- $sorts_title = $sorts_release = $sorts_rating = array();
+ $sorts_title = $sorts_release = $sorts_rating = $sorts_added_at = array();
$raw_section_genres = array();
foreach($items as $key=>$item) {
@@ -120,24 +120,27 @@
}
}
$sorts_title[$key] = $title_sort;
-
$sorts_release[$key] = @strtotime($item['release_date']);
$sorts_rating[$key] = ($item['user_rating'])?$item['user_rating']:$item['rating'];
if(is_array($item['genre']) and count($item['genre'])>0) {
foreach($item['genre'] as $genre) {
$raw_section_genres[$genre]++;
}
}
+ $sorts_added_at[$key] = $item['addedAt'];
} // end foreach: $items (for sorting)
asort($sorts_title, SORT_STRING);
asort($sorts_release, SORT_NUMERIC);
+ asort($sorts_added_at, SORT_NUMERIC);
asort($sorts_rating, SORT_NUMERIC);
$sorts['title_asc'] = array_keys($sorts_title);
$sorts['release_asc'] = array_keys($sorts_release);
+ $sorts['addedAt_asc'] = array_keys($sorts_added_at);
$sorts['rating_asc'] = array_keys($sorts_rating);
$sorts['title_desc'] = array_reverse($sorts['title_asc']);
$sorts['release_desc'] = array_reverse($sorts['release_asc']);
+ $sorts['addedAt_desc'] = array_reverse($sorts['addedAt_asc']);
$sorts['rating_desc'] = array_reverse($sorts['rating_asc']);
$section_genres = array();
@@ -170,6 +173,7 @@
'status' => 'success',
'version' => $plex_export_version,
'last_generated' => time()*1000,
+ 'last_updated' => 'last updated : '.date('Y-m-d - H:i',time()),
'total_items' => $total_items,
'num_sections' => $num_sections,
'section_display_order' => $section_display_order,
@@ -239,13 +243,14 @@ function load_data_for_movie($el) {
'user_rating' => ($_el->userRating)?floatval($_el->userRating):false,
'release_year' => ($_el->year)?intval($_el->year):false,
'release_date' => ($_el->originallyAvailableAt)?strval($_el->originallyAvailableAt):false,
+ 'addedAt' => false,
'content_rating' => ($_el->contentRating)?strval($_el->contentRating):false,
'summary' => ($_el->summary)?strval($_el->summary):false,
'studio' => ($_el->studio)?strval($_el->studio):false,
'genre' => false,
'director' => false,
'role' => false,
- 'media' => false,
+ 'media' => false
);
$media_el = $el->Media->attributes();
@@ -288,6 +293,8 @@ function load_data_for_movie($el) {
foreach($xml->Video->Role as $role) $roles[] = strval($role->attributes()->tag);
if(count($roles)>0) $item['role'] = $roles;
+ $item['addedAt']=intval($xml->Video->attributes()->addedAt);
+
return $item;
} // end func: load_data_for_movie
View
@@ -43,6 +43,7 @@
<li class="current" data-sort="title"><em>asc</em>By title</li>
<li data-sort="rating">By rating</li>
<li data-sort="release">By release date</li>
+ <li data-sort="addedAt">By recently added</li>
</ul>
</div><!-- end .sidebar-section -->
@@ -85,7 +86,7 @@
</div><!-- end #main -->
<div id="footer">
- <p><a href="http://l0ke.com/bl">Plex</a> + <a href="http://l0ke.com/bb">Plex Export</a></p>
+ <p><a href="http://l0ke.com/bl">Plex</a> + <a href="http://l0ke.com/bb">Plex Export</a><span id="last_updated"></span></p>
</div><!-- end #footer -->
</div><!-- end #container -->

0 comments on commit 9ed857b

Please sign in to comment.