~hristoast/mousikofidi

d4ec0804c26a164123c17278d961796acc9abdad — Hristos N. Triantafillou 8 months ago e052850 0.18
A special logo easter egg that can be disabled

Ogenfald has graciously created several variations on the MousikóFídi
logo that now display on various days/months of the year.

It defaults to being on if it isn't configured, but can be disabled
altogether by putting `holidays: false` in your config.yml.
M mousikofidi/mousikofidi.py => mousikofidi/mousikofidi.py +76 -2
@@ 40,6 40,14 @@ app = Flask(__name__)
debug = os.getenv("FLASK_ENV") == "development"

MAX_COOKIE_SIZE = 4093

LOGOS = {
    "*": "fidi.png",
    "month:10": "fidi-oct.png",
    "month:12": "fidi-dec.png",
    "04-20": "fidi-420.png",
}

THEMES = {
    "dark": "/css/water/dark.standalone",
    "light": "/css/water/light.standalone",


@@ 234,6 242,8 @@ def config_to_string(config_file: str) -> str:


def request_context(config_data: dict) -> dict:
    favicon = select_logo(config_data, "favicon_path")
    logo = select_logo(config_data, "logo_path")
    m = config_data["config"]["music_dirs"]
    music_dirs = paths_list(m)
    playlists = list_playlists(config_data["config"]["playlist"]["dir"])


@@ 260,9 270,9 @@ def request_context(config_data: dict) -> dict:

    return {
        "debug": debug,
        "favicon_path": config_data["config"]["favicon_path"],
        "favicon_path": favicon,
        "icons": icons,
        "logo_path": config_data["config"]["logo_path"],
        "logo_path": logo,
        "music_dirs": music_dirs,
        "playlist_dir": config_data["config"]["playlist"]["dir"],
        "playlist_save": config_data["config"]["playlist"]["save"],


@@ 317,6 327,17 @@ def init(

    # TODO: A more DRY way to handle checking for configs
    try:
        if c["config"]["holidays"].lower() == "true":
            c["config"]["holidays"] = True
        else:
            c["config"]["holidays"] = False
    except KeyError:
        wrn(
            "No 'holidays' value was found in the configuration file!  Defaulting to on..."
        )
        c["config"]["holidays"] = True

    try:
        if c["config"]["icons"].lower() == "true":
            c["config"]["icons"] = True
        else:


@@ 891,6 912,59 @@ def paths_list(music_dirs: list) -> list:
    return dl


def select_logo(config: dict, item: str, fakenow=None) -> str:
    if config["config"]["holidays"]:
        logo = config["config"]["logo_path"]

        from datetime import datetime

        if fakenow:
            now = fakenow
        else:
            now = datetime.now()

        for logo_date in LOGOS.keys():
            if "-" in logo_date:
                sdate = logo_date.split("-")

                if len(sdate) == 2:
                    month, date = sdate
                    today_month, today_date = now.strftime("%m-%d").split("-")

                    if month == today_month and date == today_date:
                        dbg(
                            "Activating holiday {item} for '{date}'!".format(
                                item=item, date=logo_date
                            )
                        )
                        logo = "/" + LOGOS[logo_date]

            elif ":" in logo_date:
                date_type, date = logo_date.split(":")

                if date_type == "day":
                    if date == now.strftime("%d"):
                        logo = "/" + LOGOS[logo_date]

                elif date_type == "month":
                    if date == now.strftime("%m"):
                        logo = "/" + LOGOS[logo_date]

            elif logo_date == "*":
                logo = "/" + LOGOS[logo_date]

        if debug:
            logo = "/static" + logo

        return logo

    else:
        # No holidays!
        if debug:
            return "/static" + config["config"][item]
        return config["config"][item]


def title_slug(title: str, slug_limit=20) -> str:
    return "".join(thing for thing in title if thing.isalnum()).lower()[:slug_limit]


A mousikofidi/static/fidi-420.png => mousikofidi/static/fidi-420.png +0 -0

A mousikofidi/static/fidi-dec.png => mousikofidi/static/fidi-dec.png +0 -0

A mousikofidi/static/fidi-oct.png => mousikofidi/static/fidi-oct.png +0 -0

M mousikofidi/templates/about.html => mousikofidi/templates/about.html +6 -1
@@ 9,7 9,12 @@
    You are using MousikóFídi: a web application designed for streaming self-hosted audio and video, via a web browser.  It is designed to have as few dependencies as possible, and to be easier to set up than other software that serves a similar purpose.
  </p>

  <h5 class="center">How To Get Help With MousikóFídi</h5>
  <div class="center">
    <img src="{{ logo_path }}" title="The MousikóFídi logo, by Ogenfald.">
  </div>

  <div id="get-help"></div>
  <h5 class="center"><a href="#get-help">How To Get Help With MousikóFídi</a></h5>

  <p>
    In the links above, you can find: a user's manual, a configuration guide, as well as a full setup document.

M mousikofidi/templates/base.html => mousikofidi/templates/base.html +3 -4
@@ 29,8 29,6 @@
        <link rel="stylesheet" href="/static/css/fidi-nes.css">
      {% endif %}

      <link rel="icon" href="/static{{ favicon_path }}">

    {% else %}
      <link rel="stylesheet" href="/css/normalize.min.css">



@@ 53,9 51,10 @@
        <link rel="stylesheet" href="/static/css/fidi-nes.min.css">
      {% endif %}

      <link rel="icon" href="{{ favicon_path }}">
    {% endif %}

    <link rel="icon" href="{{ favicon_path }}">

  </head>
  <body>
    {% if top_link %}


@@ 79,7 78,7 @@
        {% endif %}
        <li id="logo">
          <a id="logo" href="{% if video_player or video_list %}#videoplayer{% elif audio_player or item_list %}#audio-time-link{% else %}/{% endif %}">
            <img alt="Fidi Logo and {% if video_player or video_list %}video player{% elif audio_player %}player{% else %}home{% endif %} link" src="{% if debug and logo_path == '/fidi.png' %}/static{% endif %}{{ logo_path }}" title="The MousikóFídi logo, and a link to the {% if video_player or video_list %}video player{% elif audio_player %}player{% else %}main index page{% endif %}.">
            <img alt="Fidi Logo and {% if video_player or video_list %}video player{% elif audio_player %}player{% else %}home{% endif %} link" src="{{ logo_path }}" title="The MousikóFídi logo, and a link to the {% if video_player or video_list %}video player{% elif audio_player %}player{% else %}main index page{% endif %}.">
          </a>
        </li>
      </ul>

M mousikofidi/templates/index.html => mousikofidi/templates/index.html +1 -1
@@ 9,7 9,7 @@
  {% endif %}

  <div class="center">
    <img src="{% if debug %}/static{% endif %}/fidi.png" title="The MousikóFídi logo, by Ogenfald.">
    <img src="{{ logo_path }}" title="The MousikóFídi logo, by Ogenfald.">
  </div>

{% endblock %}

M test_mousikofidi.py => test_mousikofidi.py +86 -2
@@ 20,6 20,7 @@ import sys
import tempfile
import yaml

from datetime import datetime
from flask import session
from mousikofidi import (
    THEMES,


@@ 43,6 44,7 @@ from mousikofidi import (
    paths_list,
    quote,
    request_context,
    select_logo,
    title_slug,
)



@@ 597,6 599,78 @@ def test_request_context():
        }


def test_select_logo_no_holiday():
    c = {
        "config": {
            "favicon_path": "/fidi.png",
            "logo_path": "/fidi.png",
            "holidays": False,
        }
    }
    favicon = select_logo(c, "favicon_path")
    logo = select_logo(c, "logo_path")

    assert favicon == "/fidi.png"
    assert logo == "/fidi.png"


def test_select_logo_apr_holiday():
    c = {
        "config": {
            "favicon_path": "/fidi.png",
            "logo_path": "/fidi.png",
            "holidays": True,
        }
    }

    fake_oct_str = "2019-04-20 15:04:00 -0500"
    fake_oct = datetime.strptime(fake_oct_str, "%Y-%m-%d %H:%M:%S %z")

    favicon = select_logo(c, "favicon_path", fakenow=fake_oct)
    logo = select_logo(c, "logo_path", fakenow=fake_oct)

    assert favicon == "/fidi-420.png"
    assert logo == "/fidi-420.png"


def test_select_logo_oct_holiday():
    c = {
        "config": {
            "favicon_path": "/fidi.png",
            "logo_path": "/fidi.png",
            "holidays": True,
        }
    }

    fake_oct_str = "2019-10-31 15:04:00 -0500"
    fake_oct = datetime.strptime(fake_oct_str, "%Y-%m-%d %H:%M:%S %z")

    favicon = select_logo(c, "favicon_path", fakenow=fake_oct)
    logo = select_logo(c, "logo_path", fakenow=fake_oct)

    assert favicon == "/fidi-oct.png"
    assert logo == "/fidi-oct.png"


def test_select_logo_dec_holiday():
    c = {
        "config": {
            "favicon_path": "/fidi.png",
            "logo_path": "/fidi.png",
            "holidays": True,
        }
    }

    fake_oct_str = "2019-12-15 15:04:00 -0500"
    fake_oct = datetime.strptime(fake_oct_str, "%Y-%m-%d %H:%M:%S %z")

    favicon = select_logo(c, "favicon_path", fakenow=fake_oct)
    logo = select_logo(c, "logo_path", fakenow=fake_oct)

    assert favicon == "/fidi-dec.png"
    assert logo == "/fidi-dec.png"


def test_handle_playlist_cmd_add():
    with app.test_request_context("/"):
        example_dir = os.path.join(THIS_DIR, "example")


@@ 820,6 894,7 @@ def test_init():
    assert c == {
        "config": {
            "favicon_path": "/fidi.png",
            "holidays": True,
            "icons": False,
            "logo_path": "/fidi.png",
            "music_dirs": [


@@ 1732,7 1807,6 @@ def test_dir_detail_found(client):
    site_name = "COOL TEST SITE"
    url = "/browse" + example_dir_unescaped

    app.fidiConfig["config"]["favicon_path"] = "/cool-favicon.png"
    app.fidiConfig["config"]["music_dirs"] = dir_list
    app.fidiConfig["config"]["site_name"] = site_name
    app.fidiConfig["config"]["theme"] = "dark"


@@ 1743,6 1817,9 @@ def test_dir_detail_found(client):
    # Reset the config
    app.fidiConfig = app._fidiConfig.copy()

    for line in rv.data.decode().split("\n"):
        print(line)

    assert rv.status == "200 OK"
    assert bytes(example_dir_unescaped, "utf8") in rv.data
    assert bytes(quote(example_dir_unescaped), "utf8") in rv.data


@@ 1776,10 1853,17 @@ def test_dir_detail_found(client):
        )
        in rv.data
    )

    assert (
        bytes('<link rel="icon" href="{}">'.format("/cool-favicon.png"), "utf8")
        bytes('<link rel="icon" href="{}">'.format("/fidi.png"), "utf8") in rv.data
        or bytes('<link rel="icon" href="{}">'.format("/fidi-oct.png"), "utf8")
        in rv.data
        or bytes('<link rel="icon" href="{}">'.format("/fidi-dec.png"), "utf8")
        in rv.data
        or bytes('<link rel="icon" href="{}">'.format("/fidi-420.png"), "utf8")
        in rv.data
    )

    assert (
        b'<link rel="stylesheet" href="/css/water/dark.standalone.min.css">' in rv.data
    )