github-readme-youtube-cards icon indicating copy to clipboard operation
github-readme-youtube-cards copied to clipboard

🚀 Feature: JSON output option

Open DenverCoder1 opened this issue 3 years ago • 17 comments

The user may want to parse the output manually in a different action step.

An option, for example, output_type: "json" could be useful to allow such customization more easily.

A format such as the following may be useful (all the params, plus the svg card url)

[
  {
      "id": "...",
      "title": "...",
      "timestamp": "...",
      "background_color": "...",
      "title_color": "...",
      "stats_color": "...",
      "width": "...",
      "duration": "...", // if applicable
      "image_url": "https://ytcards.demolab.com/?id=...&...",
  },
  {
      ...
  },
]

This can be coordinated with #24 since both involve adding output_type.

DenverCoder1 avatar Sep 11 '22 20:09 DenverCoder1

!assign

HeyAnirudh avatar Oct 05 '22 12:10 HeyAnirudh

Hi @HeyAnirudh, any updates on this issue?

DenverCoder1 avatar Oct 14 '22 23:10 DenverCoder1

hey, @DenverCoder1 wasn't well for a few days and had trouble setting up the project. I did ask people out in discord but no luck yet .

HeyAnirudh avatar Oct 16 '22 04:10 HeyAnirudh

The CONTRIBUTING.md has some info on getting things set up and running assuming you already have Python installed and an editor.

If there are any specific issues you are facing, feel free to ask. The more specific you are with the question, the more likely it is someone can help.

DenverCoder1 avatar Oct 16 '22 05:10 DenverCoder1

so while creating API credentials ,what shall we use image

HeyAnirudh avatar Oct 16 '22 06:10 HeyAnirudh

and also where shall i add the API key and channel id .

HeyAnirudh avatar Oct 16 '22 06:10 HeyAnirudh

You don't need an API key to run the project. It only really affects whether duration is included in the params or not.

Here's some details about YouTube API keys in case it helps though https://github.com/DenverCoder1/github-readme-youtube-cards/wiki/Setting-Up-the-Action-with-a-YouTube-API-Key

DenverCoder1 avatar Oct 16 '22 06:10 DenverCoder1

To test the action you can run the python part like this

python action.py --channel=UCipSxT7a3rn81vGLw9lqRkg --comment-tag-name="EXAMPLE-YOUTUBE-CARDS"

With api key:

python action.py --channel=UCipSxT7a3rn81vGLw9lqRkg --comment-tag-name="EXAMPLE-YOUTUBE-CARDS" --youtube-api-key="your-key"

You can see the action.yml and action.py for more details on what it can do

DenverCoder1 avatar Oct 16 '22 06:10 DenverCoder1

stuck with this error image

HeyAnirudh avatar Oct 16 '22 07:10 HeyAnirudh

stuck with this error

What version of python are you running?

i.e what does python --version tell you?

It works for me on Python 3.10.8 (it's written to be run with Python 3.10)

DenverCoder1 avatar Oct 16 '22 07:10 DenverCoder1

Some clarification on the requested issue:

It was mentioned in the issue that a new output_type input would be made, but I'm realizing this doesn't really make much sense since you wouldn't update a readme with that json.

Instead, I think it should be an additional output, i.e. you would have markdown which is already an output, and json as another.

In the action.yml, the way to do that would be something like

echo "::set-output name=json::$(<something that echos the json here>)"

If you were to create a file with the json in the action.py (eg. save it in youtube-cards-output.json), you could set the output with

echo "::set-output name=json::$(cat youtube-cards-output.json)"

Would want to make sure to remove it though, so it doesn't commit, for example, you could do afterwards rm youtube-cards-output.json to delete it.

DenverCoder1 avatar Oct 16 '22 07:10 DenverCoder1

stuck with this error

What version of python are you running?

i.e what does python --version tell you?

It works for me on Python 3.10.8 (it's written to be run with Python 3.10)

yeah its 3.10.8 for me

so before it gave an error image in line 146 I have updated r with "rb" which solves it. but after that, it showed the same issue as before.

HeyAnirudh avatar Oct 16 '22 07:10 HeyAnirudh

Try using encoding="utf8" in the open function, that's usually what fixes the "charmap can't decode" issue.

Try to keep it as "r" and not "rb" since it's more useful for it to be a string and not bytes.

DenverCoder1 avatar Oct 16 '22 08:10 DenverCoder1

Also if you manage to fix the charmap decoding issue, feel free to make a pull request for that. I haven't seen the issue come up before, but it might only occur with certain channels.

DenverCoder1 avatar Oct 16 '22 08:10 DenverCoder1

Try using encoding="utf8" in the open function, that's usually what fixes the "charmap can't decode" issue.

Try to keep it as "r" and not "rb" since it's more useful for it to be a string and not bytes.

yeah that solved the charmap issue

HeyAnirudh avatar Oct 16 '22 15:10 HeyAnirudh

@DenverCoder1 should I open a pr for that?

HeyAnirudh avatar Oct 16 '22 15:10 HeyAnirudh

Sure, it's good to keep separate issues in separate PRs, so you can feel free to open a PR specifically to change that.

DenverCoder1 avatar Oct 16 '22 15:10 DenverCoder1