A simple command line application to generate static HTML page for music groups with data acquired from their facebook, instagram and spotify profiles.
My primary goal is to create a software that is able to generate an up to date HTML page for my band based on recent activities from our social pages. The execution can be automated so this way the page can be updated regularly with new music, videos and gigs withous any manual interaction.
This project however doesn't intend to eliminate the work that must be done on the web design, so it uses Handlebars.Net as a templating system for the processed HTML. In other words, user of this software has to sitebuild his own template.
You can see a working example here: https://sz4p.hu
You can download the latest release from the releases page of this repository.
The project is built with dotnet core 3.1 so it needs dotnet runtime to be run. You can download it here
Optionally, the app can be published to any platform as a standalone by dotnet SDK if you clone the repository.
The app is configured with command line options and a settings JSON file.
-o: The absolute path to the generated HTML page; example:C:\BandPage\index.html-t: The absolute path to the folder that contains the Handlebars template from which the output is generated. The template has to be named index.html (in a future release Handlebars partials can be loaded from here with other names)
example:C:\BandPage\Template-s: The absolute path to the settings JSON file; example:C:\BandPage\settings.json-d: (optional) The absolute path to the folder where the image files (photos, cover images, etc.) will be downloaded. The images are served from the original facebook, instagram, youtube and spotify sources if not set); example:C:\BandPage\downloads
IMPORTANT: The settings file includes sensitive API keys that should not be exposed publicly!
Example settings file can be found here
FacebookPageId: unique facebook id of the band's facebook page, usually it is the unique url behind www.facebook.com/InstagramId: unique id of the band's instagram account (must be linked with facebook page as instagram business page!)
you can find it with online tools like thisFilterHashtags: array of hashtags to filter instagram images (only images using any of these hashtags will be pusblished on the page)
example:["#hashtag1", "#hashtag2]AlbumId: facebook graph id of a facebook photo album that is displayed on the pageApiVersion: facebook graph api version to use (usev3.2as it is the most recent when writing this)AccessToken: API access token to make requests to facebook API see belowPastEventDisplayLimit: How many past events you want to display on the page
YoutubeApiKey: key to access Youtube data API see belowChannelId: Id of the band's youtube channelAdditionalVideoIds: an array of videos that are not published on the band's channel but is a band video (added to cumulated view count of the channel)FeaturedPlaylistId: A youtube playlist from which videos are fetched to be played on the page
SpotifyClientId: spotify API client ID see belowClientSecret: spotify API client secret see belowArtistId: spotify artist IDAlternativeLinks: an array of titled album link collection to other providers (like bandcamp, itunes, etc.)Title: the title of the album (albums are associated with the ones fetched from spotify API by title)Links: key-value pairs of provider and album link, example:{ "bandcamp": "https://band.bandcamp.com/album/some-album" }
GeneralDownloadedBasePath: used only if-dcommand line option is used, image paths are appended to this, so it has to contain the url where the page is going to be hosted; example:https://myband.com/downloads
The app can be run from the folder where it is downloaded with the above example values like this:
dotnet BandPageGenerator.dll -o C:\BandPage\index.html -t C:\BandPage\Template -s C:\BandPage\settings.json -d C:\BandPage\downloads
You will need different API keys and tokens to access your social data with this app. These can be acquired differently from each provider.
Note: figuring this process out was almost as much work as to write this entire software. How ironic that it is nearly impossible to use graph api to access PUBLIC data from your own page while all the facebook partners are gathering the users' private data haha.
At the time of writing this, the Graph API is in v3.2 version. The only way to use it for accessing public data from your page is to create an API app and leave it in development mode.
Other prerequisites to make it work:
- you have to be the owner of the app
- you have to be admin on the facebook page you want to access
- your instagram account must be linked with your facebook page as a business account
Steps to acquire a never expiring access token to your page:
- On https://developers.facebook.com click on My apps, then Add new app
- Give your app a name and create it
- In Products + section of the dashboard, add Marketing API (click Set Up)
- Go back to Products and add Instagram too
- Go to Marketing API > Tools
- In Get Access Token section check all the checkboxes and click "Get Token"
- Copy the given token
- Go to Graph API Explorer
- On the right select your Facebook App
- Under permission type "instagram_basic" in the "Add a Permission" field
- Click Get Access Token button on the bottom
- Accept the popup
- Above the Get token button paste the previously (7th step) copied token
- Select your band's facebook page from the User or Page dropdown
- Go back to Access Token field (where you pasted the previous token) and save its content, this is your final token
- Check it on Access Token Debugger
You should see something like this:
- Type: Page
- Page ID: your band page ID and name
- Expires: Never
This token has to be set in the Facebook > AccessToken settings.
- Go to Google Developer Console and sign in with your google account
- Click on top left dropdown, then click create a project
- Give it a name and create it
- Go to Library on the left menu
- Search for Youtube Data API v3
- Select it and click on Enable
- Go to Credentials on the left menu
- Click + Create credential
- For the Where will you be calling the API from? question select Other non-UI
- From the radio buttons select public data
- Click the button, save the key that is presented
This key should be set in the Youtube > ApiKey settings
- Go to Spotify developer dashboard
- Log in to Spotify
- Click create client id
- Fill in the form, select Desktop app checkbox
- Click 'No' on the next page (Are you developing a commercial integration?)
- Check all the checkboxes and continue
- Copy your client ID to settings JSON:
Spotify > ClientId - Click 'Show client secret' and copy the value to settings JSON:
Spotify > ClientSecret
In the provided template index.html one can use Handlebars syntax to display gathered data from provider APIs. For full reference of the syntax, visit https://handlebarsjs.com/
An example template is included in this project, you can browse it here
Likes: Facebook page like countProfilePictureUrl: Url of facebook page profile pictureUpcomingEvents: Page events in the future, array of FacebookEventModelPastEvents: Past page events limited byPastEventDisplayLimitcount, array of FacebookEventModelFeaturedPhotos: Featured facebook photo album (specified by album ID in facebook settings), array of FacebookPhotoModelMemberPhotos: Member facebook photo album (note that captions of member photos on facebook have to have a line break in them, the first line is member name, the last is description), array of FacebookMemberPhotoModelInstagramPhotos: Recent instagram photos, array of FacebookInstagramMediaModelViewCount: Cumulated view count of all videos of the band on YoutubeVideos: Videos of featured playlist on Youtube (specified byFeaturedPlaylistIdin settings), array of YoutubeVideoModelAlbums: Albums of band on Spotify, array of SpotifyAlbumTemplateModel
Id: Id of the eventCategory: Category of the eventName: Name of the eventDescription: Raw text description of the eventFormattedDescription: Description of the event formatted with HTML line breaks and linksStartTime: DateTime of event start, can be displayed with date helperEndTime: DateTime of event end, can be displayed with date helperTicketUri: URL of ticket purchase linkCover: The event cover pictureId: Cover photo IDOffsetX: Offset X of facebook display on event pageOffsetY: Offset Y of facebook display on event pageSource: URL of the picture
Place: Place object of the event locationId: Place IDName: Place nameLocation: Geographical location of placeNameCityCountryStateStreetZipLatitudeLongitude
IdHeightWidthSource: URL of the picture
Has all the properties of FacebookPhotoModel, plus:
Name: Name of the member, first line of the facebook photo captionDescription: Description of the member, second line of the facebook photo caption
IdMediaType: String representation of type, alwaysIMAGEMediaUrl: URL of the pictureCaption: Instagram caption of the picturePermalink: URL of the origin instagram postTimestamp: DateTime of the upload, can be displayed with date helper
IdTitle: Title of the videoPublishedAt: DateTime of publication, can be displayed with date helperDescriptionThumbnail: thumbnail pictureUrl: URL of the thumbnail imageWidthHeight
IdAlbumType: The type of the album: one of "album" , "single" , or "compilation"Label: Publishing labelName: Title of the albumReleaseDate: DateTime of the release, can be displayed with date helperType: "album"Image: Cover of the albumUrlWidthHeight
Tracks: list of tracks on the album, array of SpotifyTrackModelAlternativeLinks: list of links on other streaming platforms, defined in in settings
IdName: Title of the trackTrackNumber: The number of the track on the albumDurationMs: Duration in millisecondsDuration: Duration in TimeSpan, can be displayed with interval helper
Built in Handlebars helpers for displaying certain types of data
Formats a DateTime object based on standard .NET DateTime format string
Example usage: {{date UpcomingEvents.0.StartTime 'yyyy. MM. dd. HH:mm'}}
Output: 2019. 12. 24. 20:00
Formats a TimeSpan object based on standard .NET TimeSpan format string
Example usage: {{interval Albums.0.Tracks.0.Duration '\:mm\:ss'}}
Output: 05:23
You can host your own page for free on GitLab and set it up to be automatically refreshed, pulling new data from social sites. I've set up a skeleton project, you can make your own page in a few steps:
- Register a user on GitLab: https://gitlab.com/users/sign_in#register-pane
Carefully choose your username, because your page address is going to be username.gitlab.io - Confirm your email address and log in
- Go to the prototype project page: https://gitlab.com/codernr/band-page-generator-auto-prototype
- Click 'Fork' on the top right, now you have your own version of the project
- Go to Settings > General menu
- Under 'Permissions' set your project visibility to private. This is important, because you will store sensitive API keys in your settings.json
- Under 'Advanced', click 'Remove fork relationship' button
- Under 'Advanced > Rename repository', set your project path from
band-page-generator-auto-prototypetoyour-username.gitlab.io - Go to 'Repository > Files' in the menu
- Open
settings.jsonand edit it as described in settings documentation - Open
public/index.htmland edit your template HTML as you wish
After each modification a CI page publish pipeline runs that you can see in the menu CI/CD. After a while (sometimes can take an hour), your page will be available under https://your-username.gitlab.io
The point in this project is that you have to create your page template once and it gets updated with new data from your social accounts. If you have a new event on your facebook, new picture on your instagram or new release on spotify, it should appear on your page automatically without touching it.
To achieve this, you can set a schedule to run the generation periodically:
- Go to CI/CD > Schedules
- Click on New Schedule
- Name it
- Set Interval Pattern to Every day (4:00am)
- Set your timezone
- Click Save pipeline schedule
Now this generation pipeline will run every day at 4:00am, so your social updates will appear on your site next day!