Kodi Community Forum

Full Version: Playlist.Add is adding songs twice to the queue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Adding a file to the queue using a file item parameter adds the items twice to the queue if the song has been scanned into the music database

Code:
{"id":1,"jsonrpc":"2.0","method":"Playlist.Add","params":{"item":{"file":"/media/Music/Pop/Lovebugs - In Every Waking Moment - 2006/01 - Lovebugs - Tonight.mp3"},"playlistid":0}}"

It fails in CFileItemHandler::FillFileItemList(const CVariant &parameterObject, CFileItemList &list) when doing the following check

Code:
if (list[index]->GetPath() == file)

The left side contains the resolved internal musicdb:// path and the right side the file name so it will obviously fail and add the file twice

Code:
bool CFileItemHandler::FillFileItemList(const CVariant &parameterObject, CFileItemList &list)
{
  CAudioLibrary::FillFileItemList(parameterObject, list);
  CVideoLibrary::FillFileItemList(parameterObject, list);
  CFileOperations::FillFileItemList(parameterObject, list);

  std::string file = parameterObject["file"].asString();
  if (!file.empty() && (URIUtils::IsURL(file) || (CFile::Exists(file) && !CDirectory::Exists(file))))
  {
    bool added = false;
    for (int index = 0; index < list.Size(); index++)
    {
      if (list[index]->GetPath() == file)
      {
        added = true;
        break;
      }
    }

    if (!added)
    {
      CFileItemPtr item = CFileItemPtr(new CFileItem(file, false));
      if (item->IsPicture())
      {
        CPictureInfoTag picture;
        picture.Load(item->GetPath());
        *item->GetPictureInfoTag() = picture;
      }
      if (item->GetLabel().empty())
      {
        item->SetLabel(CUtil::GetTitleFromPath(file, false));
        if (item->GetLabel().empty())
          item->SetLabel(URIUtils::GetFileName(file));
      }
      list.Add(item);
    }
  }

  return (list.Size() > 0);
}
Nice finding that explains why I get some reports of items duplication when reordering playlists.

Let's hope @DaveTBlake read this Smile

I really need to find time to upgrade to VS 2015 Sad

Git blame does not shows recent changes, do know when this started to happens ?
Yeap I'm reading, Colin thanks for the PM. I'm going to be looking at JSON and playlists soon so will keep this in mind. Meanwhile I am having a slight detour looking at smart playlist query logic.
Finally found a tool, that removed 40 GB of junk on the SSD Smile (10GB nvidia drivers, 30GB windows patches ....)

So will be able to help on the playlist part Smile
10008 (PR)

Would have been cool to have an answer on when this started to happens Wink