Sorting tvshows in smart-playlists
#1
Question 
Hello, I'm trying to use the <sorttitle> tag to specify a custom sorting for tvshows. I'm already using the same tag for movies, but it doesn't seem to work for tvshows (only in playlists, it works fine when using the standard tvshows list).
I also tried directly editing the tables in MyVideos60.db (this is what i usually do for movies btw, editing the 'c10' field): for tvshows i'm editing the c15 (as described here), but it looks like that either xbmc ignores the field or this is not the correct field..
Anyone having the same problem?
Reply
#2
My guess is the sorttitle field is hooked up only for movies. See SmartPlaylist.cpp (xbmc/playlists) and compare the movies and tvshow branches.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
Looks like the current source code already handles tvshows sorting:
Code:
else if (mediaType == MediaTypeTvShow)
  {
    CStdString result;
    if (field == FieldId) return "tvshowview.idShow";
    else if (field == FieldTitle)
    {
      // We need some extra logic to get the title value if sorttitle isn't set
      if (queryPart == DatabaseQueryPartOrderBy)
        result.Format("CASE WHEN length(tvshowview.c%02d) > 0 THEN tvshowview.c%02d ELSE tvshowview.c%02d END", VIDEODB_ID_TV_SORTTITLE, VIDEODB_ID_TV_SORTTITLE, VIDEODB_ID_TV_TITLE);
      else
        result.Format("tvshowview.c%02d", VIDEODB_ID_TV_TITLE);
    }

I guess I'll try the latest nighlty and see if it works.
Reply
#4
Uhm, just tried the latest Alpha 3, and it still does not sort tvshows in smart playlist, just in normal list.. I'll guess it's back to the source code..
Reply
#5
I think I have found the problem: the current XBMC has distinct code for loading movies/shows/etc by directory or by playlist.
When loading from smart-playlists, all items are always sort using the current sort method and order (inside CGUIMediaWindow->SortItems()): this method creates a CGUIViewState instance, whose type changes depending on the item type (movies, tvshows), and every item type has different order methods (specified in the class constructor).
The current costructor for CGUIViewStateVideoTVShows is the following:
Code:
CGUIViewStateVideoTVShows::CGUIViewStateVideoTVShows(const CFileItemList& items) : CGUIViewStateWindowVideo(items)
{
  if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
    AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS("%L", "%M", "%L", "%M"));  // Label, #Episodes | Label, #Episodes
  else
    AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%L", "%M", "%L", "%M"));  // Label, #Episodes | Label, #Episodes

  AddSortMethod(SORT_METHOD_YEAR, 562, LABEL_MASKS("%L","%Y","%L","%Y"));  // Label, Year | Label, Year

  if (items.IsSmartPlayList() || items.GetProperty("library.filter").asBoolean())
  {
    AddSortMethod(SORT_METHOD_PLAYLIST_ORDER, 559, LABEL_MASKS("%L", "%M", "%L", "%M"));  // Label, #Episodes | Label, #Episodes
    SetSortMethod(SORT_METHOD_PLAYLIST_ORDER);
  }
  else
    SetSortMethod(g_settings.m_viewStateVideoNavTvShows.m_sortMethod);

  SetViewAsControl(g_settings.m_viewStateVideoNavTvShows.m_viewMode);

  SetSortOrder(g_settings.m_viewStateVideoNavTvShows.m_sortOrder);

  LoadViewState(items.GetPath(), WINDOW_VIDEO_NAV);
}
This code sorts by label and episode count (for tvshows the label is always set to the show title, not the sort title).
So I replaced the label field with the sort title field (as in the movies class constructor):
Code:
CGUIViewStateVideoTVShows::CGUIViewStateVideoTVShows(const CFileItemList& items) : CGUIViewStateWindowVideo(items)
{
  if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
    AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 551, LABEL_MASKS("%T", "%M", "%T", "%M"));  // Title, #Episodes | Title, #Episodes
  else
    AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 551, LABEL_MASKS("%T", "%M", "%T", "%M"));  // Title, #Episodes | Title, #Episodes
  AddSortMethod(SORT_METHOD_YEAR, 562, LABEL_MASKS("%T", "%Y", "%T", "%Y"));  // Title, Year | Title, Year

  if (items.IsSmartPlayList() || items.GetProperty("library.filter").asBoolean())
  {
    AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 551, LABEL_MASKS("%T", "%M", "%T", "%M"));  // Title, #Episodes | Title, #Episodes
    SetSortMethod(SORT_METHOD_PLAYLIST_ORDER);
  }
  else
    SetSortMethod(g_settings.m_viewStateVideoNavTitles.m_sortMethod);

  SetViewAsControl(g_settings.m_viewStateVideoNavTvShows.m_viewMode);

  SetSortOrder(g_settings.m_viewStateVideoNavTvShows.m_sortOrder);

  LoadViewState(items.GetPath(), WINDOW_VIDEO_NAV);
}

This way XBMC uses the sort title for tvshows too.
I tried on my computer and tvshows are correctly sorted by sorttitle even inside playlists.
Is this ok for a commit?
Reply
#6
Sure - please do a pull req on github.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#7
Funnily enough, I ran into this problem today, with some old tv shows
eg. Flash Gordon Trip to Mars, Flash Gordon Conquers the universe
I added a sorttitle of FlashGordon (1938) to the first and Flash Gordon (1940) to the second, but it didnt work, now I know why.

Hopefully this will be fixed soon.
Reply

Logout Mark Read Team Forum Stats Members Help
Sorting tvshows in smart-playlists0