Archive for the ‘libmtp’ Category

New-Old Laptop Update – 20091106

November 6, 2009

I looked at Distrowatch to see what was happening with various distros and downloaded a few ISOs. Among the candidates for my new-old laptop were Debian (Xfce/lxde), OpenBSD 4.6, Slackware 13, and Mandriva-One KDE 2010. I narrowed it down after a little thinking and only burned the images for Slackware and OpenBSD. I was open to looking at KDE on this and wish I could live with it, but I think I’ll be happier without it.

I decided to install Slackware 13 on my laptop yesterday afternoon and did some minor tweaking and configuration while I watched Survivor. I only burned the first two images because I didn’t want to use KDE, but I did go ahead and install Xfce as my only desktop. I may eventually change that to either ion3 or ratpoison even though I have a lot more room on my desktop now (17″). 

In addition to installing Adobe Flash and something else I won’t mention, I compiled the most recent release of GNU emacs. I also installed slapt-get and gslapt though I’ve yet to configure for any repository beyond the defaults. I still have to compile mew, and I need to install my office software (I think I can get away with IBM Lotus Symphony now, else I’ll have to install OOo). At some point, I’ll compile a custom kernel. The big one from Slackware has xfs, jfs, and all kinds of other things built in it that I don’t need and I’d like to reclaim every little bit of RAM I can.

I’ve yet to test things like my beloved Samsung S3 (libmtp is installed) to see what’s working or not. I did a fast basic configuration to get wifi working and moved a few things over via SSH; I do know that audio and X are working without any additional tweaking. Hopefully I’ll have time soon to turn this into my primary computer, whether or not I sell the Acer Aspire One.

No time frame for anything but the office suite and mew (ASAP) because I still am catching up on work from September and October. And no screen shots because it’s just the vanilla Xfce desktop with a solid blue background rather than the default (but quite tasteful, I’ll admit) striped Xfce wallpaper — like it should be without someone else’s muddled idea of how it should be branded with a distro name (or worse). That’s one of the great things about Slackware. That and the fact it has some of the best documentation available so setting it up is straightforward (second in all respects only to OpenBSD in my book).

More when I get time.

A Sync Script for MTP Device

July 29, 2009

I’m less concerned about managing albums on my Samsung S3 from within Linux than I am “changing” content like podcasts, images, shopping and to-do lists, etc. This is no problem at all in Windows because MTP is perfectly supported under it.

The S3 has a file structure which separates “datacasts” from other audio content. I’d been using a quick little script that would copy every ogg, mp3, and/or wma file in the current directory (specifically, ~/podcasts) to my S3’s Datacasts directory. It was fine for doing that, but I wanted it to do a little more than that so I could use one directory as a “sync” folder for more file types. Then I could move all content I want to that folder, run one script, and my podcasts would go to Datacasts, text files would go to Texts, and pics would go to Pictures; as I’ve written before, the device isn’t fine-tuned enough to automatically put each kind of file in an appropriate directory so I wanted my script to assure everything goes exactly where I want it. Otherwise I’d have to go to the “File manager” directory and trace through it to other folders to find my content. This way I know exactly where everything is.

One important thing to note about libmtp and mtp-tools (mtp-examples in Fedora) is that directories are referred by their ID numbers rather than their names. It’s easy to get the directory ID numbers for these using the mtp-folders command. For example, I used the following to get the “Pictures” directory:

% mtp-folders | grep -i pictures

This reported back the folder “Pictures” with an ID number 32776. Other MTP devices will likely have different ID numbers for different things so double check your own device before using the following script.

Once I had the relevant directory numbers, I could set up a few functions to send files to them through a case command for each file type I want to manage. Here’s the current version of my move_podcasts.sh script:

#!/bin/sh
# lucky13linux.wordpress.com - Wed Jul 29 14:33:14 CDT 2009

# moves files from PWD to MTP device via mtp-sendfile
# and deletes the file from PWD. Use this for podcasts,
# text files, and images rather than for music kept
# on the system. 

# mtp-folders for my Samsung S3
# 32773 = Datacasts
# 32774 = Texts
# 32776 = Pictures

function move_podcast_files  {
	mtp-sendfile $SYNC_THIS_FILE 32773
	echo "removing $SYNC_THIS_FILE from $PWD..."
	rm $SYNC_THIS_FILE
}

function move_text_files  {
	mtp-sendfile $SYNC_THIS_FILE 32774
	echo "removing $SYNC_THIS_FILE from $PWD..."
	rm $SYNC_THIS_FILE
}

function move_image_files  {
	mtp-sendfile $SYNC_THIS_FILE 32776
	echo "removing $SYNC_THIS_FILE from $PWD..."
	rm $SYNC_THIS_FILE
}

for SYNC_THIS_FILE in *
do
	case $SYNC_THIS_FILE in
		*.mp3)	move_podcast_files                                 ;;
		*.ogg)	move_podcast_files                                 ;;
		*.wma)	move_podcast_files                                 ;;
		*.txt)	move_text_files                                    ;;
		*.TXT)	move_text_files                                    ;;
		*.jpg)	move_image_files                                   ;;
		*.jpeg)	move_image_files		                   ;;
		*.JPG)	move_image_files		                   ;;
		*) echo "are you sure $SYNC_THIS_FILE goes to MTP device?" ;;
	esac
done

Nothing fancy, and someone will no doubt have a better solution (feel free to opine) or suggest moving some of the repetitive commands in each function to the for loop. It’s a work in progress and works the way I want. Caveats and additional points:

  • I use mksh and edited this to /bin/sh; change to suit your needs if /bin/sh doesn’t link to your preferred shell. EDIT (sorry!): That includes possibly having to edit the functions if your shell (e. g., CSH or TCSH?) uses C/POSIX functionname () {…} semantics rather than function functionname {…}.
  • Add or remove file types based on your own needs. I convert all my images to jpg for convenience.
  • I used single entries for each file type because I may end up adding more to the functions, e. g., adding custom id tags to mp3 and/or oggs (can’t add tags to wma in Linux as far as I know).
  • I haven’t bothered putting videos on my S3 even though it’s capable. I don’t even know if/how I can convert to the format Samsung requires videos be in to play on their devices. RTFM.
  • Delete the rm/echo commands in the functions if you want to keep local copies.
  • In my cheap original script for ogg, mp3, wma, I used ‘for FILETYPE in *.{ogg,wma,mp3}’ which resulted in error messages if one or more weren’t in the directory.
  • I’ll most likely add POD_SYNC_DIR so I can run the script from any directory or from a dynamic directory (dmenu or ion3’s F3 menu) which reads from $PATH. No big deal because I tend to wget files directly to ~/podcasts and always have a terminal open. Whatever.

Finally, mtp-tools (mtp-examples in Fedora) has the mtp-delfile command which is a bit clumsy. To remove files, I tend to delete them directly from the S3 after I listen or use gphotofs (fuse) to mount the device and delete or copy back files I want to keep. In fact, I highly recommend using gphotofs or other applications utilizing libgphoto2 for copying files from a MTP device back to a computer. Unfortunately, libgphoto2 doesn’t copy/move files and directories from computer to device or else it would be ideal, but it’s for cameras rather than media devices. Maybe the libgphoto people and libmtp people can do more collaboration and maybe even merge their projects for better all-around support of cameras and media players using PTP/MTP.

UPDATE 2009-07-29 20:01 CDT: Version 2 of the above script now does rudimentary logging which, when I’m finished, will maintain a list of the file ID numbers to (hopefully) ease removal of files without using the other utilities mentioned in the last paragraph.

Another Way (Maybe) to Skin The MTP Cat

July 19, 2009

I knew there was a nexus between MTP and PTP but I hadn’t checked to see if I could use libgphoto2 to access my Samsung S3 before today. I decided to check because I saw the S3 listed among the devices supported by libgphoto2. Imagine that.

I’d already installed gtkam, which uses libgphoto2, to manage my old Kodak digital camera. I looked to see if the S3 was among the “cameras” listed in the camera selection dialog. It wasn’t listed there but several similar Samsung models were. I didn’t have anything to lose so I plugged it in. I then ran the “detect” option and, voila, I had a listing for my MTP device. I expanded the entry and I had access to everything on the device.

screenshot-20090719160151

What gets me is that this (in #!/Jaunty) is the current version of gtkam and libgphoto2 2.4.2 (current is 2.4.6 and the S3 is named among supported devices in that version). Even with the current version of libmtp, I don’t have the ability to see things by directory (not shown but take my word for it: “Datacasts” and all  the other directories are listed above this “Music” directory) when using apps like rhythmbox. My only option is to use mtp-tools (aka “mtp-examples” to those of you still hitting my blog searching for Fedora help). The only options I have in rhythmbox are to view by artist, song, album, etc. Useful but limited. At least mtp-tools is adequate to manage the device.

I haven’t looked to see if there are any other apps using libgphoto2 to manage MTP devices or to allow mounting them via fuse. Speaking of fuse, the version of mtpfs in Jaunty’s repositories is of no use to me. I can mount the device but a command like ls results with question marks rather than file sizes and permissions. It also shows the filenames but doesn’t allow any other operation on them.

Anyway, it’s nice to see there might be another way to use MTP devices under non-Windows operating systems and that it may actually yield better results. Of course, I’ve only tried to read files and directories and delete files. It may be back to square one if I try to add files.

UPDATE: I installed gphotofs, a fuse system for libgphoto2 which allows PTP/MTP cameras to be mounted as any other filesystem. Yes! I can mount the device and have full access of it. Just deleted a bunch of podcasts from the Datacasts directory.

screenshot-20090719165825

My shell, mksh, carries text beyond the screen (<) so you can’t see the rm command but you can see the result. Finally something freaking works right.

UPDATE 2: Add another 16MB (27MB when various {u} dependencies are removed) of cruft removed. Gone are rhythmbox, libmtp, libusb-dev (needed to recompile libmtp), mtp-tools, mtpfs, etc. It’s redundant to gphoto2/gphotofs and I have much better access to my device now.

UPDATE 3: Using gphotofs is very easy, especially if you’ve used fuse before. You need to be in group plugdev. I chose to create a mount point in my home directory (~/mtp) rather than use a point like /mnt. To mount, first make sure fuse is loaded (lsmod if it was built as a module) and then use the gphotofs command:

gphotofs ~/mtp

Or whatever your mount point is. Once mounted, you can navigate and issue commands as you would any other directory (in a terminal, file manager, whatever you want). When finished, unmount the point:

fusermount -u ~/mtp

Or whatever your mount point is. Give it a moment to umount and then you can remove your device. It’ll work for your camera (if the camera is MTP or PTP) as well.

UPDATE 4: Fuck. If it’s too good to be true, it probably is. I can read from the device and copy and delete from it. Copying to it:

cp: cannot create regular file... Function not implemented

So tomorrow I reinstall libmtp and mtp-tools. Yippee.

getting ready for crunchbang de-bloat, etc.

July 11, 2009

I haven’t changed things around much yet beyond what I wrote yesterday. I’ve started looking at what I can remove and what I’ll have to live with. Here’s a list of the things from dry runs I did earlier to see what I can do without causing major breakage:

The following packages will be REMOVED:
 abiword abiword-common abiword-help abiword-plugin-grammar 
 abiword-plugin-mathview gnumeric gnumeric-common gnumeric-doc 
 libgoffice-0-6 libgoffice-0-6-common 
0 packages upgraded, 0 newly installed, 10 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 60.4MB will be freed.

The following packages will be REMOVED:
 agave 
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 1012kB will be freed.

The following packages will be REMOVED:
 claws-mail claws-mail-html2-viewer claws-mail-i18n claws-mail-pgpinline 
 claws-mail-pgpmime claws-mail-trayicon tango-icon-theme-claws-mail-3.6.0 
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 9720kB will be freed.

The following packages will be REMOVED:
 linux-headers-2.6.28-13 linux-headers-2.6.28-13-generic 
 linux-headers-generic 
0 packages upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 74.7MB will be freed.

The following packages will be REMOVED:
 crunchbang-gwibber-theme gedit-plugins gwibber libmetacity0 metacity 
 metacity-common python-gnome2-desktop 
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 16.6MB will be freed.

The following packages will be REMOVED:
 nvidia-173-modaliases nvidia-180-modaliases nvidia-71-modaliases 
 nvidia-96-modaliases nvidia-common 
0 packages upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 459kB will be freed.

The following packages will be REMOVED:
 libpurple-bin libpurple0 pidgin pidgin-data 
0 packages upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 28.9MB will be freed.

The following packages will be REMOVED:
 rhythmbox 
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 14.5MB will be freed.

The following packages will be REMOVED:
 vim vim-gtk vim-gui-common vim-runtime xchat 
0 packages upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 30.2MB will be freed.

The following packages will be REMOVED:
 libexo-0.3-0 libthunar-vfs-1-2 libxfce4util4 libxfcegui4-4 libxfconf-0-2 
 thunar-data xfburn xfconf 
0 packages upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 19.5MB will be freed.

I think I counted over 200MB and that’s without counting things like gpodder, which is of no use to me if MTP support is lacking for my S3 (so libmtp and mtp-tools will go), and a few other things in that list. I can also get rid of some of the CD/DVD tools (brasero if it’s not in that list above) since I don’t have any plans to start toting around a USB CD/DVD which will probably outweigh my AA1. My mini CDRW bit the dust when I was taking care of family last year. I haven’t been able to find another device this small and thumbdrives are big enough now that I don’t see any reason to get an external optical device. Even Microsoft is considering putting the Windows 7 installer on a USB drive to make installation easier for netbook users. What’s funny is, Microsoft may beat most of the big Linux distros to the punch — with most distros, live images can be put on USB media via external tools like unetbootin or Fedora’s live USB creator. There are only a handful which have USB-ready images that can be installed via simple scripts. I think that’s the future whether netbooks and nettops ever outsell traditional computers.

100_0660_scaled

Yes, that’s the old CDRW next to my AA1. If anyone knows of a DVD-RW (or Blu-Ray!) this small, please let me know.

By the way, no problems like I had in Fedora yet with wifi even though I’ve tested suspend/resume. The only thing that continues to be an issue is the initial association with the wrong AP before it re-associates with my router. I really, really don’t like that but I haven’t looked to see what I can do to stop it. In addition to the stuff in dmesg, iwconfig shows the association with SSID=”the wrong one” and then after the nm-applet icon changes to show that it’s connected iwconfig shows SSID=”my router.”

I have some other things I have to take care of today and a busy evening, too. It might be tomorrow before I get down to business.

crunchbang – More JWM Screenshots

July 10, 2009

Here are a couple more screenshots. New shell is mksh. Added a few more entries to .jwmrc and also uncommented the Debian part of the default menu. I also moved the <Dock/> tag down so there’s not that big empty space between the applets and clock (compare this emacs shot to the next two).

emacs-pic-01

Remembered to get “free -mt” after a reboot.

jwm-shot-01

I also took the openbox keybindings out of the .conkyrc and added in the other mount points I want to see. I’ll probably set up something like xbindkeys so my keybindings are the same regardless of which window manager I use.

jwm-shot-02

That’s it. I have some reports to finish so I can call it a day. Tomorrow I’ll probably start pruning some of the things from my list last night and see what I can do to keep NetworkManager — or whatever alternative I can find — from associating with any other AP before it connects to mine. I also need to see if I can find out what the problem is with libmto and mtp-tools and my S3; it’s not being detected at all under #! right now.

Using libmtp, mtp-tools in Fedora 10

July 4, 2009

Working on MTP-stuff while watching the first day’s time trials in the Tour de Lance. I removed rhythmbox several days ago along with the big load of Gnome bloatware I ditched. No big deal.

aa1-s3-600x445

Just for background, my MTP device is a Samsung S3 (YP-S3). The S3 was on my wishlist because it’s capable of playing OGG and video; it also has a cool touchpad interface instead of a stupid wheel thing. Unfortunately, just because it plays ogg files doesn’t mean it plays fairly with non-Windows operating systems. It was purchased from a big box electronics store which runs its own music download site; this retailer sells custom-flashed models to work with their store and this custom firmware removes OGG-capability (even though the retailer’s site provides specs suggesting it does play ogg files). I installed the default firmware for the device to get OGG support on it; Windows, though, will wrongly suggest these files won’t play on the device when copying. And despite being capable of playing back video, the videos must first be converted for the device using Samsung’s software that comes with it. I chose to not install it so I don’t watch videos. Finally, the other fly in the ointment with the device is that it’s MTP rather than UMS. UMS is standard USB storage and MTP is Microsoft Transfer Protocol. Of course, the packaging and specs don’t tell the consumer that it’s MTP and not plug-and-use like any standard USB device.

Fortunately, there is some MTP support for non-Windows operating systems via libmtp. The project has had some support from Microsoft. Contrary to the naysayers and haters, Microsoft wants wider adoption of their protocols. After all, a Zune sale makes them money whether the user wants to use it in Windows or Linux. Unfortunately, the ease/difficulty of getting devices to work depends on how they’re set up by manufacturers and how many developers or owners have provided information to the developers. Some applications which use libmtp work better than others, which also is affected by which version of libmtp is being used.

There are several applications which use libmtp to support MTP devices. These include amarok and rhythmbox, but also include lesser-known applications and utilities.

I installed mtpfs, a fuse filesystem allowing the device to be mounted, in Debian but was unimpressed with it. I didn’t see mtpfs in Fedora. I don’t know if I’ll bother with compiling it. In Debian, I was able to mount the device and navigate directories to read files but had zero control over files. Like other MTP utilities, there was scant information to help me resolve the problems. I wish it had worked because I love the fuse approach for things like this.

I also looked briefly at gnomad2 (in Fedora) but was put off by a few things. The worst part was the non-recognition of my device (not too surprising since the application isn’t a general MTP manager but targeted to a couple specific devices). The other thing — and this is the kind of aggravating thing some programmers do that pisses me off — is that it uses graphical interface boxes for the main part of the application or its preferences designed for high resolution screens so that on a smaller screem (such as my AA1) a user has to press alt to scroll the thing up off the screen to get to the options on bottom. Maybe the developer isn’t aware that scrollbars allow users to navigate below a certain point if their screens aren’t the same size as his. I removed it after having to push it up the screen repeatedly to find more options to see if it might be tweakable to find and work with my device. I just said, “Fuck it.”

While most users would feel more comfortable using an application like amarok or rhythmbox which uses libmtp, libmtp comes with its own set of tools (usually called mtp-tools for some strange reason). These tools are command-line and not very well documented. Maybe they’d be easier to use if they were, eh.

The first thing I had to do was figure out which Fedora package has mtp-tools. After looking through the mtp-related files (via yum search and yum info) I realized “libmtp-examples” is mtp-tools. Whatever. I installed it and started seeing what I could do with it.

One important command to see if the device is recognized is mtp-detect. This command will provide details about the device — name, ID numbers, directories, and capabilities. Once you know the device is recognizable by libmtp, you can look at managing it (the list of mtp commands is posted below).

I wanted to copy a couple test podcasts to one particular directory. I didn’t know off the top of my head if using mtp-sendfile would result in my podcasts going to the Music directory or to the root directory. After transferring them — one of which resulted in an error — I disconnected the S3, turned it on, and started looking for it. Music? No. But it did land in the file manager’s Music folder, and it played when I selected it.

So I had to figure out  how to manage the directory structure on the device. It’s offputting to have everything go in one directory when there’s a full tree of directories to manage things better. The mtp-folders command produces a list of folders, each with a number in front of it.

After doing a few searches, I learned that I can’t name destination directories when transferring files but rather need to use their number codes (available via mtp-folders). Once I knew that it was easy to send my podcasts to “Datacasts” on my Samsung S3.

screenshot-20090704113939

I still get the “unknown options” error message but the files are going to my “Datacasts” directory; when sending to “Datacasts” by name, they were going to the root of the Music directory and accessible only in the File Manager rather than under Music (stupid, huh). Also note that the permissions require root access to the device. Go figure. I’ll add a new group for it or something but it’s not a big deal since Windows will ignore the permissions anyway.

There are a variety of mtp-tool commands. As you can see, though, I used mtp-connect –sendfile instead of mtp-sendfile. No matter because mtp-sendfile, mtp-delfile, mtp-getfile, mtp-newfolder, and mtp-sendtr are all links to mtp-connect.

mtp-albumart        mtp-emptyfolders    mtp-getplaylist     mtp-reset           mtp-trexist
mtp-albums          mtp-files           mtp-hotplug         mtp-sendfile
mtp-connect         mtp-folders         mtp-newfolder       mtp-sendtr
mtp-delfile         mtp-format          mtp-newplaylist     mtp-thumb
mtp-detect          mtp-getfile         mtp-playlists       mtp-tracks

I’ll see if I can put together a better, more comprehensive tutorial on using these devices without installing bloated apps like those mentioned above.