Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Bash scripting with mtp-tools

  1. #1
    Join Date
    Nov 2010
    Beans
    44
    Distro
    Ubuntu 10.04 Lucid Lynx

    Bash scripting with mtp-tools

    In lack of compatible software for an old MP3 player like mine (I've tried it all), I'm writing my own bash scripts for transfering playlists. I got libmtp/mtp-tools, and the commands work perfectly, but are difficult to implement in a script.

    For example, mtp-newfolder, upon completion, outputs something like this:
    Code:
    libmtp version: 1.3.3
    
    New folder ID: 43722
    And I want the ID for subsequent commands. After hours of painstaking testing with sed and grep, I gave up and succeded to obtain the ID using this script:
    Code:
        oput=`mtp-newfolder ${gFolder} ${ind_music} 0`
        oput=${oput//[a-zA-Z]/ }
        set -- $oput
        folder_ID=$4
    The output of the other tools make this method hard, if not impossible, and I don't like doing it this way. Now, I'm an amateur at most of this scripting, but I have two hopes in mind:

    A) Somewhere, someplace, the ID is actually sent alone, and I can fetch it if only I know where to look.
    B) I can rewrite the mtp-tools and change the output, or write my own that work as I wish. I know C, so I should manage this if only I knew how.

  2. #2
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Bash scripting with mtp-tools

    If I have understood your requirement clearly , you want to extract ID from the below output .

    Code:
    libmtp version: 1.3.3
    
    New folder ID: 43722
    try this below commandline .

    Code:
    echo 'libmtp version: 1.3.3\
    > New folder ID: 43722' | awk -F":" '/ID/{print $2}'
    Last edited by codemaniac; July 19th, 2012 at 01:39 PM.
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  3. #3
    Join Date
    Nov 2010
    Beans
    44
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Bash scripting with mtp-tools

    Thank you, I am still considering this kind of method. However, I run into problems with the following output, from mtp-sendtr:

    libmtp version: 1.1.3 /home/cerapter/Musikk/Roteskuff/Hayley Westenra - Listen To The Wind.mp3,/Music/07.19 World collide/Hayley Westenra - Listen To The Wind.mp3,Hayley Westenra,(null),Listen to the Wind,(null),(null),(null),00,0,0,1 Sending track /home/cerapter/Musikk/Roteskuff/Hayley Westenra - Listen To The Wind.mp3 to /Music/07.19 World collide/Hayley Westenra - Listen To The Wind.mp3 type: mp3, 2 Sending track: Codec: ISO MPEG-1 Audio Layer 3 Title: Listen to the Wind Artist: Hayley Westenra Storage ID: 0 Sending track... New track ID: 1475434407225 (100%)
    Where I wish to extract the ID, which I know (from later testing) to be only 147543. Here it is merged with the filesize in bytes, and both ID and this size can be any number of numerals!

    So I'm primarily looking for a way of manipulating the tools themselves, to give the output I want.

  4. #4
    Join Date
    Feb 2006
    Beans
    1,086
    Distro
    Ubuntu Gnome

    Re: Bash scripting with mtp-tools

    Have you tried playedit? You can install it by adding the ppa with
    Code:
    sudo add-apt-repository ppa:glennric/mtp
    I had a similar problem with an mp3 player that used the mtp protocol and so I wrote this program to create and edit playlists on the device. I can't guarantee it will work for your mp3 player, but if it does it may make things easier for you. Please let me know if you try it, and if it works or not.

  5. #5
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Bash scripting with mtp-tools

    Quote Originally Posted by Cerapter View Post
    Thank you, I am still considering this kind of method. However, I run into problems with the following output, from mtp-sendtr:

    Where I wish to extract the ID, which I know (from later testing) to be only 147543. Here it is merged with the filesize in bytes, and both ID and this size can be any number of numerals!

    So I'm primarily looking for a way of manipulating the tools themselves, to give the output I want.
    The output you have shared is not in a standard format for a Unix filter or text processing Utility to be parsed as per wish.

    Can you please post a screenshot of your terminal , to understand the output layout better .I think the text you have posted above is wrapped up .
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  6. #6
    Join Date
    Nov 2010
    Beans
    44
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Bash scripting with mtp-tools

    Quote Originally Posted by glennric View Post
    Have you tried playedit?
    I have tried my luck with playedit, and I'm willing to give it another try. I've been unable to install it correctly, because I cannot figure out how to meet this dependency:
    Code:
    checking for GUDEV... no
    configure: error: Package requirements (gudev-1.0) were not met:
    
    No package 'gudev-1.0' found
    
    Consider adjusting the PKG_CONFIG_PATH environment variable if you
    installed software in a non-standard prefix.
    
    Alternatively, you may set the environment variables GUDEV_CFLAGS
    and GUDEV_LIBS to avoid the need to call pkg-config.
    See the pkg-config man page for more details.
    I cannot seem to find this gudev-package (I'm on Precise). I do have gir1.2-gudev-1.0, and this might do, but I'm not sure how to define this for playedit.

    ---

    Quote Originally Posted by codemaniac View Post
    The output you have shared is not in a standard format for a Unix filter or text processing Utility to be parsed as per wish.

    Can you please post a screenshot of your terminal , to understand the output layout better .I think the text you have posted above is wrapped up .
    In the terminal, the output continually updates with the progress of the file transfer:

    What I posted was the value I got when I tried to catch the output in this way:
    Code:
    oput=$(mtp-sendtr <args>)
    ---

    I have downloaded libmtp-dev and found the original C code of the mtp-tools. I will attempt to modify, compile and run these to see if that works. EDIT: I might have been wrong about this, I have been unable to compile these files, and I also can't seem to understand how to get at the source code, either.
    Last edited by Cerapter; July 21st, 2012 at 08:57 AM.

  7. #7
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash scripting with mtp-tools

    use [code][/code] tags to preserve formatting
    what happens when you echo "$oput"? is id on a separate line?
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  8. #8
    Join Date
    Feb 2006
    Beans
    1,086
    Distro
    Ubuntu Gnome

    Re: Bash scripting with mtp-tools

    Quote Originally Posted by Cerapter View Post
    I have tried my luck with playedit, and I'm willing to give it another try. I've been unable to install it correctly, because I cannot figure out how to meet this dependency:
    [CODE]checking for GUDEV... no
    configure: error: Package requirements (gudev-1.0) were not met:

    No package 'gudev-1.0' found

    I cannot seem to find this gudev-package (I'm on Precise). I do have gir1.2-gudev-1.0, and this might do, but I'm not sure how to define this for playedit.
    The correct package is libgudev-1.0-dev. However, you do not need to compile it. If you add the repository ppa:glennric/mtp that I mentioned before you can simply install it with "sudo apt-get install playedit" (or use the software center).

  9. #9
    Join Date
    Nov 2010
    Beans
    44
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Bash scripting with mtp-tools

    Quote Originally Posted by Vaphell View Post
    use tags to preserve formatting
    what happens when you echo "$oput"? is id on a separate line?
    Unfortunately, it is not, and this is why I used the quote tag:
    Code:
    libmtp version: 1.1.3 /home/cerapter/Musikk/Roteskuff/Hayley Westenra -  Listen To The Wind.mp3,/Music/07.19 World collide/Hayley Westenra -  Listen To The Wind.mp3,Hayley Westenra,(null),Listen to the  Wind,(null),(null),(null),00,0,0,1 Sending track  /home/cerapter/Musikk/Roteskuff/Hayley Westenra - Listen To The Wind.mp3  to /Music/07.19 World collide/Hayley Westenra - Listen To The Wind.mp3  type: mp3, 2 Sending track: Codec: ISO MPEG-1 Audio Layer 3 Title:  Listen to the Wind Artist: Hayley Westenra Storage ID: 0 Sending  track...  New track ID: 1475434407225 (100%)
    ---
    Quote Originally Posted by glennric View Post
    The correct package is libgudev-1.0-dev. However, you do not need to compile it. If you add the repository ppa:glennric/mtp that I mentioned before you can simply install it with "sudo apt-get install playedit" (or use the software center).
    That's great news! I successfully installed playedit, started it, and it was about to load up my music player when this happened:
    Code:
    cerapter@Ancalagon:~$ playedit
    Device 0 (VID=041e and PID=4162) is a Creative ZEN X-Fi.
    terminate called after throwing an instance of 'Gdk::PixbufError'
    Aborted (core dumped)
    cerapter@Ancalagon:~$
    I can try and access the core dump if there's anything useful there.

  10. #10
    Join Date
    Feb 2006
    Beans
    1,086
    Distro
    Ubuntu Gnome

    Re: Bash scripting with mtp-tools

    Quote Originally Posted by Cerapter View Post
    That's great news! I successfully installed playedit, started it, and it was about to load up my music player when this happened:
    Code:
    cerapter@Ancalagon:~$ playedit
    Device 0 (VID=041e and PID=4162) is a Creative ZEN X-Fi.
    terminate called after throwing an instance of 'Gdk::PixbufError'
    Aborted (core dumped)
    cerapter@Ancalagon:~$
    I can try and access the core dump if there's anything useful there.
    Hmm, that is odd. Yeah, if you can send me the core dump it would help. It seems to be having a problem loading album art from the device.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •