Skip to content

Commit

Permalink
add offline listening history
Browse files Browse the repository at this point in the history
  • Loading branch information
purarue committed Aug 7, 2023
1 parent cd2b5b9 commit fe33cbf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This is built on top of [`karlicoss/HPI`](https://github.com/karlicoss/HPI). It
- `my.chess.export`, to track my [chess.com](https://www.chess.com)/[lichess.org](https://lichess.org/) games, using [`chess_export`](https://github.com/seanbreckenridge/chess_export)
- `my.trakt.export`, providing me a history/my ratings for Movies/TV Show (episodes) using [`traktexport`](https://github.com/seanbreckenridge/traktexport)
- `my.listenbrainz.export`, exporting my music listening history from [ListenBrainz](https://listenbrainz.org/) (open-source Last.fm) using [`listenbrainz_export`](https://github.com/seanbreckenridge/listenbrainz_export)
- `my.offline.listens`, for offline music listen history, using [offline_listens](https://github.com/seanbreckenridge/offline_listens)
- `my.mal.export`, for anime/manga history using [`malexport`](https://github.com/seanbreckenridge/malexport)
- `my.grouvee.export`, for my video game history/backlog using [`grouvee_export`](https://github.com/seanbreckenridge/grouvee_export)
- `my.runelite.screenshots`, parses data from the [automatic runelite screenshots](https://github.com/runelite/runelite/wiki/Screenshot)
Expand Down
1 change: 1 addition & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ module_dependencies() {
hpi_module my.mail.all || return $?
hpi_module my.piazza.scraper || return $?
hpi_module my.grouvee.export || return $?
hpi_module my.offline.listens || return $?
hpi_module my.mal.export || return $?
hpi_module my.listenbrainz.export || return $?
hpi_module my.skype.gdpr || return $?
Expand Down
45 changes: 45 additions & 0 deletions my/offline/listens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Parses scrobbles from https://github.com/seanbreckenridge/offline_listens
"""

REQUIRES = ["git+https://github.com/seanbreckenridge/offline_listens"]

# see https://github.com/seanbreckenridge/dotfiles/blob/master/.config/my/my/config/__init__.py for an example
from my.config import offline as user_config # type: ignore[attr-defined]


from pathlib import Path
from typing import Iterator, Sequence

from offline_listens.listens import Listen
from offline_listens.parse import iter_dir, parse_file

from my.core import get_files, Stats, Paths, dataclass
from my.utils.input_source import InputSource


@dataclass
class config(user_config.listens):
# path[s]/glob to the exported data
export_path: Paths


def inputs() -> Sequence[Path]:
return get_files(config.export_path)


Results = Iterator[Listen]


def history(from_paths: InputSource = inputs) -> Results:
for f in from_paths():
if f.is_dir():
yield from iter_dir(f)
else:
yield from parse_file(f)


def stats() -> Stats:
from my.core import stat

return {**stat(history)}
4 changes: 4 additions & 0 deletions tests/my/my/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ class minecraft:
class advancements:
export_path: Paths = ""

class offline:
class listens:
export_path: Paths = ""


class time:
class tz:
Expand Down

0 comments on commit fe33cbf

Please sign in to comment.