NHL.com + Sochi 2014 Data URLs in JSON and JSONP

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
After going through the network traffic of NHL's services, I have compiled a list of URLs that the NHL uses to obtain stats for certain players, teams, standings, etc... Best of all, all of this data is free and does not require any sort of API Key or anything of that nature.

This data came from the network traffic of NHL.com on a PC, NHL Gamecenter App on an iPhone, and TSN's iPhone App. There is no HTML/Web scraping involved :)


To make the data more readable, please use www.jsonlint.com to parse it.

JSON/JSONP Data > HTML Scraping

All URLs are subject to change but based upon the previous URLs, the NHL will post the new URL when you call the old one


Team Roster:​

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/ANA/iphone/clubroster.json

Change the team name (ex. ANA) to the wanted team; returns most current roster

Team Schedule Per Month

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/clubschedule/CGY/2014/02/iphone/clubschedule.json

Change CGY to the wanted team abbreviation, 2014 to the wanted year and 02 to the wanted month.

Player Stats for the Entire Specified Team:​

ex. http://nhlwc.cdnak.neulion.com/fs1/...ne/20132014/2/ANA/iphone/playerstatsline.json

From the Gamecenter App - Simple Structure, change the season and team as wanted

Playoff Player Stats for the Entire Specified Team:​

http://nhlwc.cdnak.neulion.com/fs1/...ne/20132014/3/PIT/iphone/playerstatsline.json

Simple Structure, change the season and team as wanted, the 3 stands for Playoffs

Stats for an Individual Player:​

You can either loop through the club roster and "player stats line" URL's above or get it from TSN:

http://www.tsn.ca/mobile/bbcard.aspx?hub=NHL&name=Sidney+Crosby

XML Data!

Just change the player name as desired.

Stats for Games:​

There are a couple of URL's for this data, the most common that NHL.com uses are:

Structure: "http://live.nhle.com/GameData/" + Year (ex 20132014) + "/" + Gameid (ex 2013020821) + "/gc/" + Data Wanted (gcsb, gcbx etc...) + ".jsonp"


http://live.nhle.com/GameData/20132014/2013020821/gc/gcsb.jsonp

- Updates way quicker than the data for the specified day (http://live.nhle.com/GameData/GCScor...13-01-31.jsonp) and contains Team ID's, Player's currently on the ice (gives their jersey numbers), Shots and goals for each team separated by the total or by period, current game time (in seconds in the sr listing), most recent event/play.


http://live.nhle.com/GameData/20132014/2013020758/gc/gcbx.jsonp

- Recommended for in depth recent in-game plays and player stats. Contains recent events (it does not contain all of the events!), goal summary (goal scorer, assists, time, id, teams involved, type of play (you can find the alphabetical equivalents that correspond to the numbers on a script the NHL has which will be discussed below), penalty summary, and the only way to obtain the game stats for each player in the game according to their jersey number (the NHL.com Player ID is not necessary).

- For each player it includes their Assists, Goals, PIM, Plus Minus, Shots, and Time On Ice for that game


PlayByPlay.jsonp is not used by the NHL.com at this current time but contains all of the plays of the game, and goal info; I don't know whether NHL.com will continue to update it in the future.

"League Leaders" Overview Stats

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/leagueleaders.json

"League Leaders" In Points

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/points/leagueleaders.json

"League Leaders" In Goals

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/goals/leagueleaders.json

"League Leaders" In Assists

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/assists/leagueleaders.json

"League Leaders" In Plus/Minus

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/plusminus/leagueleaders.json

"League Leaders" In Wins

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/wins/leagueleaders.json

"League Leaders" In GAA

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/gaa/leagueleaders.json

"League Leaders" In Save Percentage

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/savepercentage/leagueleaders.json

"League Leaders" In Shutouts

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/leagueleaders/iphone/shutouts/leagueleaders.json

Team Standings:​

http://app.cgy.nhl.yinzcam.com/V2/Stats/Standings

XML Data!

NHL Game Center requires an "auth" code in order to obtain team standings, this URL is extracted from the same data and doesn't require authentication.

or TSN's Standings:

http://www.tsn.ca/datafiles/XML/NHL/standings.xml

Also XML

NHL News:​

http://nhlwc.cdnak.neulion.com/fs1/nhl/league/news/NHL/iphone/1/news.json

Player Mug Pictures​

You need the id of the player in order to access this which can be obtained from their team roster:

URL: http://3.cdn.nhle.com/photos/mugs/thumb/8476822.jpg

Self explanatory, just change the ending to the desired player id.

Default Image: http://3.cdn.nhle.com/photos/mugs/thumb/default.jpg

UPDATE: Thanks to aksun for the following info:

I found transparent high-quality player pictures from TSN site.

Example picture

API workaround:

Code:
GET http://tsnimages.tsn.ca/ImageProvider/PlayerHeadshot?seoId=[B][name][/B]

So it's pretty easy to use it, just change the [name] to your player's name. There is a couple of things to keep in mind while using this system.
  • Latin alphabets only
  • replace spaces with hyphens(-)
  • replace aphostrophes(') and dots(.) with nothing

PHP for replacing work:

PHP:
$name = str_replace(array(" ", "'", "."), array("-", "", ""), $originalName);

NHL Game Calendar​

http://www.nhl.com/gamecenter/en/ajax/gamecalendarjson.htm?month=4&year=2011

Games on the Specified Day​

http://live.nhle.com/GameData/GCScoreboard/2013-02-01.jsonp

This gives a good outlook on the games happening that day and also provides the Game ID's.

Thanks to meetc for the following info!

The returned JSON object can contain the following fields, some of them are not present prior to the start of the game.

PHP:
field                  datatype      descriptipon 
ata                    char(3)       Away team acronym, 3 letter short name 
atc                    text          Before: blank During: "progress" After: "winner" if away team wins 
atcommon               text          away team common name 
atn                    text          away team city name 
ats                    int           away team score 
atsog                  int           Before: null During and After: away team shots on goal 
bs                     time/text     Before: start time (unsure if local or EST) During: 05:10 2nd, eg After: "FINAL", "FINAL OT" etc 
bsc                    text          Before: blank During: "progress" After: "final" 
canationalbroadcasts   text          Canadian TV broadcasters, comma separated list 
gcl                    Bool          gamecenter live? 
gcll                   bool          gamecenter live? 
gs                     int           game status? 1=secheduled, 3= in progress, 5=finished 
hta                    char(3)       home team acronym 
htc                    text          Before: blank During: "progress" After: "winner" if home team wins 
htcommon               text          home team common name 
htn                    text          home team city name 
hts                    int           home team score 
htsog                  int           Before: null During and After: home team shots on goal 
id                     int           game ID 
rl                     Bool          true after game completed 
usnationalbroadcasts   text          US tv broadcasters, comma separated list




Game ID Explained:​

For its web services, each game in the NHL is assigned a GameID which is needed in order to obtain/maintain data for that game. Here are a couple examples of GameIDs and their structure:

Thanks to meetc for the following info!

First 4 digits indicate the year which the season begins
Digits 5,6 indicate the part of the season. 01 is pre-season, 02 is regular season, 03 is playoffs, 09 was used for the Sochi Olympics for the Mens Hockey
Digits 7-10 are the game number for that part of the season. In pre-season and regular season, these are mostly sequential based on the date and time the game starts.
In the playoffs digit 7 is always 0, digit 8 is the round of games (eg 1 preliminary, 2 quarters, 3 conference, 4 finals), digit 9 is a team matchup for that round, and digit 10 is the game number in that series.

NOTE: For Neulion's Video Highlight service (which the NHL uses to manage NHL Game Center), you use the significant digits of the Game Code specified above. So if the game code is 0815, then in the video highlight URL, it will be 815.


Neulion Highlights​

This does not require the Game Center Live subscription!

NHL.com requires you to have NHL GameCenter Live in order to view highlights, but the video is just an MP4 so you can easily track it down.





UPDATE: 3/31/2014

Well, you can now find the highlight video URL really easily.

http://live.nhle.com/GameData/20132014/2013021122/gc/gcgm.jsonp

Replace 2013021122 with the specified game id and 20132014 with the year of that game.

This will return the highlight id's for each video, once you have the id, go to:

http://video.nhl.com/videocenter/servlets/playlist?ids=2013021122-60-h&format=json

Replace 2013021122-60-h with the your highlight id.

It will look something like this:

[**
"id":"2013021122-60-h",
"name":"Corey Crawford Save on Beau Bennett (02:00/1st)",
"trackName":"Corey Crawford Save on Beau Bennett (02:00/1st)",
"description":"Home broadcast - Chicago Blackhawks at Pittsburgh Penguins - March 30, 2014",
"image":"www/thumbs/2014/03/30/591215_es.jpg",
"bigImage":"www/thumbs/2014/03/30/591215_eb.jpg",
"publishPoint":"http://e1.cdnak.neulion.com/nhl/vod/2014/03/30/1122/2_1122_chi_pit_1314_h_discrete_PIT60_save_1_1600.mp4?eid=590676&pid=591215&gid=3000&pt=1",
"formats":"0",
"shareable":true,

"releaseDate":"2014-03-30T19:30:00.000",
"runtime":"0:14","duration":"14"
}]

Which includes everything you'll need to obtain the video source and info!







Ex. Highlight Video URL: http://e1.cdnak.neulion.com/nhl/vod...js_cgy_1314_h_discrete_CGY475_goal_1_1600.mp4


The URL can be accessed without any credentials, let me explain the structure for the URL to view any highlight from a game.

Base URL: http://e1.cdnak.neulion.com/nhl/vod/

/2014/ - Year of the game
/01/ - Month of the game
/30/ - Day of the game
/815/ - Game code (last 3 digits of the gameid)
2_ - It is a static value, always 2
815_ - Game code (last 3 digits of the gameid)
sjs_ - Away team (San Jose Sharks)
cgy_ - Home team (Calgary Flames)
1314_ - Game season (2013 - 2014)
h_discrete_ - Static value
CGY - Home team (Calgary Flames)
475_ - Highlight ID (You can obtain this from PlayByPlay.jsonp, gcbx.jsonp, gcsb.jsonp etc...)
goal_ - Type of highlight (Goal, save, hit etc...)
1_ - I don't really know what this value stands for, it is either 1 or 2
1600 - Bitrate of the highlight (This is the only bitrate available)




Sochi 2014 Olympic Stats:​




Medals for each country:​

http://mapi.sochi2014.com/v1/en/olympic/medal/rating


Ice Hockey Schedule:​

http://mapi.sochi2014.com/v1/en/olympic/results/IHSNR

Ice Hockey Olympic News:​

http://mapi.sochi2014.com/v1/en/olympic/news?page=1&pagesize=24&sport=IH

Olympic Games Schedule for Specified Day:​

http://mapi.sochi2014.com/v1/en/olympic/gamescalendar/?date=2014-02-06

Just change the date parameter YYYY/MM/DD
 
Last edited:
  • Like
Reactions: bur and 666 others

Doctor No

Registered User
Oct 26, 2005
9,250
3,971
hockeygoalies.org
Very interesting stuff!

For hockeygoalies.org, I've always pulled all of my data by hand, just because I've seen enough errors in the data to cause me doubt.

I'd still love to learn more about how to automate the process.
 

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
Very interesting stuff!

For hockeygoalies.org, I've always pulled all of my data by hand, just because I've seen enough errors in the data to cause me doubt.

I'd still love to learn more about how to automate the process.

Wow, I give you massive credit for doing that all manually.

You could create a PHP Server Side script that runs once a day/week/hour etc.. that checks the roster of the teams that played that day (or every single team roster) and get the stats of the goalies. You would then put that data into a MySQL database that your web page would gather info from when a user visits it.

You would have to tweak your website though since in order to extract data from MySQL, you would have to use a server side language like PHP which would then "echo" the tables with the stats.

PHP Example:

singlegame.php



This PHP script generates a live scoreboard image based upon the parameters "gameid" and "date" on the url. It finds the team names, score, shots, plays, and logos, generates it and presents it to the user every single time the page is reloaded. Unlike HTML, it is impossible to see the source code of PHP since it runs server side. PHP files can also generate HTML documents pretty easily so it shouldn't be too much of a task.

ex.

Code:
<html> 
 <title>Calgary Flames Goalie Stats</title>
 <body>
 <h1>CALGARY FLAMES GOALTENDING HISTORY: YEAR-BY-YEAR</h1>

 <?php
 // PHP Code:
 // Extract the data from your database and generate the appropriate tables with the data
 ?>
 
 </body>
 </html>


To avoid the website reloading when going to a new page, you can use an AJAX call to post and receive the data from a PHP script. Efficiency :)

Ex. http://stackoverflow.com/questions/16834138/javascript-function-post-and-call-php-script (or) http://www.w3schools.com/php/php_ajax_database.asp

PHP is a pretty simple language, here is W3 Schools tutorial: http://www.w3schools.com/php/default.asp

This forum (vBulletin) is based off of MySQL and PHP ;)

There are some other ways to do this, but a MySQL database would be your best bet.
 
Last edited:

Doctor No

Registered User
Oct 26, 2005
9,250
3,971
hockeygoalies.org
I do PHP/MySQL on my database side of things. Part of the downside of creating my site in 1994 was that I continued to update the page incrementally, so by the time I went to "databaseize" it, it took me more than two years.

I still need a lot of practice pulling things down from other websites, though. That's next on the old Doug's new trick list. :laugh:
 

Fever

Registered User
Feb 7, 2014
1
0
Me also PHP/MySQL..

Does anyone know much about this JSON data from NHL? Is it for their own GameCenter Live website and their apps?

They dont provide any documentation or anything ... I was just looking for a game result json feed but I guess if you use the gamecenter json you can iterate through and get the results that way.

Edit... Just saw this in the first post:
http://live.nhle.com/GameData/GCScoreboard/2013-02-01.jsonp

This is awesome!!


I have a really good use for this data once I figure it out!
 
Last edited:

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
Me also PHP/MySQL..

Does anyone know much about this JSON data from NHL? Is it for their own GameCenter Live website and their apps?

They dont provide any documentation or anything ... I was just looking for a game result json feed but I guess if you use the gamecenter json you can iterate through and get the results that way.

Edit... Just saw this in the first post:
http://live.nhle.com/GameData/GCScoreboard/2013-02-01.jsonp

This is awesome!!


I have a really good use for this data once I figure it out!

This is the raw data for their NHL GameCenter Website/App services, there is no documentation (unless you worked on the infrastructure) but if you don't understand what a certain attribute means, feel free to ask; shouldn't take too long for me to analyze.

Remember that the URL you linked above is in JSONP and thus needs the "loadScoreboard(***DATA***)" to be removed in order to parse it as JSON.

You use PHP, so here is how you convert the JSONP to JSON:

PHP:
$dayscores = "http://live.nhle.com/GameData/GCScoreboard/" . $gamedate . ".jsonp";
$rawscores = file_get_contents($dayscores);
// Convert JSONP to JSON
$rawscores = preg_replace('/.+?(**.+}).+/','$1',$rawscores);
$rawscores = json_decode($rawscores, true);

To get more data for a specific game as well as more up to the second updated stats, use gcsb.jsonp or some of the other URLs listed.

PHP:
$scoresraw = "http://live.nhle.com/GameData/20132014/" . $gameid . "/gc/gcsb.jsonp";
$gamestats = file_get_contents($scoresraw);
$gamestats = preg_replace('/.+?(**.+}).+/','$1',$gamestats);
$gamestats = json_decode($gamestats, true);
 
Last edited:

meetc

Registered User
Jun 30, 2014
3
0
Thanks a lot for all these data sources, I'm using a few of them for a project I'm working on. I have a few updates for the descriptions of the data sources.

Game ID Explained:

First 4 digits indicate the year which the season begins
Digits 5,6 indicate the part of the season. 01 is pre-season, 02 is regular season, 03 is playoffs, 09 was used for the Sochi Olympics for the Mens Hockey
Digits 7-10 are the game number for that part of the season. In pre-season and regular season, these are mostly sequential based on the date and time the game starts.
In the playoffs digit 7 is always 0, digit 8 is the round of games (eg 1 preliminary, 2 quarters, 3 conference, 4 finals), digit 9 is a team matchup for that round, and digit 10 is the game number in that series.


Games on the Specified Day:
GCScoreboard/yyyy-mm-dd.jsonp

JSON object can contain the following fields, some of them are not present prior to the start of the game.

PHP:
field                  datatype      descriptipon
ata                    char(3)       Away team acronym, 3 letter short name
atc                    text          Before: blank During: "progress" After: "winner" if away team wins
atcommon               text          away team common name
atn                    text          away team city name
ats                    int           away team score
atsog                  int           Before: null During and After: away team shots on goal
bs                     time/text     Before: start time (unsure if local or EST) During: 05:10 2nd, eg After: "FINAL", "FINAL OT" etc
bsc                    text          Before: blank During: "progress" After: "final"
canationalbroadcasts   text          Canadian TV broadcasters, comma separated list
gcl                    Bool          gamecenter live?
gcll                   bool          gamecenter live?
gs                     int           game status? 1=secheduled, 3= in progress, 5=finished
hta                    char(3)       home team acronym
htc                    text          Before: blank During: "progress" After: "winner" if home team wins
htcommon               text          home team common name
htn                    text          home team city name
hts                    int           home team score
htsog                  int           Before: null During and After: home team shots on goal
id                     int           game ID
rl                     Bool          true after game completed
usnationalbroadcasts   text          US tv broadcasters, comma separated list
 

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
Thanks a lot for all these data sources, I'm using a few of them for a project I'm working on. I have a few updates for the descriptions of the data sources.

Game ID Explained:

First 4 digits indicate the year which the season begins
Digits 5,6 indicate the part of the season. 01 is pre-season, 02 is regular season, 03 is playoffs, 09 was used for the Sochi Olympics for the Mens Hockey
Digits 7-10 are the game number for that part of the season. In pre-season and regular season, these are mostly sequential based on the date and time the game starts.
In the playoffs digit 7 is always 0, digit 8 is the round of games (eg 1 preliminary, 2 quarters, 3 conference, 4 finals), digit 9 is a team matchup for that round, and digit 10 is the game number in that series.


Games on the Specified Day:
GCScoreboard/yyyy-mm-dd.jsonp

JSON object can contain the following fields, some of them are not present prior to the start of the game.

PHP:
field                  datatype      descriptipon
ata                    char(3)       Away team acronym, 3 letter short name
atc                    text          Before: blank During: "progress" After: "winner" if away team wins
atcommon               text          away team common name
atn                    text          away team city name
ats                    int           away team score
atsog                  int           Before: null During and After: away team shots on goal
bs                     time/text     Before: start time (unsure if local or EST) During: 05:10 2nd, eg After: "FINAL", "FINAL OT" etc
bsc                    text          Before: blank During: "progress" After: "final"
canationalbroadcasts   text          Canadian TV broadcasters, comma separated list
gcl                    Bool          gamecenter live?
gcll                   bool          gamecenter live?
gs                     int           game status? 1=secheduled, 3= in progress, 5=finished
hta                    char(3)       home team acronym
htc                    text          Before: blank During: "progress" After: "winner" if home team wins
htcommon               text          home team common name
htn                    text          home team city name
hts                    int           home team score
htsog                  int           Before: null During and After: home team shots on goal
id                     int           game ID
rl                     Bool          true after game completed
usnationalbroadcasts   text          US tv broadcasters, comma separated list

Thanks for the info, I've added it to the first post!

All the best for your project
 

aksun

Registered User
Oct 6, 2014
3
0
Oulu, Finland
I found transparent high-quality player pictures from TSN site.

Example picture

API workaround:

Code:
GET http://tsnimages.tsn.ca/ImageProvider/PlayerHeadshot?seoId=[B][name][/B]

So it's pretty easy to use it, just change the [name] to your player's name. There is a couple of things to keep in mind while using this system.
  • Latin alphabets only
  • replace spaces with hyphens(-)
  • replace aphostrophes(') and dots(.) with nothing

PHP for replacing work:

PHP:
$name = str_replace(array(" ", "'", "."), array("-", "", ""), $originalName);

OP can edit this to the first post if he wants to.
 
Last edited:

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
I found transparent high-quality player pictures from TSN site.

Example picture

API workaround:

Code:
GET http://tsnimages.tsn.ca/ImageProvider/PlayerHeadshot?seoId=[B][name][/B]

So it's pretty easy to use it, just change the [name] to your player's name. There is a couple of things to keep in mind while using this system.
  • Latin alphabets only
  • replace spaces with hyphens(-)
  • replace aphostrophes(') and dots(.) with nothing

PHP for replacing work:

PHP:
$name = str_replace(array(" ", "'", "."), array("-", "", ""), $originalName);

OP can edit this to the first post if he wants to.

Great work, but I just don't understand why any reputable company would switch between alpha and numeric parameters for their calls since TSN also assigns ID's to each player.

I've added it to the OP.
 
Last edited:

Ail

Based and Rangerspilled.
Nov 13, 2009
29,140
5,225
Boomerville
I found transparent high-quality player pictures from TSN site.

Example picture

API workaround:

Code:
GET http://tsnimages.tsn.ca/ImageProvider/PlayerHeadshot?seoId=[B][name][/B]

So it's pretty easy to use it, just change the [name] to your player's name. There is a couple of things to keep in mind while using this system.
  • Latin alphabets only
  • replace spaces with hyphens(-)
  • replace aphostrophes(') and dots(.) with nothing

PHP for replacing work:

PHP:
$name = str_replace(array(" ", "'", "."), array("-", "", ""), $originalName);

OP can edit this to the first post if he wants to.

Oh, that is pretty cool. Thanks dude!
 

King Karl

five-year run of unparalleled suffering
Mar 18, 2014
1,128
1,404
Halifax, NS
Wow, I give you massive credit for doing that all manually.

You could create a PHP Server Side script that runs once a day/week/hour etc.. that checks the roster of the teams that played that day (or every single team roster) and get the stats of the goalies. You would then put that data into a MySQL database that your web page would gather info from when a user visits it.

You would have to tweak your website though since in order to extract data from MySQL, you would have to use a server side language like PHP which would then "echo" the tables with the stats.

PHP Example:

singlegame.php



This PHP script generates a live scoreboard image based upon the parameters "gameid" and "date" on the url. It finds the team names, score, shots, plays, and logos, generates it and presents it to the user every single time the page is reloaded. Unlike HTML, it is impossible to see the source code of PHP since it runs server side. PHP files can also generate HTML documents pretty easily so it shouldn't be too much of a task.

ex.

Code:
<html> 
 <title>Calgary Flames Goalie Stats</title>
 <body>
 <h1>CALGARY FLAMES GOALTENDING HISTORY: YEAR-BY-YEAR</h1>

 <?php
 // PHP Code:
 // Extract the data from your database and generate the appropriate tables with the data
 ?>
 
 </body>
 </html>
Very cool stuff. Is there a way to have your tables in SQL automatically check for new stats and have them update themselves?
 

aksun

Registered User
Oct 6, 2014
3
0
Oulu, Finland
Very cool stuff. Is there a way to have your tables in SQL automatically check for new stats and have them update themselves?

I don't think that's possible. At least MySQL is not for that purpose(crawling data). But it's not hard to make a php script to update the table. Use cron jobs for the automatic script run.

good luck.
 

King Karl

five-year run of unparalleled suffering
Mar 18, 2014
1,128
1,404
Halifax, NS
I don't think that's possible. At least MySQL is not for that purpose(crawling data). But it's not hard to make a php script to update the table. Use cron jobs for the automatic script run.

good luck.
Ah ok. I'm not overly familiar with PHP, but I've got a while to learn it. Any pointers you could give to a beginner about interacting between PHP and MySQL?
 

aksun

Registered User
Oct 6, 2014
3
0
Oulu, Finland
Ah ok. I'm not overly familiar with PHP, but I've got a while to learn it. Any pointers you could give to a beginner about interacting between PHP and MySQL?

You should use PDO for the MySQL link, it's best practise nowadays. Don't use mysql_* functions, they are deprecated in PHP.
 

teris

Registered User
Dec 6, 2006
195
0
First of all, many thanks for this thread everyone. Started two different projects thanks to the information here. Figured I should share my own findings as well so here goes.

Thanks to meetc for the following info!

The returned JSON object can contain the following fields, some of them are not present prior to the start of the game.

PHP:
field                  datatype      descriptipon 
ata                    char(3)       Away team acronym, 3 letter short name 
atc                    text          Before: blank During: "progress" After: "winner" if away team wins 
atcommon               text          away team common name 
atn                    text          away team city name 
ats                    int           away team score 
atsog                  int           Before: null During and After: away team shots on goal 
bs                     time/text     Before: start time (unsure if local or EST) During: 05:10 2nd, eg After: "FINAL", "FINAL OT" etc 
bsc                    text          Before: blank During: "progress" After: "final" 
canationalbroadcasts   text          Canadian TV broadcasters, comma separated list 
gcl                    Bool          gamecenter live? 
gcll                   bool          gamecenter live? 
gs                     int           game status? 1=secheduled, 3= in progress, 5=finished 
hta                    char(3)       home team acronym 
htc                    text          Before: blank During: "progress" After: "winner" if home team wins 
htcommon               text          home team common name 
htn                    text          home team city name 
hts                    int           home team score 
htsog                  int           Before: null During and After: home team shots on goal 
id                     int           game ID 
rl                     Bool          true after game completed 
usnationalbroadcasts   text          US tv broadcasters, comma separated list
Just to add to this here's what I received once right before the game was about to start with the relevant parts bolded:
Code:
{
      "atcommon": "DUCKS",
      "canationalbroadcasts": "",
      "ata": "ANA",
      "rl": false,
      "atsog": 0,
      [B]"bs": "PREGAME"[/B],
      "htcommon": "AVALANCHE",
      "id": 2014020168,
      "atn": "ANAHEIM",
      "hts": "",
      "atc": "progress",
      "htn": "COLORADO",
      "usnationalbroadcasts": "",
      "gcl": true,
      "hta": "COL",
      "ats": "",
      "htc": "progress",
      "htsog": 0,
      "bsc": "progress",
      [B]"gs": 2[/B],
      "gcll": true
}
I would assume that "gs": 4 would mean post game broadcasting but I haven't witnessed it. I can confirm that it's US/Eastern time if "bs" has a start time. Secondly...

Ex. Highlight Video URL: http://e1.cdnak.neulion.com/nhl/vod...js_cgy_1314_h_discrete_CGY475_goal_1_1600.mp4


The URL can be accessed without any credentials, let me explain the structure for the URL to view any highlight from a game.

Base URL: http://e1.cdnak.neulion.com/nhl/vod/

/2014/ - Year of the game
/01/ - Month of the game
/30/ - Day of the game
/815/ - Game code (last 3 digits of the gameid)
2_ - It is a static value, always 2
815_ - Game code (last 3 digits of the gameid)
sjs_ - Away team (San Jose Sharks)
cgy_ - Home team (Calgary Flames)
1314_ - Game season (2013 - 2014)
h_discrete_ - Static value
CGY - Home team (Calgary Flames)
475_ - Highlight ID (You can obtain this from PlayByPlay.jsonp, gcbx.jsonp, gcsb.jsonp etc...)
goal_ - Type of highlight (Goal, save, hit etc...)
1_ - I don't really know what this value stands for, it is either 1 or 2
1600 - Bitrate of the highlight (This is the only bitrate available)
"h_discrete" is not actually static but two different variables. Replace "h" with "a" to get the away feed of the same highlight. It works most of the time including your example but sometimes only home or away is available. Next thing seems to be mostly for goals and home feeds but you can sometimes replace "discrete" with "ingame". It just gives you the same highlight but shorter with less buildup and no replays. There's also another base url. To demonstrate...

http://nhl.cdnllnwnl.neulion.net/u/nhlmobile/vod/nhl/2014/11/08/204/2_204_nyr_tor_1415_h_discrete_tor579_goal_1_1600.mp4

http://nhl.cdnllnwnl.neulion.net/u/nhlmobile/vod/nhl/2014/11/08/204/2_204_nyr_tor_1415_a_discrete_tor579_goal_1_1600.mp4

http://nhl.cdnllnwnl.neulion.net/u/nhlmobile/vod/nhl/2014/11/08/204/2_204_nyr_tor_1415_h_ingame_tor579_goal_1_1600.mp4
 

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
"h_discrete" is not actually static but two different variables. Replace "h" with "a" to get the away feed of the same highlight.

Yeah, I saw this a long time ago when I was generating a tables that stored the URLs of every "highlight" for the past couple of years.

Also, it is hilarious that the full-length replays of each game do not require any credentials; so I just got the replays of every game for the past couple of years in a table by replicating the URL structure. At least the streams require credentials to view them.
 

King Karl

five-year run of unparalleled suffering
Mar 18, 2014
1,128
1,404
Halifax, NS
Ok, so for a project, I'm looking to pull statistics from here, and the update an SQL database automatically with the information. I'd also like to do this for every team. How would I go about doing this? Most importantly though, is how would I take the information from that page and turn it into an SQL query, solely using PHP?
(I literally only started using PHP yesterday)
 
Last edited:

Step7750

Registered User
Jan 24, 2014
55
1
Calgary, Alberta
Ok, so for a project, I'm looking to pull statistics from here, and the update an SQL database automatically with the information. I'd also like to do this for every team. How would I go about doing this? Most importantly though, is how would I take the information from that page and turn it into an SQL query, solely using PHP?
(I literally only started using PHP yesterday)

Do know programming basics such as looping and recursion? If not, you should spend time in that area before you undertake any project.

Here are some tips:

- Loop through the url with an array consisting of the abbreviations:

"devils": "NJD",
"islanders": "NYI",
"rangers": "NYR",
"flyers": "PHI",
"penguins": "PIT",
"bruins": "BOS",
"sabres": "BUF",
"canadiens": "MTL",
"senators": "OTT",
"mapleleafs": "TOR",
"hurricanes": "CAR",
"panthers": "FLA",
"lightning": "TBL",
"capitals": "WSH",
"blackhawks": "CHI",
"redwings": "DET",
"predators": "NSH",
"blues": "STL",
"flames": "CGY",
"avalanche": "COL",
"oilers": "EDM",
"canucks": "VAN",
"ducks": "ANA",
"stars": "DAL",
"kings": "LAK",
"coyotes": "PHX",
"sharks": "SJS",
"bluejackets": "CBJ",
"wild": "MIN",
"jets": "WPG"

- While I don't particularly like W3Schools, try to figure out the structure of the Insert and Update statements for SQL (http://www.w3schools.com/sql/sql_insert.asp).

- You'll need to parse the json on the page using "json_decode" (http://php.net/manual/en/function.json-decode.php) and then loop through the given array to extract the needed info

- You may want a tool such as phpMyAdmin (http://www.phpmyadmin.net/home_page/index.php) to allow easier administration for the database(s)
 

King Karl

five-year run of unparalleled suffering
Mar 18, 2014
1,128
1,404
Halifax, NS
Do know programming basics such as looping and recursion? If not, you should spend time in that area before you undertake any project.

Here are some tips:

- Loop through the url with an array consisting of the abbreviations:

"devils": "NJD",
"islanders": "NYI",
"rangers": "NYR",
"flyers": "PHI",
"penguins": "PIT",
"bruins": "BOS",
"sabres": "BUF",
"canadiens": "MTL",
"senators": "OTT",
"mapleleafs": "TOR",
"hurricanes": "CAR",
"panthers": "FLA",
"lightning": "TBL",
"capitals": "WSH",
"blackhawks": "CHI",
"redwings": "DET",
"predators": "NSH",
"blues": "STL",
"flames": "CGY",
"avalanche": "COL",
"oilers": "EDM",
"canucks": "VAN",
"ducks": "ANA",
"stars": "DAL",
"kings": "LAK",
"coyotes": "PHX",
"sharks": "SJS",
"bluejackets": "CBJ",
"wild": "MIN",
"jets": "WPG"

- While I don't particularly like W3Schools, try to figure out the structure of the Insert and Update statements for SQL (http://www.w3schools.com/sql/sql_insert.asp).

- You'll need to parse the json on the page using "json_decode" (http://php.net/manual/en/function.json-decode.php) and then loop through the given array to extract the needed info

- You may want a tool such as phpMyAdmin (http://www.phpmyadmin.net/home_page/index.php) to allow easier administration for the database(s)
Awesome. Thanks so much for your help. I'll post the finished product on here when it's done.
 

Ad

Upcoming events

Ad

Ad

-->