<commit_before>/**
 * Copyright 2015 Longtail Ad Solutions Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 **/

(function () {

    angular
        .module('jwShowcase.video')
        .controller('VideoController', VideoController);

    /**
     * @ngdoc controller
     * @name jwShowcase.video.controller:VideoController
     *
     * @requires $scope
     * @requires $state
     * @requires $ionicHistory
     * @requires $ionicScrollDelegate
     * @requires jwShowcase.core.apiConsumer
     * @requires jwShowcase.core.dataStore
     * @requires jwShowcase.core.watchProgress
     * @requires jwShowcase.core.watchlist
     * @requires jwShowcase.core.userSettings
     * @requires jwShowcase.core.utils
     * @requires jwShowcase.core.share
     * @requires jwShowcase.core.player
     */
    VideoController.$inject = ['$scope', '$state', '$ionicHistory', '$ionicScrollDelegate',
        'apiConsumer', 'dataStore', 'watchProgress', 'watchlist', 'userSettings', 'utils', 'share', 'player', 'feed', 'item'];
    function VideoController ($scope, $state, $ionicHistory, $ionicScrollDelegate, apiConsumer, dataStore,
                              watchProgress, watchlist, userSettings, utils, share, player, feed, item) {

        var vm                   = this,
            lastPos              = 0,
            resumed              = false,
            started              = false,
            requestQualityChange = false,
            playerPlaylist       = [],
            playerLevels,
            initialLevel,
            watchProgressItem;

        vm.item                = item;
        vm.feed                = feed;
        vm.recommendationsFeed = null;
        vm.duration            = 0;
        vm.inWatchList         = false;
        vm.title               = '';

        vm.onComplete     = onComplete;
        vm.onFirstFrame   = onFirstFrame;
        vm.onTime         = onTime;
        vm.onPlaylistItem = onPlaylistItem;
        vm.onLevels       = onLevels;

        vm.cardClickHandler      = cardClickHandler;
        vm.shareClickHandler     = shareClickHandler;
        vm.watchlistClickHandler = watchlistClickHandler;

        activate();

        ////////////////////////

        /**
         * Initialize the controller.
         */
        function activate () {

            playerPlaylist = generatePlaylist(feed, item);

            vm.playerSettings = {
                width:          '100%',
                height:         '100%',
                aspectratio:    '16:9',
                ph:             4,
                autostart:      $state.params.autoStart,
                playlist:       playerPlaylist,
                related:        false,
                sharing:        false,
                visualplaylist: false
            };

            $scope.$watch(function () {
                return userSettings.settings.conserveBandwidth;
            }, conserveBandwidthChangeHandler);

            update();
        }

        /**
         * Update controller
         */
        function update () {

            var itemIndex = feed.playlist.findIndex(byMediaId(vm.item.mediaid));

            vm.feed.playlist = feed.playlist
                .slice(itemIndex)
                .concat(feed.playlist.slice(0, itemIndex));

            watchProgressItem = watchProgress.getItem(vm.item);
            vm.duration       = utils.getVideoDurationByItem(vm.item);
            vm.inWatchList    = watchlist.hasItem(vm.item);
            vm.title          = vm.item.title;

            if (vm.title.length > 100) {
                vm.title = vm.title.substr(0, 100) + '...';
            }
<commit_msg>Watch for watchlist changes in video controller<commit_after>/**
 * Copyright 2015 Longtail Ad Solutions Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 **/

(function () {

    angular
        .module('jwShowcase.video')
        .controller('VideoController', VideoController);

    /**
     * @ngdoc controller
     * @name jwShowcase.video.controller:VideoController
     *
     * @requires $scope
     * @requires $state
     * @requires $ionicHistory
     * @requires $ionicScrollDelegate
     * @requires jwShowcase.core.apiConsumer
     * @requires jwShowcase.core.dataStore
     * @requires jwShowcase.core.watchProgress
     * @requires jwShowcase.core.watchlist
     * @requires jwShowcase.core.userSettings
     * @requires jwShowcase.core.utils
     * @requires jwShowcase.core.share
     * @requires jwShowcase.core.player
     */
    VideoController.$inject = ['$scope', '$state', '$ionicHistory', '$ionicScrollDelegate',
        'apiConsumer', 'dataStore', 'watchProgress', 'watchlist', 'userSettings', 'utils', 'share', 'player', 'feed', 'item'];
    function VideoController ($scope, $state, $ionicHistory, $ionicScrollDelegate, apiConsumer, dataStore,
                              watchProgress, watchlist, userSettings, utils, share, player, feed, item) {

        var vm                   = this,
            lastPos              = 0,
            resumed              = false,
            started              = false,
            requestQualityChange = false,
            playerPlaylist       = [],
            playerLevels,
            initialLevel,
            watchProgressItem;

        vm.item                = item;
        vm.feed                = feed;
        vm.recommendationsFeed = null;
        vm.duration            = 0;
        vm.inWatchList         = false;
        vm.title               = '';

        vm.onComplete     = onComplete;
        vm.onFirstFrame   = onFirstFrame;
        vm.onTime         = onTime;
        vm.onPlaylistItem = onPlaylistItem;
        vm.onLevels       = onLevels;

        vm.cardClickHandler      = cardClickHandler;
        vm.shareClickHandler     = shareClickHandler;
        vm.watchlistClickHandler = watchlistClickHandler;

        activate();

        ////////////////////////

        /**
         * Initialize the controller.
         */
        function activate () {

            playerPlaylist = generatePlaylist(feed, item);

            vm.playerSettings = {
                width:          '100%',
                height:         '100%',
                aspectratio:    '16:9',
                ph:             4,
                autostart:      $state.params.autoStart,
                playlist:       playerPlaylist,
                related:        false,
                sharing:        false,
                visualplaylist: false
            };

            $scope.$watch(function () {
                return userSettings.settings.conserveBandwidth;
            }, conserveBandwidthChangeHandler);

            $scope.$watch(function () {
                return watchlist.hasItem(vm.item);
            }, function (val, oldVal) {
                if (val !== oldVal) {
                    vm.inWatchList = val;
                }
            });

            update();
        }

        /**
         * Update controller
         */
        function update () {

            var itemIndex = feed.playlist.findIndex(byMediaId(vm.item.mediaid));

            vm.feed.playlist = feed.playlist
                .slice(itemIndex)
                .concat(feed.playlist.slice(0, itemIndex));

            watchProgressItem = watchProgress.getItem(vm.item);
            vm.duration       = utils.getVideoDurationByItem(vm.item);
            vm.title          = vm.item.title;

            if (vm.title.length > 100) {
                vm.title = vm.title.substr(0, 100) + '...';
            }

{'fraction_non_alphanumeric': 0.10292397660818714, 'fraction_numerical': 0.006549707602339181, 'mean_word_length': 1.6547656007451101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1873053', 'n_tokens_mistral': 2292, 'n_tokens_neox': 2144, 'n_words': 515}