Skip to content

Instantly share code, notes, and snippets.

@parkerlreed
Last active November 29, 2018 00:30
Show Gist options
  • Save parkerlreed/19d38c3cf8237dcc814c5bae3018ffb3 to your computer and use it in GitHub Desktop.
Save parkerlreed/19d38c3cf8237dcc814c5bae3018ffb3 to your computer and use it in GitHub Desktop.
Pass in playlist path as first argument and either --print (to print to terminal) or --save (to overwrite original file) as second.
#!/usr/bin/env bash
game_lookup() { grep -A 23 -r $1 Data/Platforms/ | grep Title | cut -d ">" -f 2 | cut -d "<" -f 1 | tail -1; }
game_list=$(for i in `grep '"id"' "$1" | tail -n +2 | cut -d "\"" -f 4`; do echo -n "$i "; game_lookup $i; done | sort -k 1.38 | cut -d " " -f 1)
playlist_file=$(
head -3 "$1"
for i in $game_list; do echo ' {
"id": "'$i'",
"notes": ""
},' ; done | sed '$ s/.$//'
tail -6 "$1")
case "$2" in
--print) echo "$playlist_file"
;;
--save) echo "$playlist_file" > "$1"
;;
*) echo "Please either pass --print or --save as the second argument"
;;
esac
[parker@stealth Arcade]$ ./sort_playlist.sh Playlists/b227465a-7fa5-44cb-942b-bbec15fabc85.json --print
{
"id": "b227465a-7fa5-44cb-942b-bbec15fabc85",
"games": [
{
"id": "2d0071b4-8ea9-40b1-a642-c970ca260cb2",
"notes": ""
},
{
"id": "ca5c0488-f894-4f2f-b92c-95ec4f836eaa",
"notes": ""
},
{
"id": "9bb4ffad-8084-45c2-a285-a4ce1a771e02",
"notes": ""
},
{
"id": "a9c12944-f679-4aca-a803-8846d54b2f99",
"notes": ""
},
{
"id": "3ec21252-5f78-4960-a3ef-1c32fec8df74",
"notes": ""
},
{
"id": "8de9681d-f820-4421-b18c-9d59416ab807",
"notes": ""
},
{
"id": "887fa483-b9f9-489d-ac5f-7c88335c7946",
"notes": ""
},
{
"id": "5a0810b3-abaa-726b-be5d-d27e8f792563",
"notes": ""
},
{
"id": "c2c25f38-7ab1-4859-8c5b-75ca9f043d32",
"notes": ""
},
{
"id": "17dcecb5-16f2-4efa-86ea-def9c31b830c",
"notes": ""
},
{
"id": "dc47b8c5-b626-14a5-bded-edf347f659de",
"notes": ""
},
{
"id": "8cbb824f-73f1-49fe-9390-79e2295e4598",
"notes": ""
},
{
"id": "62a45085-51cd-443c-af15-a85ce7b06574",
"notes": ""
},
{
"id": "c5d2c57f-6ab9-481c-9436-901ad7528500",
"notes": ""
},
{
"id": "82accbbb-8aad-5622-787c-15f61c282133",
"notes": ""
},
{
"id": "9d46e1e9-12bf-4d1d-ad2e-1e9aafb81484",
"notes": ""
},
{
"id": "286a74e2-a85d-4c6d-a1b9-0d57551035d5",
"notes": ""
},
{
"id": "1bd6af6a-f1e4-44ba-8f1e-cb19a318739a",
"notes": ""
},
{
"id": "ba1bc17f-9069-f9fd-ee69-8bcfb31a271c",
"notes": ""
},
{
"id": "24fcce31-6e12-87b9-777f-ace9ef441ccc",
"notes": ""
},
{
"id": "824643b0-fb12-42dd-bb82-16e6fa6ff403",
"notes": ""
},
{
"id": "2352d025-15b6-43b0-b44f-160b4a6cc456",
"notes": ""
},
{
"id": "511281fb-e173-4ff5-8867-7622031f3bb2",
"notes": ""
},
{
"id": "3eb4f7d7-da2d-4b20-81bf-e38e3597a63a",
"notes": ""
},
{
"id": "03358cb0-d36d-422c-a01b-39848ffadb67",
"notes": ""
},
{
"id": "03b224b3-259a-42eb-b5a9-926daed7c5ad",
"notes": ""
},
{
"id": "cf497521-a41c-4332-b41e-949730bf8f83",
"notes": ""
},
{
"id": "a4a00459-8784-b149-5adb-0d9e5f1a249c",
"notes": ""
},
{
"id": "de0cee15-9928-2568-48f8-53469c0de1c6",
"notes": ""
},
{
"id": "6a724774-959a-3628-d867-2b754442a728",
"notes": ""
},
{
"id": "09ce9710-bb31-4673-a580-b6ecd3320bcb",
"notes": ""
},
{
"id": "d0abcdd0-240f-4fee-b87a-1b3fd36da119",
"notes": ""
},
{
"id": "ad2925ed-d8f5-1a97-67e3-8fff07f23c08",
"notes": ""
},
{
"id": "b0d2b9a9-ab00-465e-b5a3-56031b92f070",
"notes": ""
},
{
"id": "61c8e0d0-7f45-461b-93d8-7c485f800576",
"notes": ""
},
{
"id": "b7726ba9-cbc4-4942-9498-5a02aff4246e",
"notes": ""
},
{
"id": "9ff177ab-469b-413e-9825-98442d8a3b2f",
"notes": ""
},
{
"id": "d0dee3fc-6bce-49c8-8408-06c763b1109a",
"notes": ""
},
{
"id": "25d9d738-6215-4eb3-ad24-7ca949b9a650",
"notes": ""
},
{
"id": "f4147e46-008e-4c30-a315-4fd8bbb933d5",
"notes": ""
},
{
"id": "693b13b8-ab7f-487c-8e9e-b15f6c0b52dd",
"notes": ""
},
{
"id": "58b87a44-bb9c-4030-ade3-6b7d343cc530",
"notes": ""
},
{
"id": "4abcd7b9-d22b-4abe-9e8e-b8576aa0e0e0",
"notes": ""
},
{
"id": "ddc998ce-08c3-46d5-a039-8fa65fabd43f",
"notes": ""
},
{
"id": "9ef17b8f-021d-43ab-a96f-8dc011499a62",
"notes": ""
},
{
"id": "3173188b-8ad2-463d-b926-0759e5814db5",
"notes": ""
},
{
"id": "2a55cd7c-160a-4b5a-b898-f5f0be333c56",
"notes": ""
},
{
"id": "453ee7e4-39e0-4057-a3be-814320ead99e",
"notes": ""
},
{
"id": "69f40196-b84d-0d36-0402-68caab8aa8a9",
"notes": ""
},
{
"id": "b0ce771e-7c02-4317-8528-ba48139e2688",
"notes": ""
},
{
"id": "ff91ae48-6f80-0b23-2115-f1a0caf2c3ee",
"notes": ""
}
],
"title": "Favorites",
"description": "",
"author": "Parker",
"icon": "data:image/png;base64,iVBORw0KGgoAA....LONG_BASE_64"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment