Search code examples
androidexportaudio-playerandroid-music-player

How to export a playlists Song from android to a windows PC


So I wanted to export all the songs on my phone to my PC, which were in a specific playlist in my preinstalled music player. A feature that should be integrated imho. But it is not, and because the music files are stored in many different directories, some even on the external SD card, I didn't want to do this by hand.

Googling returned nothing valuable and samsung Kies doesn't seem to offer that functionality, so I wrote myself a Batch file and thought I could share. I do so on here because people who use my file should have a basic understanding of what they are about to do, which they probably have when they are users of stackoverflow.


Solution

  • For this solution, you need adb installed.

    How to use my file:

    1. Create a file with the paths of the music

    This app does so automatically and would also allow to import playlists (without the music files). But you could also create that file by other means e.g. by hand. Make sure that each file path is on a new line. Spaces are ok.

    /storage/extSdCard/Instalok/Media__t4p3f3.mp3 /storage/extSdCard/Instalok/Media__t6p5f3.mp3 /storage/extSdCard/Instalok/Media__t8p7f3.mp3 /storage/emulated/0/books/GRETE_PAIA_San_Sebastiano.mp3 /storage/emulated/0/mp3/the prodigy - 3 kilos.m4a
    /storage/emulated/0/mp3/Mermaid.mp3

    Example file above. Call that file playlist.txt and store it on your PC next to my batch file.

    2. Make sure your phone is ready

    Connect your android phone through USB with your windows computer and open up a CMD. You may need to enable USB debugging on your phone or unlock the lockscreen and allow access. If your phone is connected, adb devices will list it up.

    3. Check the file path

    If you automatically generated your file, the path may be not the same as adb uses. In my case, adb used /mnt/sdcard while the file contained all paths to the internal sdcard as /storage/emulated/0. /storage/emulated/ existed through adb but the dir 0 did not. In My case, it worked for the external sdcard. So check your path by using adb shell and your usual means of navigating: cd and ls

    If your path is different than the one adb needs, replace it in the textfile or make use of the SEARCHTEXT REPLACETEXT option in the batch file. If you do not need my option, make sure to replace something with itself.

    4. Set your destination folder Edit the batch file and set pathname to your desired destination folder. Make sure it already exists!

    5. Testrun Store the batch file in the same directory as playlist.txt and run it. It will ask you to do a testrun. Press y and then Enter to let it display what source paths it will use. it will also check if the destination folder does exist: if it doesn't the writing will turn red. It does not check the source path though, that is your own job.

    6. Run Run it again, this time type anything except y. Then press enter. It wil run for real this time, copying the specified files into your destination folder.

    The File

    save it as something.bat

    @echo off
    REM make sure everything is set correctly
    REM playlist.txt: place a text file in the same dir as this file
    REM               and name it playlist.txt
    REM               it should contain all file paths on the phone
    REM               each path on a new line
    REM                    This can be autogenerated for a playlist by https://play.google.com/store/apps/details?id=org.ssi.playlistbackup
    REM pathname: Where should all the files be saved to
    REM SEARCHTEXT: Where the file containing all the paths says the file is
    REM REPLACETEXT: Where adb shell says the file is
    REM Make sure your destination folder at pathname already exists
    setlocal enabledelayedexpansion
    color 0f
    set pathname=F:\Files\Music
    set SEARCHTEXT=/storage/emulated/0/
    set REPLACETEXT=/mnt/sdcard/
    set /p testrun=Is this a testrun? Testrun recommended. (y/n)
    if %testrun%==y (
    
    echo Testrun
    
    for /F "tokens=*" %%A in (playlist.txt) do (
        set filename=%%~nxA
        set remotename=%%A
        REM replace the path with the path as adb uses it. 
        REM use "adb shell
        REM     >> ls   and >>cd
        REM " to find it out
        SET string=!remotename!
        set fixedremotepath=!string:%SEARCHTEXT%=%REPLACETEXT%!
    
    echo I will try to load this from !fixedremotepath!  to !pathname!/!filename!
    )
    
    echo This warning always appears in Testruns: Make sure you have set all variables as specified in the comments in this file.
    echo If the writing turns red, check your destination Path
    echo I don't check the origin paths for correctness. If they are wrong, they will be mentioned as not found.
    color 0c
    cd %pathname%
    
    ) else (
    for /F "tokens=*" %%A in (playlist.txt) do (
        set filename=%%~nxA
        set remotename=%%A
        REM replace the path with the path as adb uses it. 
        REM use "adb shell
        REM     >> ls   and >>cd
        REM " to find it out
        set SEARCHTEXT=/storage/emulated/0/
        set REPLACETEXT=/mnt/sdcard/
        SET string=!remotename!
        set fixedremotepath=!string:%SEARCHTEXT%=%REPLACETEXT%!
    
    echo I WILL load this from !fixedremotepath!  to !pathname!/!filename!
    REM ------------------------------------------------------------
    adb pull -p "!fixedremotepath!"  "!pathname!"
    REM ------------------------------------------------------------
    )
    )
    pause