Folder structure / Samsung TV

Anonymous
2012-09-24
2013-05-29

  • Anonymous
    2012-09-24

    Some people have their media files finely organized into folders and only want to browse those files the shortest / fastest way possible.

    Now some Samsung TVs don't let you simply browse a DLNA server, but instead offer you the categories (Pictures, Music, Videos) which each drop into the respective category offered by MiniDLNA. No direct browsing access there. :(

    Since those "organized" people (such as me) don't need any of the category entries other than what's in the "Folders" item, that's an unnecessary extra step to reach the media.

    The solution: this patch turns the video category into simple folder browsing mode:

    diff -ruN minidlna-1.0.25.orig/scanner.c minidlna-1.0.25/scanner.c
    --- minidlna-1.0.25.orig/scanner.c      2012-06-29 23:11:29.000000000 +0200
    +++ minidlna-1.0.25/scanner.c   2012-09-23 23:27:30.000000000 +0200
    @@ -479,7 +479,7 @@
            else if( is_video(name) )
            {
                    orig_name = strdup(name);
    -               strcpy(base, VIDEO_DIR_ID);
    +               strcpy(base, VIDEO_ID);
                    strcpy(class, "item.videoItem");
                    detailID = GetVideoMetadata(path, name);
                    if( !detailID )
    @@ -549,8 +549,6 @@
                               MUSIC_PLIST_ID, MUSIC_ID, _("Playlists"),
                                     VIDEO_ID, "0", _("Video"),
    -                            VIDEO_ALL_ID, VIDEO_ID, _("All Video"),
    -                            VIDEO_DIR_ID, VIDEO_ID, _("Folders"),
                                     IMAGE_ID, "0", _("Pictures"),
                                 IMAGE_ALL_ID, IMAGE_ID, _("All Pictures"),
    

    Pictures and Music could probably be converted easily as well.

    Another thing that irritated me was this:
    When you have several media_dirs (of the same type, videos in my case) and browse that category, contents of all the media_dirs are mixed up.

    I created another patch so it creates a folder for each media_dir and adds the contents to that instead, so it doesn't mix up anymore.
    Here you go:

    diff -ruN minidlna-1.0.25.orig/scanner.c minidlna-1.0.25/scanner.c
    --- minidlna-1.0.25.orig/scanner.c      2012-06-29 23:11:29.000000000 +0200
    +++ minidlna-1.0.25/scanner.c   2012-09-24 01:26:11.000000000 +0200
    @@ -729,6 +729,32 @@
                    return;
            DPRINTF(parent?E_INFO:E_WARN, L_SCANNER, _("Scanning %s\n"), dir);
    +
    +       if( !parent )
    +       {
    +               // This is a media_dir entry - it has no parent.
    +
    +               // Insert dir as a directory entry to the browse dir
    +               // instead of directly adding it's contents to the browse dir.
    +               startID = get_next_available_id("OBJECTS", BROWSEDIR_ID);
    +               name = escape_tag(dir, 1);
    +               insert_directory(basename(name), dir, BROWSEDIR_ID, "", startID);
    +
    +               // Now scan the dir with it's directory entry as the parent.
    +               // That way, the content will be added to the directory entry,
    +               // not the browse dir. Hence, the different media_dirs show up
    +               // as folders and the contents don't mix up.
    +               sprintf(parent_id, "$%X", startID);
    +               ScanDirectory(dir, parent_id, dir_type);
    +
    +               free(name);
    +
    +               // We can return early here since the contents of this dir
    +               // have been added now.
    +               DPRINTF(E_WARN, L_SCANNER, _("Scanning %s finished (%llu files)!\n"), dir, fileno);
    +               return;
    +       }
    +
            switch( dir_type )
            {
                    case ALL_MEDIA:
    @@ -752,11 +778,6 @@
                    return;
            }
    -       if( !parent )
    -       {
    -               startID = get_next_available_id("OBJECTS", BROWSEDIR_ID);
    -       }
    -
            for (i=0; i < n; i++)
            {
     #if !USE_FORK
    @@ -793,14 +814,7 @@
                    free(namelist[i]);
            }
            free(namelist);
    -       if( parent )
    -       {
    -               chdir(dirname((char*)dir));
    -       }
    -       else
    -       {
    -               DPRINTF(E_WARN, L_SCANNER, _("Scanning %s finished (%llu files)!\n"), dir, fileno);
    -       }
    +       chdir(dirname((char*)dir));
     }
     void
    

    Please be kind with me, I'm not so good with C so there is probably "room for improvements". :)

    Note: a rescan / rebuild of your db is required.

     

  • Anonymous
    2012-09-24

    I created a fork on github.

    I believe this is off the latest cvs. It also needed another patch to compile on older libavutil versions that don't have error.h / av_strerror().

     
  • R S
    R S
    2012-09-24

    Awesome.. I really needed the Second patch….
    So.. quick question.. How does one apply that?
    Step 1: I create a file name folderPatch
    Step 2. Insert the conttenet of the file to be what you have above
    Step 3: apply the patch? How
    Step 4: Make clean
    Step 5: Make
    Step 6: sudo make install

    can you explain how to do Step 3?

     
  • Cecil Coupe
    Cecil Coupe
    2012-09-25

    3)  use the command 'patch' to appy the patch file to the minidlna/ source directory.
    3a) read the patch manual. 'man patch'
    3b) think about what could go wrong
    3c) make backups of the source before patching
    3d) decide if you need the -p0 or -p1

     
  • peteS
    peteS
    2013-01-21

    Thank you. Nicely done.

    Actually thanks to your second patch the audio folder traversal is fine. Going to music->folders isn't that big of a deal. In a few spare minutes I tried modifying the code for audio to mirror what you did for video, but kept losing playlist functionality along the way. I guess this warrants a closer look with undivided attention, but like I said it's good enough as is.

    I don't know if UPNP supports this, but what would really be cool is being able to create playlists on the fly from the DLNA client by just browsing audio files and flagging/tagging them somehow. I'm sure most people would agree that server side static playlist creation is a real PITA. I'll take a look to see what control codes can be sent to the server. No promises though. :-)

     

  • Anonymous
    2013-03-01

    I installed minidnla in ubuntu 12.10 using a ppa.

    Can somebody explain me how to easily use this patch?

    Thanks!

     

  • Anonymous
    2013-03-25

    You need to download source and build and install from there.  If you've never done that before, you might find this link useful: https://help.ubuntu.com/community/CompilingEasyHowTo

    Once you understand that, you can download the source from the sourceforge project page.

    Good luck!

     
  • Logan007
    Logan007
    2013-05-17

    rhartman, I happened to come across your first patch… it seems we did exactly the same, independently - I also own Samsung TVs.  :)

    I found that scanner.h needs a change, too:

    #define VIDEO_ALL_ID            "2$80" // !!! was: 2$8

    Otherwise, the 7th, 8th, or 9th directory at root (one of them of which I don't remember the correct number) will not show the content you expect.