<commit_before>import logging

import gst

from mopidy.models import Track, Playlist
from mopidy.backends import (BaseBackend,
                             BasePlaybackController,
                             BaseCurrentPlaylistController)

logger = logging.getLogger(u'backends.gstreamer')

class GStreamerBackend(BaseBackend):
    def __init__(self, *args, **kwargs):
        super(GStreamerBackend, self).__init__(*args, **kwargs)

        self.playback = GStreamerPlaybackController(self)
        self.current_playlist = GStreamerCurrentPlaylistController(self)

class GStreamerCurrentPlaylistController(BaseCurrentPlaylistController):
    def add(self, uri, at_position=None):
        tracks = self.playlist.tracks

        if at_position is None:
            tracks.append(Track(uri))
        else:
            tracks.insert(at_position, Track(uri))

        self.playlist = Playlist(tracks=tracks)

class GStreamerPlaybackController(BasePlaybackController):
    STATE_MAPPING = {
        gst.STATE_PAUSED: BasePlaybackController.PAUSED,
        gst.STATE_PLAYING: BasePlaybackController.PLAYING,
        gst.STATE_NULL: BasePlaybackController.STOPPED,
    }

    def __init__(self, backend):
        super(GStreamerPlaybackController, self).__init__(backend)

        bin = gst.element_factory_make("playbin", "player")
        sink = gst.element_factory_make("fakesink", "fakesink")

        bin.set_property("video-sink", sink)

        self.bin = bin

    @property
    def state(self):
        gststate = type(gst.STATE_NULL)

        for state in self.bin.get_state():
            if type(state) == gststate and state in self.STATE_MAPPING:
                return self.STATE_MAPPING[state]

        return self.STOPPED
<commit_msg>Set id on tracks when adding them<commit_after>import logging

import gst

from mopidy.models import Track, Playlist
from mopidy.backends import (BaseBackend,
                             BasePlaybackController,
                             BaseCurrentPlaylistController)

logger = logging.getLogger(u'backends.gstreamer')

class GStreamerBackend(BaseBackend):
    def __init__(self, *args, **kwargs):
        super(GStreamerBackend, self).__init__(*args, **kwargs)

        self.playback = GStreamerPlaybackController(self)
        self.current_playlist = GStreamerCurrentPlaylistController(self)

class GStreamerCurrentPlaylistController(BaseCurrentPlaylistController):
    next_id = 0

    def add(self, uri, at_position=None):
        tracks = self.playlist.tracks

        track = Track(uri=uri, id=self.next_id)

        if at_position is None:
            tracks.append(track)
        else:
            tracks.insert(at_position, track)

        self.next_id += 1
        self.playlist = Playlist(tracks=tracks)

class GStreamerPlaybackController(BasePlaybackController):
    STATE_MAPPING = {
        gst.STATE_PAUSED: BasePlaybackController.PAUSED,
        gst.STATE_PLAYING: BasePlaybackController.PLAYING,
        gst.STATE_NULL: BasePlaybackController.STOPPED,
    }

    def __init__(self, backend):
        super(GStreamerPlaybackController, self).__init__(backend)

        bin = gst.element_factory_make("playbin", "player")
        sink = gst.element_factory_make("fakesink", "fakesink")

        bin.set_property("video-sink", sink)

        self.bin = bin

    @property
    def state(self):
        gststate = type(gst.STATE_NULL)

        for state in self.bin.get_state():
            if type(state) == gststate and state in self.STATE_MAPPING:
                return self.STATE_MAPPING[state]

        return self.STOPPED

{'fraction_non_alphanumeric': 0.08779264214046822, 'fraction_numerical': 0.0005574136008918618, 'mean_word_length': 2.9570011025358323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2201697', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1044, 'n_words': 197}