我的酷狗音乐2018年年度报告

我的酷狗音乐2018年年度报告

分析完网易云音乐的报告之后就该分析酷狗音乐的了。我的酷狗音乐年度报告的地址为:你好,时光

您好,振兴为您提供年度音乐报告。

——丁文亮

同样,酷狗音乐的年度报告也是不能直接用电脑浏览器查看的。

这个get_data?...返回的数据就是我们需要的数据了,是个GET请求,把链接复制过来:
https://inventory2018.kugou.com/v1/user/get_data?callback=jQuery331014765760677391482_1546609118219&user_id=978183797&key=1f74e7bf&_=1546609118220
这个链接返回的不是纯json格式的数据,而是有个这个东西:

显然不是好东西,但是如果你把链接改成这个:
https://inventory2018.kugou.com/v1/user/get_data?format=json&user_id=978183797&key=1f74e7bf&_=1546609118220

返回的数据就是纯json格式的数据了。

下面开始进行年度总结:

首先把json文件下载下来保存起来:kugou2018.json

1
2
3
4
library(jsonlite)
download.file('https://inventory2018.kugou.com/v1/user/get_data?format=json&user_id=978183797&key=1f74e7bf&_=1546608016821', 'kugou2018.json')
df <- read_json('kugou2018.json')
df <- df$data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
> # 注册时间:
> df$reg_time
[1] "20161130"
>
> # 注册天数
> df$reg_days
[1] 761
>
> # 今年听歌总数
> df$play_scids
[1] 786
>
> # 今年播放总次数
> df$play_nums
[1] 4848
>
> # 今年听歌累计时长(分钟)
> df$play_times
[1] 18530
>
> # 这个是时间超过了这么多人
> df$play_order
[1] "92%"
>
> # 今年我有这么多天在听歌
> df$play_days
[1] 92

最长听歌时段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
df$time_interval$data %>% data.frame() -> time_interval
time_interval <- t(time_interval) %>% as.data.frame()
row.names(time_interval) <- 0:23
colnames(time_interval) <- c('weight')
time_interval$time <- 0:23
time_interval$weight <- as.numeric(time_interval$weight)

library(RColorBrewer)
ggplot(data = time_interval) +
geom_col(aes(x = factor(time), y = weight,
fill = factor(time))) +
theme_ipsum(
base_family = 'STSongti-SC-Bold'
) +
scale_fill_manual(values = c(brewer.pal(12, 'Set3'), brewer.pal(12, 'Set3'))) +
guides(fill = 'none') +
labs(x = '时刻', y = '权重',
title = '每日最长听歌时段',
subtitle = '横轴对应每个小时段',
caption = '数据来源:酷狗音乐\nhttp://www.kugou.com/')

最受喜欢的三个歌手:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
top3_singer <- data.frame(
name = NA,
pic = NA,
times = NA
)

for(i in 1:length(df$top5_singer$data)){
top3_singer <- rbind(
top3_singer,
data.frame(
name = df$top5_singer$data[[i]]$name,
pic = df$top5_singer$data[[i]]$pic,
times = df$top5_singer$data[[i]]$times
)
)
};rm(i);

top3_singer <- subset(top3_singer, !is.na(top3_singer$name))
top3_singer$pic <- gsub(pattern = '\\{size\\}', replacement = '240', top3_singer$pic)

top3_singer$times <- as.numeric(top3_singer$times)
top3_singer$name <- factor(top3_singer$name)

library(ggimage)
ggplot(
data = top3_singer
) +
geom_col(aes(x = name, y = times,
fill = name)) +
geom_image(aes(x = name, y = times + 50, image = pic), size = 0.1) +
hrbrthemes::theme_ipsum(
base_family = 'STSongti-SC-Bold'
) +
scale_fill_brewer(palette = 'Set2') +
guides(fill = 'none') +
theme(axis.title.x = element_blank()) +
labs(y = '听歌次数',
title = '最爱的三个歌手',
subtitle = '按照播放次数的标准',
caption = '数据来源:酷狗音乐\nhttp://www.kugou.com/')

最常听的三十首歌曲:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
top10_scid <- data.frame(
days = NA,
name = NA,
s_id = NA
)

for(i in 1:length(df$top10_scid$data)){
top10_scid <- rbind(
top10_scid,
data.frame(
days = df$top10_scid$data[[i]]$days,
name = df$top10_scid$data[[i]]$name,
s_id = df$top10_scid$data[[i]]$s_id
))
};rm(i)

top10_scid <- subset(top10_scid, !is.na(top10_scid$days))
top10_scid$days <- as.numeric(top10_scid$days)
top10_scid$singer <- gsub(pattern = '( - .*)', replacement = '', top10_scid$name)
top10_scid$songname <- gsub(pattern = '(.* - )', replacement = '', top10_scid$name)

top10_scid$name <- factor(
top10_scid$name,
levels = arrange(top10_scid, days)$name)
ggplot(data = top10_scid) +
geom_col(aes(x = name, y = days, fill = name)) +
scale_fill_manual(values = c(
brewer.pal(12, 'Set3'),
brewer.pal(12, 'Set3'),
brewer.pal(6, 'Set3')
)) +
labs(title = '酷狗音乐听歌榜',
subtitle = '程振兴 | 酷狗音乐',
caption = '数据来源:酷狗音乐\nhttp://www.kugou.com/',
y = '播放次数') +
theme_ipsum(
base_family = 'STSongti-SC-Bold'
) +
guides(fill = 'none') +
coord_flip() +
theme(axis.title.y = element_blank())

再看看我的年度标签词云:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tagcloud <- data.frame(
word = NA,
weight = NA
)

for(i in 1:length(df$keyword$data$list)){
tagcloud <- rbind(
tagcloud,
data.frame(
word = df$keyword$data$list[[i]]$word,
weight = df$keyword$data$list[[i]]$weight %>% as.numeric()
))
};rm(i)

tagcloud <- subset(tagcloud, !is.na(tagcloud$word))

下面我用三个R包绘制了词云:

1
2
3
4
# 词云1
# devtools::install_github('adymimos/rWordCloud')
library(rWordCloud)
d3Cloud(text = tagcloud$word, size = tagcloud$weight)

1
2
3
4
5
6
7
8
9
10
11
12
13
# 词云2
tagcloud$color = c(brewer.pal(10, 'Set3'), brewer.pal(10, 'Set3'))
library(echarts4r)
tagcloud %>%
e_color_range(weight, color, colors = c(brewer.pal(9, 'Set1'))) %>%
e_charts() %>%
e_cloud(word, weight, shape = "rectangle",
sizeRange = c(50, 80),
color = color) %>%
e_title("我的酷狗音乐年度标签词云",
textStyle = list("fontSize" = 30,"fontFamily" = "STSong"),
textAlign = "middle", left = "50%") %>%
e_theme("macarons")

1
2
3
4
5
6
# 词云3
library(wordcloud2)
wordcloud2(tagcloud, color = tagcloud$color, size = 0.7,
backgroundColor = '#e5f5f9',
fontFamily = 'STSongti-SC-Bold',
rotateRatio = 0)

风格成分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
style <- data.frame(
name = c("古风", "民谣", "中国风"),
proportion = c(0.3578, 0.3211, 0.2202)
)

ggplot(data = style, aes(x = 'temp', y = proportion, fill = name)) +
geom_bar(stat = 'identity', position = 'stack') +
geom_text(aes(x = 'temp', y = 0.75, label = '古风\n35.78%'), family = 'STSong', size = 6, color = I('white')) +
geom_text(aes(x = 'temp', y = 0.38, label = '民谣\n32.11%'), family = 'STSong', size = 6, color = I('white')) +
geom_text(aes(x = 'temp', y = 0.12, label = '中国风\n22.02%'), family = 'STSong', size = 6, color = I('white')) +
coord_polar(theta = 'y') +
theme_ipsum(
base_family = 'STSongti-SC-Bold'
) +
scale_fill_brewer(palette = 'Set2') +
theme(axis.title = element_blank(),
axis.text = element_blank(),
panel.grid = element_blank()) +
guides(fill = 'none') +
labs(title = '我的音乐类型偏好',
subtitle = '酷狗音乐 | 程振兴',
caption = '数据来源:酷狗音乐\nhttp://www.kugou.com/')

最后再把酷狗音乐的年度报告截图保存:
















# R

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×