DenverCoder1 / github-readme-youtube-stats

Youtube stats badges for your Github profile README. Displays the total number of subscribers or the view count for your channel.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Short number formatted labels appear stretched for large numbers

DenverCoder1 opened this issue · comments

Issue

Currently, the number is updated with a regex replacement on the response from Shields.io. The rectangle width and text length don't get updated, causing the text to occasionally appear stretched like shown here:

image

Potential fixes

The easiest fix might be to be to fetch the YouTube statistics before creating the shields.io URL and use the static shields.io API instead of dynamic. Doing it this way will allow shields.io to determine what the rectangle size and text length should be.

The format for the static shields.io URLs is like this:

https://img.shields.io/static/v1?label=<LABEL>&message=<MESSAGE>&color=<COLOR>

Other query parameters such as labelColor, style, and others will still work.

Steps

  • Fetch the data from the YouTube API with curl_get_contents and json_decode
  • Locate the view count and subscriber count numbers using array indexing
  • Set the message parameter to the number, but make sure the number is in the right format first
  • Remove unused code

If you are able to accurately resize the input another way, feel free to do it as you choose.

If you have any questions, don't hesitate to ask!


Please comment on the issue before making a pull request.

This issue is for first-timers only! Since this a simple issue to fix, I am offering this issue specifically to those who have submitted fewer than 4 pull requests

Can I take this

@DavidPretty Sure, that would be great!

Can I work on this.?

@ImagineZero0, the issue has already been claimed by @DavidPretty although I'm not sure how much progress has been made. If there has been no progress and no response by this time tomorrow, I will make it available.

@DavidPretty If you have any questions, don't hesitate to ask. Let me know if you plan on working on this.

@DavidPretty If you have any questions, don't hesitate to ask. Let me know if you plan on working on this.

HI, was going to look at this tomorrow. If that's not Ok happy for someone else to claim

@DavidPretty 👍 Not a problem at all. You can take your time. I just wanted to make sure it wasn't forgotten about.

Sorry, relinquishing this, apologies for wasting people's time

@DavidPretty I'm able to help with some steps if you need, but if you're sure, I can see if @ImagineZero0 is still interested.

HI DenverCoder1 thanks for the offer but I don't have enough php experience-should have looked more closely before jumping in. Please let ImagineZero0 take this.

@ImagineZero0 This issue is available now, let me know if you are still interested

Yes, I would really love to contribute.
Thank you

@ImagineZero0 You can work on it if you'd like.
If you have any questions, don't hesitate to ask!

Okay, Sure @DenverCoder1 ...
I will get straight on it.

Hey, @DenverCoder1, I just wanted your help in the part of curl_get_contents as it kind of seems not trivial, and also I am not able to understand how to use it get the required JSON data from the API, but after that, I got how to change the dynamic Shields.io to Static shield.io...
kindly look into this.

Hi @ImagineZero0!

In functions.php, you should see curl_get_contents. All you need to know about it is that it takes a url as a parameter and returns the response text of the url as the output (whether it is JSON, an SVG image, or whatever it is).

You can use curl_get_contents on the YouTube API url to get the JSON returned as a string, then json_decode can be used on that to turn it into a PHP array which can be parsed more easily.

Let me know if that helps

Hey @DenverCoder1, Your advice worked out and I was able to do almost all the steps that is extracting the Json from the API, decoding and extracting the required array values, made the count in a proper format, and build the shield static URL, but when I am trying to run with the header('Content-type: image/svg+xml'); code, it is giving me a Render Error, while without this I am getting the URL as output from echo(which I would get),
https://img.shields.io/static/v1?label=Youtube+Subscribers&message=107m&color=brightgreen&logo=youtube&logoColor=white&style=flat-square&labelColor=gray&id=UC-lHJZR3Gqxm24_Vd_AJ5Yw&key=AIzaSyB66QFKg2skV3gGHDnNHJotxmMgKfy5k9E

But I am not able to render this..

Could you have a look at this..

I have attached a photo of my code for the index.php for Subscribers Count..

2020-10-19

@ImagineZero0 To output the image and not the url, you can use curl_get_contents on the image url and echo the contents.

Thank you @DenverCoder1, I have successfully changed the code and verified it. I have made the respective PR, please review it.

Thank you again for your advice and help...

Fixed with #17