2

I wrote a small Plex playlist/media export utility to transfer playlists and media from Plex Media Server to Android. It uses the ADB executable to push files from the server to the phone, and works nicely; however I'd really like to port it to C or C++ and make a self-contained executable instead of a bash script with external dependencies.

A couple of days of googling turned up nothing but a bunch of false leads that ended up being wrappers for the ADB executable, and a document that explained how poorly documented the protocol is.

Has anybody run into any sort of self-contained library in any language that can do an ADB push?

Terry Carmen
  • 3,720
  • 1
  • 16
  • 32
  • what's wrong with the Google's original `c` or more recent `cpp` code? https://android.googlesource.com/platform/system/core/+/master/adb – Alex P. Oct 05 '18 at 00:02
  • Between work and personal stuff I don't really have the time right now to pull it apart and try to rebuild it, and was looking form something that was already done. However it would be nice to take a look at when I get a chance. – Terry Carmen Oct 05 '18 at 01:20

1 Answers1

2

Here are two libraries, though not in C++: Python, Haskell

It's fairly safe to assume Python is already installed on any Linux system, so I'd go with that one. Moving bash to Python is also much easier than bash to C++.

If you want to write your own in C++, the adb protocol is very well documented here.

Also, why not just install the dependencies in the shell script? There are only a handful of package managers out there so it shouldn't take long to figure out the right package name for each linux flavor and have the shell auto download it. That would be the more standard solution, and would only be a few lines of bash.

Or, you can just package your shell script and mark the dependencies in the package (The former will be easier, though both methods are easier than rewriting a bash script in another language). Then users would download the package based on which Linux flavor they have.

Nicholas Pipitone
  • 4,002
  • 4
  • 24
  • 39
  • That's awesome! I'll take a look at the python lib. "If you want to write your own in C++, the adb protocol is very well documented here" I had found that earlier, but the author semed to iindicate that a lot of the low level stuff was unclear/undocumented/not standard, like some of the hashing or crypto stuff (don't rememebr which), so if the .py code works, I'm all set. – Terry Carmen Oct 04 '18 at 20:17
  • "Also, why not just install the dependencies in the shell script?" Mostly because I never considered having a shall script ask to install it's own dependencies. It seems a little like "taking liberties" with other systems. That would have been an option, although I like the .py option much better. – Terry Carmen Oct 04 '18 at 20:22
  • @TerryCarmen While that link does hammer the adb protocol quite a bit, [this](https://github.com/cstyan/adbDocumentation#adb-push) section described how to interface with the device to get an `adb pull`, along with the encryption procedure above. I definitely don't recommend doing that though, as the libraries have already been written (And if you're not already familiar with communicating over USB or reading pcaps, it's gonna be tough - though interesting). I wouldn't worry about putting dependencies in shell scripts, it's very normal, not that the Python solution is any worse. – Nicholas Pipitone Oct 04 '18 at 20:34
  • Thanks again I appreciate it. I'll be going with the .py code. As cool as it would be, I don't have time to rewrite the protocol. – Terry Carmen Oct 04 '18 at 20:47