z411 / trackma

Open multi-site list manager for Unix-like systems. (ex-wMAL)
https://z411.github.io/trackma
GNU General Public License v3.0
761 stars 82 forks source link

list shows in json format #662

Open RaitaroH opened 1 year ago

RaitaroH commented 1 year ago

For issue https://github.com/z411/trackma/issues/660 If you merge this PR, please squash and merge.

$ trackma help
...
     list|ls <>            Lists all shows available in the local list.
   list_json <>            Print list of shows in json format.
...

Example of trackma list_json (it defaults to watching list)

{"title": "Ars no Kyojuu", "current_episode": "2", "total_episodes": "12", "score": "0", "status": "Ongoing", "estimated_aired_episode": "2", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx155089-I5zYFNvWua57.png"}
{"title": "Blue Lock", "current_episode": "14", "total_episodes": "24", "score": "5.5", "status": "Ongoing", "estimated_aired_episode": "14", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx137822-4dVWMSHLpGf8.png"}
{"title": "Buddy Daddies", "current_episode": "2", "total_episodes": "13", "score": "0", "status": "Ongoing", "estimated_aired_episode": "2", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx155907-gR7aRwVHwrjc.jpg"}
{"title": "Bungou Stray Dogs 4th Season", "current_episode": "2", "total_episodes": "13", "score": "0", "status": "Ongoing", "estimated_aired_episode": "2", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx141249-8tjavEDHmLoT.jpg"}
{"title": "Flying Witch", "current_episode": "12", "total_episodes": "12", "score": "0", "status": "Finished", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx21284-vQcCLIWt1o5O.png"}

Then it also can accept list status, trackma list_json paused:

{"title": "Casshern Sins", "current_episode": "15", "total_episodes": "24", "score": "6", "status": "Finished", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx4981-V6MbMiJUqdvP.jpg"}
{"title": "Chi's Sweet Home: Atarashii Ouchi", "current_episode": "63", "total_episodes": "104", "score": "0", "status": "Finished", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx6024-eYiQMRfPfWiF.jpg"}
{"title": "Joshiraku", "current_episode": "1", "total_episodes": "13", "score": "0", "status": "Finished", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx12679-0zlvLP7KyxjH.png"}
{"title": "Karakai Jouzu no Takagi-san 2", "current_episode": "7", "total_episodes": "12", "score": "5", "status": "Finished", "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx107068-KJq0eFP0GTjL.jpg"}

I believe trackma -a should work. I tested with trackma -a 2 list_json and it asks me to select account first, before listing anything.

In bash scripts, jq works as expected. Here is a more complicated command:

trackma list_json | jq -jr '.title, "|", .current_episode, "|", .total_episodes, "|", .score, "|", .status, "|",.estimated_aired_episode, "\n"'
Ars no Kyojuu|2|12|0|Ongoing|2
Blue Lock|13|24|5.5|Ongoing|14
Buddy Daddies|2|13|0|Ongoing|2
Bungou Stray Dogs 4th Season|2|13|0|Ongoing|2
Flying Witch|9|12|0|Finished|null
RaitaroH commented 1 year ago

Apologies if this isn't quite correct / good. I don't know python that much.