Skip to content

Commit 4d15151

Browse files
authored
Merge pull request #1 from ntsd/master
Add hidden cover image option
2 parents 6ddb02a + d8b253a commit 4d15151

4 files changed

Lines changed: 57 additions & 7 deletions

File tree

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SPOTIFY_CLIENT_ID='___'
2+
SPOTIFY_SECRET_ID='____'
3+
BASE_URL='http://localhost:3000/api'
4+
FIREBASE='__BASE64_FIREBASE_JSON_FILE__'

api/templates/callback.html.j2

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,25 @@
4141
<div class="container">
4242
<br><br>
4343
<h2 class="header center orange-text">Markdown code</h2>
44+
45+
<div class="row center">
46+
<div class="row">
47+
<div class="col s6 m4">
48+
<label>
49+
<input type="checkbox" class="filled-in" checked="checked" id="cover-image-checkbox" />
50+
<span>Cover Image</span>
51+
</label>
52+
</div>
53+
<div class="col s6 m4"></div>
54+
<div class="col s6 m4"></div>
55+
</div>
56+
</div>
57+
4458
<div class="row center">
4559
<div class="col s0 m1"></div>
4660
<div class="col s12 m10">
4761
<textarea id="markdown-code"
48-
style="width: 100%;height: 100px; padding: 10px;">[![spotify-github-profile]({{BASE_URL}}/view?uid={{uid}})](https://github.com/kittinan/spotify-github-profile)</textarea>
62+
style="width: 100%;height: 100px; padding: 10px;"></textarea>
4963
</div>
5064
<div class="col s0 m1"></div>
5165
</div>
@@ -59,8 +73,7 @@
5973
</div>
6074

6175
<div class="row center">
62-
<img src="{{BASE_URL}}/view?uid={{uid}}" />
63-
76+
<img id="example-view" />
6477
</div>
6578
<br><br>
6679

@@ -82,6 +95,35 @@
8295
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
8396
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js"></script>
8497

98+
<script>
99+
var uid = "{{uid}}";
100+
var viewUrl = "{{BASE_URL}}/view?";
101+
var markdownCodeTextArea = $('#markdown-code');
102+
var exampleView = $("#example-view");
103+
var urlParams = {
104+
uid: uid,
105+
cover_image: true,
106+
};
107+
108+
function updateUrl() {
109+
var viewUrlWithParams = viewUrl + $.param(urlParams, true);
110+
exampleView.attr('src', viewUrlWithParams);
111+
markdownCodeTextArea.text(`[![spotify-github-profile](${viewUrlWithParams})](https://github.com/kittinan/spotify-github-profile)`);
112+
}
113+
114+
updateUrl();
115+
116+
var coverImageCheckbox = $("#cover-image-checkbox");
117+
coverImageCheckbox.change(function() {
118+
if(this.checked) {
119+
urlParams.cover_image = true;
120+
} else {
121+
urlParams.cover_image = false;
122+
}
123+
updateUrl();
124+
});
125+
</script>
126+
85127
<script>
86128
var clipboard = new ClipboardJS('.btn');
87129
clipboard.on('success', function (e) {

api/templates/spotify.html.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@
9595
<div id='bars'>
9696
{{content_bar|safe}}
9797
</div>
98+
99+
{% if cover_image %}
98100
<a href="{}" target="_BLANK">
99101
<center>
100102
<img src="data:image/png;base64, {{img}}" width="300" height="300" class="cover" />
101103
</center>
102104
</a>
105+
{% endif %}
103106

104107
{% else %}
105108
<div class="playing not-play">Nothing playing on Spotify</div>

api/view.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def load_image_b64(url):
5555

5656

5757
@functools.lru_cache(maxsize=128)
58-
def make_svg(artist_name, song_name, img, is_now_playing):
58+
def make_svg(artist_name, song_name, img, is_now_playing, cover_image):
5959

6060
print("make_svg")
6161

62-
height = 445
62+
height = 445 if cover_image else 145
6363
num_bar = 75
6464

6565
if is_now_playing:
@@ -79,8 +79,8 @@ def make_svg(artist_name, song_name, img, is_now_playing):
7979
"title_text": title_text,
8080
"artist_name": artist_name,
8181
"song_name": song_name,
82-
"content_bar": content_bar,
8382
"img": img,
83+
"cover_image": cover_image,
8484
}
8585

8686
return render_template("spotify.html.j2", **rendered_data)
@@ -100,6 +100,7 @@ def catch_all(path):
100100
global CACHE_TOKEN_INFO
101101

102102
uid = request.args.get("uid")
103+
cover_image = request.args.get("cover_image", default='true') == 'true'
103104

104105
# Load token from cache memory
105106
token_info = get_cache_token_info(uid)
@@ -165,7 +166,7 @@ def catch_all(path):
165166
artist_name = item["artists"][0]["name"]
166167
song_name = item["name"]
167168

168-
svg = make_svg(artist_name, song_name, img, is_now_playing)
169+
svg = make_svg(artist_name, song_name, img, is_now_playing, cover_image)
169170

170171
resp = Response(svg, mimetype="image/svg+xml")
171172
resp.headers["Cache-Control"] = "s-maxage=1"

0 commit comments

Comments
 (0)