MestreLion / humblebundle

API for managing Humble Bundle games library
GNU General Public License v3.0
211 stars 38 forks source link

introduce --formatted-list option #5

Closed wolfgangkarall closed 9 years ago

wolfgangkarall commented 9 years ago

... to output only the basename, md5 and web URL of an item (in that order).

The shell snippet was fine for getting the download locations, but at least md5 and basename would be nice as well. I tried, but sed only gets you so far:

./humblebundle  --show  worldofgoo_android_pc_soundtrack  --json | sed -ne ': begin;
/download_struct.*\[$/,/],$/{
  /{$/,/},$/ {
        /md5/{ s/.*"\([^"]*\)",$/\1/ ; h; }
        /web/{ s/.*"\([^"]*\)"$/\1/ ; s/^\(.*\/\([^/]*\)?.*\)$/\2 \1/; H; x; s/\n/ /; p; }
  }
}'

But there's a download_struct with an "external_link" but no md5/web entry, and that kind of got me off the tracks. ;)

And I guess it's cleaner to get the data out of the script in a well-formatted way than trying to get it out of the json output.

wolfgangkarall commented 9 years ago

BTW, of course it would be nice to actually make the output configurable and not limited to

<basename> <md5> <url>

but before investing any more here I figured I rather see how you like the idea.

MestreLion commented 9 years ago

I'm not sure this is a good approach. --show as it is may be grep and cut friendly, but its primary use is for humans. --formatted-list would severely cripple that, and still require another program to actually do something. And it would never be as complete as JSON data can be.

Better to either (A) add the options you need to make humblebundle itself do what you want (a --download-all perhaps, it would even share most download args like platform, arch, etc), or (B) make a program that can parse JSON (it's like 3 lines in Python), or (C) make a Python program that imports humblebundle as a module and use the HumbleBundle class and its methods to directly manipulate game data as lists and dict objects.

I'd vote for (C), but (A) is also very interesting.

MestreLion commented 9 years ago

(C) would also be the first real test of humblebundle as a library instead of a script. Would be a great time to test if its API is flexible and robust enough to accommodate anyone's needs.

MestreLion commented 9 years ago

As a side note, please use git branches for such features. It's much easier for you to pull and push commits (and get my updates) if our master branches are always synchronized.

MestreLion commented 9 years ago

I've recently wrote a lengthy comment to another contributor about git branches, you could check it out:

https://github.com/MestreLion/legendastv/pull/5#issuecomment-71133616

Unfortunately it's in Portuguese, but it seems Google Translator can do a decent job:

https://translate.google.com/translate?hl=en&sl=pt&tl=en&u=https%3A%2F%2Fgithub.com%2FMestreLion%2Flegendastv%2Fpull%2F5%23issuecomment-71133616

Also take a look at the URLs I posted in the end, some great tutorials from Github itself

wolfgangkarall commented 9 years ago

You're quite right in all respects, especially the branching (I simply forgot). Basically I was just quickly scratching my own itch, so never mind the pull request. :)

MestreLion commented 9 years ago

I've posted this in another pull request, but this one is more appropriate for it:

This one-liner might whet your appetite:

for game in $(humblebundle --list); do humblebundle --show "$game" --json | grep '"web":' | cut -d'"' -f4; done

;)