f1u77y / web-media-controller

Allows controlling media player on different sites with Media Player widget on your desktop
The Unlicense
36 stars 10 forks source link

add bandcamp #34

Open ghost opened 4 years ago

ghost commented 4 years ago

I started implementing it based on the soundcloud connector, but I don't know how to write the observer

import BaseConnector from 'content/base-connector';
import Utils from 'content/utils';

new class extends BaseConnector {
    constructor() {
        super();
        this.name = 'BandCamp';
        this.prefix = '/com/bandcamp';

        this.artistSelector = '#band-name-location .title';
        this.titleSelector = '.title-section .title';

        this.currentTimeSelector = '.time .secondaryTexgt .time_elapsed';
        this.lengthSelector = '.time .secondaryTexgt .time_total';
        this.playButtonSelector = '.playbutton';
        this.prevButtonSelector = '.prev_cell .prevbutton';
        this.nextButtonSelector = '.next_cell .nextbutton';
        this.artSelector = '#tralbumArt .popupImage';

        //Utils.query('.playControls .playControls__inner').then((elem) => this.observe(elem));
    }

    get playbackStatus() {
        return Utils.query(this.playButtonSelector).then((elem) => (elem.classList.contains('playing') ? 'playing' : 'paused'));
    }

    getArtistTrack() {
        const artistTrack = {
            artist: document.querySelector(this.artistSelector).textContent.trim(),
            track: document.querySelector(this.titleSelector).textContent.trim(),
        };
        const match = /(.+)\s[-–—:]\s(.+)/.exec(artistTrack.track);

        if (match && ! /.*#\d+.*/.test(match[1])) {
            return { artist: match[1], track: match[2] };
        }

        return artistTrack;
    }

    get artist() {
        return this.getArtistTrack().artist;
    }

    get title() {
        return this.getArtistTrack().track;
    }

    get artUrl() {
        return super.artUrl.then((url)
    }
}();
f1u77y commented 4 years ago

Hello!

First of all, I've slightly changed Connector API, so now you just need to declare playerSelector like this.

but I don't know how to write the observer

Any element that includes all other elements, changes of which matter, will work (e.g. body will always work), but is's better to choose the deepest one of such elements because it leads to better performance.

There's also already implemented connector for different extension. You might want to look here for implementation details.

Feel free to ping me if you need more help.

ghost commented 4 years ago

I can't make wmc-mpris work with my setup. this is my ~/.mozilla/native-messaging-hosts/me.f1u77y.web_media_controller.firefox.json

{
    "name": "treeshateorcs.web_media_controller",
    "description": "Allows controlling VK player via MPRIS",
    "path": "/usr/bin/web-media-controller",
    "type": "stdio",
    "allowed_extensions": [
        "web-media-controller@treeshateorcs"
    ]
}

and firefox_manifest.json

{
    "applications": {
        "gecko": {
            "id": "web-media-controller@treeshateorcs",
            "strict_min_version": "48.0"
        }
    },
    "options_ui.browser_style": true
}

however on addons.mozilla.org it still lists my extension as web-media-controller@bobross.com

f1u77y commented 4 years ago

If your extension is listed as web-media-controller@bobross.com, you should use the same ID in native messaging host manifest. If you want to change it, you could submit a new add-on with different ID.