<commit_before>/*
 * Copyright (C) 2008 OpenedHand Ltd.
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: <NAME> <<EMAIL>>
 *         <NAME> (Khattak) <<EMAIL>>
 *                               <<EMAIL>>
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel.MPRIS;
using Rygel.MPRIS.MediaPlayer;
using FreeDesktop;

public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
    private string[] protocols;
    private string[] mime_types;

    private PlayerProxy actual_player;

    public string playback_state {
        owned get {
            return this.mpris_to_upnp_state (actual_player.playback_status);
        }

        set {
            debug ("Changing playback state to %s..", value);

            /* FIXME: Do something about errors below */
            switch (value) {
            case "STOPPED":
                try {
                    this.actual_player.stop ();
                } catch (Error error) {}

                break;
            case "PAUSED_PLAYBACK":
                try {
                    this.actual_player.pause ();
                } catch (Error error) {}

                break;
            case "PLAYING":
                try {
                    this.actual_player.play ();
                } catch (Error error) {}

                break;
            default:
                assert_not_reached ();
            }
        }
    }

    private string[] _allowed_playback_speeds = {"1"};
    public string[] allowed_playback_speeds {
        owned get {
            return this._allowed_playback_speeds;
        }
    }

    public string playback_speed {
        owned get {
            return this.double_to_rational (this.actual_player.rate);
        }

        set {
            this.actual_player.rate = this.rational_to_double (value);
        }
    }

    public double minimum_rate {
        get {
            return this.rational_to_double (_allowed_playback_speeds[0]);
        }
    }

    public double maximum_rate {
        get {
            int i = _allowed_playback_speeds.length;

            assert (i > 0);

            return this.rational_to_double (_allowed_playback_speeds[i-1]);
        }
    }

    public string? uri {
        owned get {
            var val = this.actual_player.metadata.lookup ("xesam:url");

            if (val != null) {
                return (string) val;
            } else {
                return null;
            }
        }

        set {
            try {
                this.actual_player.open_uri (value);
            } catch (Error error) {}
        }
    }

    public string? mime_type { owned get; set; }
    public string? metadata { owned get; set; }
    public string? content_features { owned get; set; }

    public bool can_seek { get { return true; } }

    public double volume {
        get {
            return this.actual_player.volume;
        }

        set {
            this.actual_player.volume = value;
        }
    }

    public int64 duration {
        get {
            var val = this.actual_player.metadata.lookup ("mpris:length");
            int64 dur = 0;

            if (val != null) {
                dur = (int64) val;
            }

            return dur;
        }
    }

    public int64 position {
        get {
            return this.actual_player.position;
        }
    }

    public Player (Plugin plugin) {
        this.actual_player = plugin.actual_player;
        this.mime_types = plugin.mime_types;
        this.protocols = plugin.protocols;

        actual_player.g_properties_changed.connect (this.on_properties_changed);
    }

    public bool seek (int64 time) {
        var ret = false;

        try {
            this.actual_player.seek (time);
            ret = true;
        } catch (Error error) {}

        return ret;
    }

    public string[] get_protocols () {
        return this.protocols;
    }<commit_msg>mpris: Seek is always relative<commit_after>/*
 * Copyright (C) 2008 OpenedHand Ltd.
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: <NAME> <<EMAIL>>
 *         <NAME> (Khattak) <<EMAIL>>
 *                               <<EMAIL>>
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel.MPRIS;
using Rygel.MPRIS.MediaPlayer;
using FreeDesktop;

public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
    private string[] protocols;
    private string[] mime_types;

    private PlayerProxy actual_player;

    public string playback_state {
        owned get {
            return this.mpris_to_upnp_state (actual_player.playback_status);
        }

        set {
            debug ("Changing playback state to %s..", value);

            /* FIXME: Do something about errors below */
            switch (value) {
            case "STOPPED":
                try {
                    this.actual_player.stop ();
                } catch (Error error) {}

                break;
            case "PAUSED_PLAYBACK":
                try {
                    this.actual_player.pause ();
                } catch (Error error) {}

                break;
            case "PLAYING":
                try {
                    this.actual_player.play ();
                } catch (Error error) {}

                break;
            default:
                assert_not_reached ();
            }
        }
    }

    private string[] _allowed_playback_speeds = {"1"};
    public string[] allowed_playback_speeds {
        owned get {
            return this._allowed_playback_speeds;
        }
    }

    public string playback_speed {
        owned get {
            return this.double_to_rational (this.actual_player.rate);
        }

        set {
            this.actual_player.rate = this.rational_to_double (value);
        }
    }

    public double minimum_rate {
        get {
            return this.rational_to_double (_allowed_playback_speeds[0]);
        }
    }

    public double maximum_rate {
        get {
            int i = _allowed_playback_speeds.length;

            assert (i > 0);

            return this.rational_to_double (_allowed_playback_speeds[i-1]);
        }
    }

    public string? uri {
        owned get {
            var val = this.actual_player.metadata.lookup ("xesam:url");

            if (val != null) {
                return (string) val;
            } else {
                return null;
            }
        }

        set {
            try {
                this.actual_player.open_uri (value);
            } catch (Error error) {}
        }
    }

    public string? mime_type { owned get; set; }
    public string? metadata { owned get; set; }
    public string? content_features { owned get; set; }

    public bool can_seek { get { return true; } }

    public double volume {
        get {
            return this.actual_player.volume;
        }

        set {
            this.actual_player.volume = value;
        }
    }

    public int64 duration {
        get {
            var val = this.actual_player.metadata.lookup ("mpris:length");
            int64 dur = 0;

            if (val != null) {
                dur = (int64) val;
            }

            return dur;
        }
    }

    public int64 position {
        get {
            return this.actual_player.position;
        }
    }

    public Player (Plugin plugin) {
        this.actual_player = plugin.actual_player;
        this.mime_types = plugin.mime_types;
        this.protocols = plugin.protocols;

        actual_player.g_properties_changed.connect (this.on_properties_changed);
    }

    public bool seek (int64 time) {
        var ret = false;

        try {
            this.actual_player.seek (time - this.position);
            ret = true;
        } catch (Error error) {}

        return ret;
    }

    public string[] get_protocols () {
        return this.protocols;
    }
{'fraction_non_alphanumeric': 0.08564588094460768, 'fraction_numerical': 0.007617803895962564, 'mean_word_length': 1.6537684088940225, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120527', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2427, 'n_words': 731}