This commit is contained in:
2024-05-23 17:51:06 +08:00
parent f6582be3f0
commit bc34a4f839
3 changed files with 173 additions and 60 deletions

View File

@@ -236,6 +236,9 @@ def generate_audio_report(pdb: PlaybackReportingDb, itemMap, rowMap, albumMap,
data = pdb.get_activitys(offset, itemType='Audio', userId=userId, data = pdb.get_activitys(offset, itemType='Audio', userId=userId,
startTime=startTime, endTime=endTime) startTime=startTime, endTime=endTime)
albumCountMap = {} albumCountMap = {}
trackCountMap = {}
artistCountMap = {}
alArtCountMap = {}
with CSVFile(join(output, "history.csv")) as his: with CSVFile(join(output, "history.csv")) as his:
his.write(_("Id"), _("Date"), _("Time"), _("Name"), _("Artists"), _("Album"), _("Album artists"), _("Duration"), _("Duration") + _("(seconds)"), _("Original item id"), _("Item id"), _("Play duration"), _("Play duration") + _("(seconds)"), _("Record content"), _("Client name"), _("Device name"), _("Playback method"), _("Play count")) # noqa: E501 his.write(_("Id"), _("Date"), _("Time"), _("Name"), _("Artists"), _("Album"), _("Album artists"), _("Duration"), _("Duration") + _("(seconds)"), _("Original item id"), _("Item id"), _("Play duration"), _("Play duration") + _("(seconds)"), _("Record content"), _("Client name"), _("Device name"), _("Playback method"), _("Play count")) # noqa: E501
while len(data) > 0: while len(data) > 0:
@@ -283,6 +286,43 @@ def generate_audio_report(pdb: PlaybackReportingDb, itemMap, rowMap, albumMap,
albumCountMap[album] = {'count': 1, albumCountMap[album] = {'count': 1,
'play_count': play_count, 'play_count': play_count,
'duration': play_duration} 'duration': play_duration}
if itemId in trackCountMap:
tmp = trackCountMap[itemId]
tmp['count'] += 1
tmp['play_count'] += play_count
tmp['duration'] += play_duration
else:
trackCountMap[itemId] = {'count': 1,
'play_count': play_count,
'duration': play_duration}
if artists:
for art in artists.split("|"):
ar = art.strip()
if ar in artistCountMap:
tmp = artistCountMap[ar]
tmp['count'] += 1
tmp['play_count'] += play_count
tmp['duration'] += play_duration
else:
artistCountMap[ar] = {'count': 1,
'play_count': play_count,
'duration': play_duration}
if album_artists:
if 'type' in item:
arts = album_artists.split("|")
else:
arts = album_artists.split(",")
for art in arts:
ar = art.strip()
if ar in alArtCountMap:
tmp = alArtCountMap[ar]
tmp['count'] += 1
tmp['play_count'] += play_count
tmp['duration'] += play_duration
else:
alArtCountMap[ar] = {'count': 1,
'play_count': play_count,
'duration': play_duration}
offset += len(data) offset += len(data)
data = pdb.get_activitys(offset, itemType='Audio', userId=userId, data = pdb.get_activitys(offset, itemType='Audio', userId=userId,
startTime=startTime, endTime=endTime) startTime=startTime, endTime=endTime)
@@ -316,3 +356,52 @@ def generate_audio_report(pdb: PlaybackReportingDb, itemMap, rowMap, albumMap,
if date.endswith("-01-01 00:00:00"): if date.endswith("-01-01 00:00:00"):
date = None date = None
al.write(album, album_artists, artists, count['count'], count['play_count'], format_duration(count['duration']), count['duration'], format_duration(duration), duration, year, date, publisher, itemId) # noqa: E501 al.write(album, album_artists, artists, count['count'], count['play_count'], format_duration(count['duration']), count['duration'], format_duration(duration), duration, year, date, publisher, itemId) # noqa: E501
with CSVFile(join(output, 'track.csv')) as tr:
tr.write(_("Name"), _("Artists"), _("Record count"), _("Play count"), _("Play duration"), _("Play duration") + _("(seconds)"), _("Duration"), _("Duration") + _("(seconds)"), _("Album"), _("Album artists"), _("Genres"), _("Track no"), _("Disc no"), _("Year"), _("Publish date"), _("Publisher"), _("Item id")) # noqa: E501
for itemId in trackCountMap:
item = itemMap[itemId]
count = trackCountMap[itemId]
name = ''
artists = ''
album = ''
album_artists = ''
genres = ''
track = None
disc = None
year = None
date = None
publisher = None
duration = None
if 'type' in item:
name = item['Name']
artists = item['Artists']
album = item['Album']
album_artists = item['AlbumArtists']
genres = item['Genres']
track = item['IndexNumber']
disc = item['ParentIndexNumber']
duration = item['RunTimeTicks'] / TIME_BASE
year = item['ProductionYear']
date = item['PremiereDate']
publisher = item['Studios']
else:
it = ITEMNAME_PATTERN.match(item['ItemName']).groupdict()
name = it['track']
if it['album'] != NOT_KNOWN:
album = it['album']
if it['album_artist'] != NOT_KNOWN:
album_artists = it['album_artist']
if year and date:
if date.endswith("-01-01 00:00:00"):
date = None
tr.write(name, artists, count['count'], count['play_count'], format_duration(count['duration']), count['duration'], format_duration(duration), duration, album, album_artists, genres, track, disc, year, date, publisher, itemId) # noqa: E501
with CSVFile(join(output, 'artist.csv')) as ar:
ar.write(_("Name"), _("Record count"), _("Play count"), _("Play duration"), _("Play duration") + _("(seconds)")) # noqa: E501
for artist in artistCountMap:
count = artistCountMap[artist]
ar.write(artist, count['count'], count['play_count'], format_duration(count['duration']), count['duration']) # noqa: E501
with CSVFile(join(output, 'album_artist.csv')) as alAr:
alAr.write(_("Name"), _("Record count"), _("Play count"), _("Play duration"), _("Play duration") + _("(seconds)")) # noqa: E501
for artist in alArtCountMap:
count = alArtCountMap[artist]
alAr.write(artist, count['count'], count['play_count'], format_duration(count['duration']), count['duration']) # noqa: E501

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: jellyfinStats 1.0\n" "Project-Id-Version: jellyfinStats 1.0\n"
"Report-Msgid-Bugs-To: [email protected]\n" "Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-05-16 10:47+0800\n" "POT-Creation-Date: 2024-05-23 16:35+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n" "Language-Team: LANGUAGE <[email protected]>\n"
@@ -17,31 +17,31 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: __main__.py:20 #: __main__.py:11
msgid "The path to config file." msgid "The path to config file."
msgstr "" msgstr ""
#: __main__.py:21 #: __main__.py:12
msgid "The path to playback_reporting.db" msgid "The path to playback_reporting.db"
msgstr "" msgstr ""
#: __main__.py:22 #: __main__.py:13
msgid "The path to library.db" msgid "The path to library.db"
msgstr "" msgstr ""
#: __main__.py:23 #: __main__.py:14
msgid "The path to jellyfin data directory." msgid "The path to jellyfin data directory."
msgstr "" msgstr ""
#: __main__.py:24 #: __main__.py:15
msgid "The directory for output files." msgid "The directory for output files."
msgstr "" msgstr ""
#: __main__.py:25 #: __main__.py:16
msgid "Specify maximum items to display in one page." msgid "Specify maximum items to display in one page."
msgstr "" msgstr ""
#: __main__.py:26 #: __main__.py:17
msgid "The path to jellyfin.db" msgid "The path to jellyfin.db"
msgstr "" msgstr ""
@@ -117,90 +117,102 @@ msgstr ""
msgid "Please input album name:" msgid "Please input album name:"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Id" msgid "Id"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Date" msgid "Date"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Time" msgid "Time"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Name" msgid "Name"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Artists" msgid "Artists"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241 audio.py:330
msgid "Album" msgid "Album"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Album artists" msgid "Album artists"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Duration" msgid "Duration"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "(seconds)" msgid "(seconds)"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Original item id" msgid "Original item id"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Item id" msgid "Item id"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Play duration" msgid "Play duration"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Record content" msgid "Record content"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Client name" msgid "Client name"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Device name" msgid "Device name"
msgstr "" msgstr ""
#: audio.py:240 #: audio.py:241
msgid "Playback method" msgid "Playback method"
msgstr "" msgstr ""
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Play count" msgid "Play count"
msgstr "" msgstr ""
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Record count" msgid "Record count"
msgstr "" msgstr ""
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Year" msgid "Year"
msgstr "" msgstr ""
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Publish date" msgid "Publish date"
msgstr "" msgstr ""
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Publisher" msgid "Publisher"
msgstr "" msgstr ""
#: audio.py:330
msgid "Genres"
msgstr ""
#: audio.py:330
msgid "Track no"
msgstr ""
#: audio.py:330
msgid "Disc no"
msgstr ""
#: cache.py:23 #: cache.py:23
msgid "Unsupported version: " msgid "Unsupported version: "
msgstr "" msgstr ""
@@ -239,7 +251,7 @@ msgstr ""
msgid "Last page" msgid "Last page"
msgstr "" msgstr ""
#: utils.py:97 #: utils.py:98
#, python-format #, python-format
msgid "%i day" msgid "%i day"
msgstr "" msgstr ""

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: jellyfinStats 1.0\n" "Project-Id-Version: jellyfinStats 1.0\n"
"Report-Msgid-Bugs-To: [email protected]\n" "Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-05-16 10:47+0800\n" "POT-Creation-Date: 2024-05-23 16:35+0800\n"
"PO-Revision-Date: 2024-05-15 10:20+0800\n" "PO-Revision-Date: 2024-05-15 10:20+0800\n"
"Last-Translator: mhy <[email protected]>\n" "Last-Translator: mhy <[email protected]>\n"
"Language-Team: Chinese (simplified) <[email protected]>\n" "Language-Team: Chinese (simplified) <[email protected]>\n"
@@ -16,31 +16,31 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: __main__.py:20 #: __main__.py:11
msgid "The path to config file." msgid "The path to config file."
msgstr "配置文件位置。" msgstr "配置文件位置。"
#: __main__.py:21 #: __main__.py:12
msgid "The path to playback_reporting.db" msgid "The path to playback_reporting.db"
msgstr "playback_reporting.db 文件位置。" msgstr "playback_reporting.db 文件位置。"
#: __main__.py:22 #: __main__.py:13
msgid "The path to library.db" msgid "The path to library.db"
msgstr "library.db 文件位置。" msgstr "library.db 文件位置。"
#: __main__.py:23 #: __main__.py:14
msgid "The path to jellyfin data directory." msgid "The path to jellyfin data directory."
msgstr "Jellyfin 数据目录位置。" msgstr "Jellyfin 数据目录位置。"
#: __main__.py:24 #: __main__.py:15
msgid "The directory for output files." msgid "The directory for output files."
msgstr "输出目录位置。" msgstr "输出目录位置。"
#: __main__.py:25 #: __main__.py:16
msgid "Specify maximum items to display in one page." msgid "Specify maximum items to display in one page."
msgstr "指定一页可以显示的最大条目数。" msgstr "指定一页可以显示的最大条目数。"
#: __main__.py:26 #: __main__.py:17
msgid "The path to jellyfin.db" msgid "The path to jellyfin.db"
msgstr "jellyfin.db 文件位置。" msgstr "jellyfin.db 文件位置。"
@@ -116,90 +116,102 @@ msgstr "请输入标题:"
msgid "Please input album name:" msgid "Please input album name:"
msgstr "请输入专辑名称:" msgstr "请输入专辑名称:"
#: audio.py:240 #: audio.py:241
msgid "Id" msgid "Id"
msgstr "ID" msgstr "ID"
#: audio.py:240 #: audio.py:241
msgid "Date" msgid "Date"
msgstr "日期" msgstr "日期"
#: audio.py:240 #: audio.py:241
msgid "Time" msgid "Time"
msgstr "时间" msgstr "时间"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Name" msgid "Name"
msgstr "名称" msgstr "名称"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Artists" msgid "Artists"
msgstr "艺术家" msgstr "艺术家"
#: audio.py:240 #: audio.py:241 audio.py:330
msgid "Album" msgid "Album"
msgstr "专辑" msgstr "专辑"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Album artists" msgid "Album artists"
msgstr "专辑艺术家" msgstr "专辑艺术家"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Duration" msgid "Duration"
msgstr "时长" msgstr "时长"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "(seconds)" msgid "(seconds)"
msgstr "(秒)" msgstr "(秒)"
#: audio.py:240 #: audio.py:241
msgid "Original item id" msgid "Original item id"
msgstr "原项目ID" msgstr "原项目ID"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Item id" msgid "Item id"
msgstr "项目ID" msgstr "项目ID"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Play duration" msgid "Play duration"
msgstr "播放时长" msgstr "播放时长"
#: audio.py:240 #: audio.py:241
msgid "Record content" msgid "Record content"
msgstr "记录内容" msgstr "记录内容"
#: audio.py:240 #: audio.py:241
msgid "Client name" msgid "Client name"
msgstr "客户端名称" msgstr "客户端名称"
#: audio.py:240 #: audio.py:241
msgid "Device name" msgid "Device name"
msgstr "设备名称" msgstr "设备名称"
#: audio.py:240 #: audio.py:241
msgid "Playback method" msgid "Playback method"
msgstr "播放方式" msgstr "播放方式"
#: audio.py:240 audio.py:290 #: audio.py:241 audio.py:300 audio.py:330
msgid "Play count" msgid "Play count"
msgstr "播放次数" msgstr "播放次数"
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Record count" msgid "Record count"
msgstr "记录次数" msgstr "记录次数"
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Year" msgid "Year"
msgstr "年份" msgstr "年份"
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Publish date" msgid "Publish date"
msgstr "发布日期" msgstr "发布日期"
#: audio.py:290 #: audio.py:300 audio.py:330
msgid "Publisher" msgid "Publisher"
msgstr "发布者" msgstr "发布者"
#: audio.py:330
msgid "Genres"
msgstr "风格"
#: audio.py:330
msgid "Track no"
msgstr "轨道号"
#: audio.py:330
msgid "Disc no"
msgstr "光盘号"
#: cache.py:23 #: cache.py:23
msgid "Unsupported version: " msgid "Unsupported version: "
msgstr "不支持的版本:" msgstr "不支持的版本:"
@@ -238,7 +250,7 @@ msgstr "下一页"
msgid "Last page" msgid "Last page"
msgstr "最后一页" msgstr "最后一页"
#: utils.py:97 #: utils.py:98
#, python-format #, python-format
msgid "%i day" msgid "%i day"
msgstr "%i 天" msgstr "%i 天"