Ejemplo n.º 1
0
    def media_selection_required(self, files):
        if Settings.get_bool("slave"):
            data, = SlaveClientController.request_master(
                "get_history_for_url", 5, self.torrent.uri)
            if data:
                history = [
                    History(x['id'], x['imdb_id'], x['type'], x['title'],
                            x['image'], x['watched_at'], x['season'],
                            x['episode'], x['url'], x['media_file'],
                            x['played_for'], x['length'])
                    for x in json.loads(data)
                ]
            else:
                history = []
        else:
            history = Database().get_history_for_url(self.torrent.uri)

        for file in files:
            seen = [x for x in history if x.media_file == file.path]
            file.seen = len(seen) > 0
            if file.seen:
                seen = seen[-1]
                file.played_for = seen.played_for
                file.play_length = seen.length

        APIController().ui_request("SelectMediaFile", self.set_media_file,
                                   60 * 30, files)
Ejemplo n.º 2
0
 def start_url(self, title, url):
     self.stop_play()
     VLCPlayer().play(url, 0)
     if Settings.get_bool("slave"):
         self.history_id, = SlaveClientController.request_master(
             "add_watched_url", 5, url, current_time())
     else:
         self.history_id = Database().add_watched_url(url, current_time())
     self.media_data.start_update()
     self.media_data.type = "Url"
     self.media_data.title = title
     self.media_data.stop_update()
     TVManager().switch_input_to_pi()
Ejemplo n.º 3
0
 def _start_playing_torrent(self):
     if Settings.get_bool("slave"):
         self.history_id, = SlaveClientController.request_master(
             "add_watched_torrent", 5, self.media_data.type,
             self.media_data.title, self.media_data.id, self.torrent.uri,
             self.torrent.media_file.path, self.media_data.image,
             self.media_data.season, self.media_data.episode,
             current_time())
     else:
         self.history_id = Database().add_watched_torrent(
             self.media_data.type, self.media_data.title,
             self.media_data.id, self.torrent.uri,
             self.torrent.media_file.path, self.media_data.image,
             self.media_data.season, self.media_data.episode,
             current_time())
     VLCPlayer().play("http://localhost:50009/torrent",
                      self.media_data.start_from)
Ejemplo n.º 4
0
    def start_file(self, url, time):
        actual_url = url
        if Settings.get_bool("slave"):
            actual_url = "http://" + Settings.get_string(
                "master_ip") + ":50015/file/" + urllib.parse.quote(url)

        self.stop_play()
        VLCPlayer().play(actual_url, time)
        if Settings.get_bool("slave"):
            self.history_id, = SlaveClientController.request_master(
                "add_watched_file", 5, url, current_time())
        else:
            self.history_id = Database().add_watched_file(url, current_time())
        self.media_data.start_update()
        self.media_data.type = "File"
        self.media_data.title = os.path.basename(url)
        self.media_data.url = url
        self.media_data.image = None
        self.media_data.stop_update()
        TVManager().switch_input_to_pi()
Ejemplo n.º 5
0
    def try_find_in_dir(self, media_data):
        season, epi = try_parse_season_episode(media_data.url)
        if season == 0 or epi == 0:
            Logger().write(LogVerbosity.Debug,
                           "No next episode of file, season/epi not parsed")
            return

        dir_name = os.path.dirname(media_data.url)
        if Settings.get_bool("slave"):
            data, = SlaveClientController.request_master(
                "get_directory", 5, dir_name)
            if not data:
                return
            data = json.loads(data)
            file_list = data["file_names"]
        else:
            file_list = FileStructure(dir_name).file_names

        for potential in file_list:
            if not is_media_file(potential):
                continue

            s, e = try_parse_season_episode(potential)
            if s == season and e == epi + 1:
                Logger().write(LogVerbosity.Info,
                               "Found next episode: " + potential)
                self.next_season = s
                self.next_episode = epi + 1
                self.next_type = "File"
                self.next_title = potential
                self.next_path = dir_name + "/" + potential
                return
        Logger().write(
            LogVerbosity.Debug,
            "No next episode of file, no matching next season/epi found in file list"
        )
        return