def main(self):
    #--extraintf=rc --rc-host=127.0.0.1:4222 --rc-quiet
    try:
      vlc = VLCRemote(self.vlc_ip, self.vlc_port)
    except:
      self.log.debug('Could not find VLC running at ' + str(self.vlc_ip) + ':'+ str(self.vlc_port))
      return
      
    vlcStatus = vlc.get_status()
    if vlcStatus:
      video = self.get_TV(vlc)
      self.log.debug(video)
      if video is None:
        video = self.get_Movie(vlc)
        self.log.debug(video)

      if (video["percentage"] >= 90
          and not self.scrobbled):
              self.log.info("Scrobbling to Trakt")
              
              try:
                  self.trakt_client.update_media_status(video["title"],
                                                        video["year"],
                                                        video["duration"],
                                                        video["percentage"],
                                                        VERSION,
                                                        VLC_VERSION,
                                                        VLC_DATE,
                                                        tv=video["tv"],
                                                        scrobble=True,
                                                        season=video["season"],
                                                        episode=video["episode"])
                  self.scrobbled = True
              except TraktClient.TraktError, (e):
                  self.log.error("An error occurred while trying to scrobble: " + e.msg)
                  if ("scrobbled" in e.msg and "already" in e.msg):
                      self.log.info("Seems we've already scrobbled this episode recently, aborting scrobble attempt.")
                      self.scrobbled = True
              
      elif (video["percentage"] < 90
            and not self.scrobbled
            and self.timer >= 900):
          self.log.info("Watching on Trakt")
          self.timer = 0
      
          try:
              self.trakt_client.update_media_status(video["title"],
                                                    video["year"],
                                                    video["duration"],
                                                    video["percentage"],
                                                    VERSION,
                                                    VLC_VERSION,
                                                    VLC_DATE,
                                                    tv=video["tv"],
                                                    season=video["season"],
                                                    episode=video["episode"])
              
          except TraktClient.TraktError, (e):
              self.timer = 870
              self.log.error("An error occurred while trying to mark watching: " + e.msg)
Beispiel #2
0
def main():
    log = logging.getLogger()
    logging.basicConfig(level=logging.DEBUG)

    if 0:
        groups = multenterbox(msg='Enter groups you would like to file to',
                                title='Enter Groups', fields=(1,2,3,4,5),
                                values=('yes','no','maybe','other'))
        groups = filter(None,groups)
    else:
        groups=('yes','no','maybe','other')

    vlc = VLCRemote('localhost', 4222)
    groups_dict = {}

    while 1:
        menu_selection = buttonbox(title='Menu',choices=(
                                    'Next','Set Group','Jump','Quit'))
        if menu_selection == 'Next':
            vlc.next()
        elif menu_selection == 'Set Group':
            choice = buttonbox(msg='Assign a group', title='Assign a group',
                                choices=groups)
            fn = vlc.get_filename()
            groups_dict[fn] = choice
        elif menu_selection == 'Jump':
            vlc.skip()
        else:
            break

    reorg = {}
    for fname in groups_dict:
        l = reorg.get(groups_dict[fname],[])
        l.append(fname)
        reorg[groups_dict[fname]] = l

    str = ''
    for grp in reorg:
        str += '--%s\n'%grp
        for fname in reorg[grp]:
            str += '%s\n'%fname
    print str
    def main(self):
        try:
            vlc = VLCRemote(self.vlc_ip, self.vlc_port)
            self.vlc_connected = True
        except:
            if self.vlc_connected:
                self.log.info('Could not find VLC running at ' +
                              str(self.vlc_ip) + ':' + str(self.vlc_port))
                self.log.debug('Make sure your VLC player is running with ' +
                               '--extraintf=rc --rc-host=' +
                               str(self.vlc_ip) + ':' + str(self.vlc_port) +
                               ' --rc-quiet', exc_info=sys.exc_info())
                self.vlc_connected = False

                # If we were watching a video but we didn't finish it, we
                # have to cancel the watching status
                if self.cache["watching"] > -1 and not self.cache["scrobbled"]:
                    self.trakt_client.cancelWatching(
                        self.cache["video"]["imdbid"],
                        self.get_episode(self.cache["video"]))

                # If there is something in the cache, we can purge the watching
                # and scrobbled information, so if the video is opened again we
                # will consider it's a new watch
                if self.cache['vlc_file_name'] is not None:
                    self.resetCacheView()

            return

        vlcStatus = vlc.is_playing()
        if not vlcStatus:
            vlc.close()
            return

        currentFileLength = vlc.get_length()
        if not int(currentFileLength) > 0:
            self.log.debug("main::File length is 0, can't do anything")
            vlc.close()
            return

        if self.USE_FILENAME:
            currentFileName = vlc.get_filename()
        else:
            currentFileName = vlc.get_title()
        self.vlcTime = int(vlc.get_time())

        # Parse the filename to verify if it comes from a stream
        parsed = urlparse(currentFileName)
        if parsed.netloc:
            # Set the filename using only the basename of the parsed path
            currentFileName = os.path.basename(parsed.path)

            # And use urllib's unquote to bring back special chars
            currentFileName = unquote(currentFileName)
        elif self.USE_FILENAME:
            # Even if it's not from a stream, if it's a filename we're using
            # we need to keep only the basename of the parsed path
            currentFileName = os.path.basename(currentFileName)

        if (currentFileName == self.cache["vlc_file_name"]
                and currentFileLength == self.cache['vlc_file_length']):
            if (self.cache["series_info"] is None
                    and self.cache["movie_info"] is None):
                video = None
            elif self.cache["series_info"] is not None:
                video = self.get_TV(vlc, self.cache["series_info"])
            else:
                video = self.get_Movie(vlc, self.cache["movie_info"])
        else:
            self.log.debug("main::New file: %s (%s)"
                           % (currentFileName, currentFileLength))

            # If we were watching a video but we didn't finish it, we
            # have to cancel the watching status
            if self.cache["watching"] > -1 and not self.cache["scrobbled"]:
                self.trakt_client.cancelWatching(
                    self.cache["video"]["imdbid"],
                    self.get_episode(self.cache["video"]))

            self.resetCache(currentFileName, currentFileLength)
            self.cache['started_watching'] = (time.time(), self.vlcTime)

            video = self.get_TV(vlc)
            if video is None:
                video = self.get_Movie(vlc)

        if video is None:
            self.log.info(
                "No tv show nor movie found for the current playing video")
            vlc.close()
            return

        # We cache the updated video information
        self.cache["video"] = video

        logtitle = video["title"]
        if video["tv"]:
            logtitle += (" - %01dx%02d"
                         % (int(video["season"]), int(video["episode"])))

            # If we changed episode, we have to reset the view status
            if (self.cache['watching'] > -1
                    and self.cache['series_current_ep'] != video['episode']):
                self.resetCacheView(video['episode'])
                self.cache['started_watching'] = (
                    time.time(),
                    self.vlcTime % video['duration'])

        self.log.info(logtitle + " state : " + str(video["percentage"]) + "%")
        self.log.debug("main::Video: %s" % str(video))
        self.log.debug("main::This video is scrobbled : " +
                       str(self.cache["scrobbled"]))

        if (((video['tv'] and self.DO_SCROBBLE_TV)
                or (not video['tv'] and self.DO_SCROBBLE_MOVIE))
                and video["percentage"] >= self.SCROBBLE_PERCENT
                and not self.cache["scrobbled"]
                and self.cache['started_watching'] is not None
                and ((time.time() - self.cache['started_watching'][0])
                     > (float(video['duration']) / 3.0))
                and ((self.vlcTime - self.cache['started_watching'][1])
                     > (float(video['duration']) / 4.0))):

            self.log.info("Scrobbling " + logtitle + " to Trakt...")
            try:
                self.trakt_client.stopWatching(video["imdbid"],
                                               video["percentage"],
                                               self.get_episode(video))

                self.cache["scrobbled"] = True
                self.log.info(logtitle + " scrobbled to Trakt !")
            except TraktClient.TraktError as e:
                self.log.error("An error occurred while trying to scrobble",
                               exc_info=sys.exc_info())

        elif (((video['tv'] and self.DO_WATCHING_TV)
                or (not video['tv'] and self.DO_WATCHING_MOVIE))
                and video["percentage"] < self.SCROBBLE_PERCENT
                and not self.cache["scrobbled"]
                and ((float(video["duration"]) * float(video["percentage"])
                     / 100.0) >= self.START_WATCHING_TIMER)):

            self.log.debug("main::Trying to mark " +
                           logtitle +
                           " watching on Trakt...")

            try:
                self.trakt_client.startWatching(video["imdbid"],
                                                video["percentage"],
                                                self.get_episode(video))

                self.log.info(logtitle + " is currently watching on Trakt...")
                self.cache["watching"] = video["percentage"]
            except TraktClient.TraktError as e:
                self.log.error("An error occurred while trying to mark as " +
                               "watching " + logtitle,
                               exc_info=sys.exc_info())

        vlc.close()
Beispiel #4
0
    def main(self):
        try:
            vlc = VLCRemote(self.vlc_ip, self.vlc_port)
            self.vlc_connected = True
        except:
            if self.vlc_connected:
                self.log.info('Could not find VLC running at ' +
                              str(self.vlc_ip) + ':' + str(self.vlc_port))
                self.log.debug('Make sure your VLC player is running with ' +
                               '--extraintf=rc --rc-host=' +
                               str(self.vlc_ip) + ':' + str(self.vlc_port) +
                               ' --rc-quiet', exc_info=sys.exc_info())
                self.vlc_connected = False

                # If we were watching a video but we didn't finish it, we
                # have to cancel the watching status
                if self.cache["watching"] > -1 and not self.cache["scrobbled"]:
                    self.trakt_client.cancelWatching(
                        self.cache["video"]["imdbid"],
                        self.get_episode(self.cache["video"]))

                # If there is something in the cache, we can purge the watching
                # and scrobbled information, so if the video is opened again we
                # will consider it's a new watch
                if self.cache['vlc_file_name'] is not None:
                    self.resetCacheView()

            return

        vlcStatus = vlc.is_playing()
        if not vlcStatus:
            vlc.close()
            return

        currentFileLength = vlc.get_length()
        if not int(currentFileLength) > 0:
            self.log.debug("main::File length is 0, can't do anything")
            vlc.close()
            return

        currentFilePath = vlc.get_filename()

        if self.USE_FILENAME:
            currentFileName = currentFilePath.decode('utf-8')
        else:
            currentFileName = vlc.get_title().decode('utf-8')
        self.vlcTime = int(vlc.get_time())

        # Parse the filename to verify if it comes from a stream
        parsed = urlparse(currentFileName)
        if parsed.netloc:
            # Set the filename using only the basename of the parsed path
            currentFileName = os.path.basename(parsed.path)
        elif self.USE_FILENAME:
            # Even if it's not from a stream, if it's a filename we're using
            # we need to keep only the basename of the parsed path
            currentFileName = os.path.basename(currentFileName)

        # Use urllib's unquote to bring back special chars
        currentFileName = unquote(currentFileName)

        if (currentFileName == self.cache["vlc_file_name"]
                and currentFileLength == self.cache['vlc_file_length']):
            if (self.cache["series_info"] is None
                    and self.cache["movie_info"] is None):
                video = None
            elif self.cache["series_info"] is not None:
                video = self.get_TV(vlc, self.cache["series_info"])
            else:
                video = self.get_Movie(vlc, self.cache["movie_info"])
        else:
            self.log.debug("main::New file: %s (length: %s)"
                           % (currentFileName, currentFileLength))

            # If we were watching a video but we didn't finish it, we
            # have to cancel the watching status
            if self.cache["watching"] > -1 and not self.cache["scrobbled"]:
                self.trakt_client.cancelWatching(
                    self.cache["video"]["imdbid"],
                    self.get_episode(self.cache["video"]))

            self.resetCache(currentFilePath, currentFileName,
                            currentFileLength)
            self.cache['started_watching'] = (time.time(), self.vlcTime)

            video = self.get_TV(vlc)
            if video is None:
                video = self.get_Movie(vlc)

        if video is None:
            self.log.info(
                "No tv show nor movie found for the current playing video")
            vlc.close()
            return

        # We cache the updated video information
        self.cache["video"] = video

        logtitle = video["title"]
        if video["tv"]:
            logtitle += (" - %01dx%02d"
                         % (int(video["season"]), int(video["episode"])))

            # If we changed episode, we have to reset the view status
            if (self.cache['watching'] > -1
                    and self.cache['series_current_ep'] != video['episode']):
                self.resetCacheView(video['episode'])
                self.cache['started_watching'] = (
                    time.time(),
                    self.vlcTime % video['duration'])

        self.log.info(logtitle + " state : " + str(video["percentage"]) + "%")
        self.log.debug("main::Video: %s" % str(video))
        self.log.debug("main::This video is scrobbled : " +
                       str(self.cache["scrobbled"]))

        if (((video['tv'] and self.DO_SCROBBLE_TV)
                or (not video['tv'] and self.DO_SCROBBLE_MOVIE))
                and video["percentage"] >= self.SCROBBLE_PERCENT
                and not self.cache["scrobbled"]
                and self.cache['started_watching'] is not None
                and ((time.time() - self.cache['started_watching'][0])
                     > (float(video['duration']) / 3.0))
                and ((self.vlcTime - self.cache['started_watching'][1])
                     > (float(video['duration']) / 4.0))):

            self.log.info("Scrobbling " + logtitle + " to Trakt...")
            try:
                self.trakt_client.stopWatching(video["imdbid"],
                                               video["percentage"],
                                               self.get_episode(video))

                self.cache["scrobbled"] = True
                self.log.info(logtitle + " scrobbled to Trakt !")
            except TraktClient.TraktError as e:
                self.log.error("An error occurred while trying to scrobble",
                               exc_info=sys.exc_info())

        elif (((video['tv'] and self.DO_WATCHING_TV)
                or (not video['tv'] and self.DO_WATCHING_MOVIE))
                and video["percentage"] < self.SCROBBLE_PERCENT
                and not self.cache["scrobbled"]
                and ((float(video["duration"]) * float(video["percentage"])
                     / 100.0) >= self.START_WATCHING_TIMER)):

            self.log.debug("main::Trying to mark " +
                           logtitle +
                           " watching on Trakt...")

            try:
                self.trakt_client.startWatching(video["imdbid"],
                                                video["percentage"],
                                                self.get_episode(video))

                self.log.info(logtitle + " is currently watching on Trakt...")
                self.cache["watching"] = video["percentage"]
            except TraktClient.TraktError as e:
                self.log.error("An error occurred while trying to mark as " +
                               "watching " + logtitle,
                               exc_info=sys.exc_info())

        vlc.close()
Beispiel #5
0
  def main(self):
    try:
      vlc = VLCRemote(self.vlc_ip, self.vlc_port)
    except:
      self.log.debug('Could not find VLC running at ' + str(self.vlc_ip) + ':'+ str(self.vlc_port))
      self.log.debug('Make sure your VLC player is running with --extraintf=rc --rc-host='+ str(self.vlc_ip) +':' + str(self.vlc_port) + ' --rc-quiet')
      return
      
    vlcStatus = vlc.get_status()

    if vlcStatus:

      video = self.get_TV(vlc)

      if video is None:
        video = self.get_Movie(vlc)

      self.log.debug("----------------------------------------------------------------------------");
      self.log.debug("                             Timer : " + str(self.timer))
      self.log.debug("----------------------------------------------------------------------------");
      self.log.info(video["title"] + " - " + video["season"] + "x" + video["episode"] + " state : " + str(video["percentage"]) + "%")
      self.log.debug("This video is scrobbled : " + str(self.scrobbled))

      if (video["percentage"] >= 90
          and not self.scrobbled):
              self.log.info("Scrobbling "+ video["title"] + " to Trakt...")              
              try:
                  self.trakt_client.update_media_status(video["title"],
                                                        video["year"],
                                                        video["duration"],
                                                        video["percentage"],
                                                        VERSION,
                                                        VLC_VERSION,
                                                        VLC_DATE,
                                                        tv=video["tv"],
                                                        scrobble=True,
                                                        season=video["season"],
                                                        episode=video["episode"])
                  self.scrobbled = True
                  self.log.info(video["title"] + " - " + video["season"] + "x" + video["episode"] + " scrobbled to Trakt !")  
              except TraktClient.TraktError, (e):
                  self.log.error("An error occurred while trying to scrobble: " + e.msg)
                  if ("scrobbled" in e.msg and "already" in e.msg):
                      self.log.info("Seems we've already scrobbled this episode recently, aborting scrobble attempt.")
                      self.scrobbled = True
              
      elif (video["percentage"] < 90
            and not self.scrobbled
            and self.timer >= self.START_WATCHING_TIMER):

          # self.timer = 0

          self.log.debug("Trying to mark " + video["title"] + " - "  + video["season"] + "x" + video["episode"] + " watching on Trakt...")
      
          try:
              self.trakt_client.update_media_status(video["title"],
                                                    video["year"],
                                                    video["duration"],
                                                    video["percentage"],
                                                    VERSION,
                                                    VLC_VERSION,
                                                    VLC_DATE,
                                                    tv=video["tv"],
                                                    season=video["season"],
                                                    episode=video["episode"])
          
              self.log.info(video["title"] + " - " + video["season"] + "x" + video["episode"] + " is currently watching on Trakt...")              
          except TraktClient.TraktError, (e):
              self.timer = 870
              self.log.error("An error occurred while trying to mark watching " + video["title"] + " - " + video["season"] + "x" + video["episode"] + " : " + e.msg)
Beispiel #6
0
    def main(self):
        #--extraintf=rc --rc-host=127.0.0.1:4222 --rc-quiet
        try:
            vlc = VLCRemote(self.vlc_ip, self.vlc_port)
        except:
            self.log.debug('Could not find VLC running at ' +
                           str(self.vlc_ip) + ':' + str(self.vlc_port))
            return

        vlcStatus = vlc.get_status()
        if vlcStatus:
            video = self.get_TV(vlc)
            self.log.debug(video)
            if video is None:
                video = self.get_Movie(vlc)
                self.log.debug(video)

            if (video["percentage"] >= 90 and not self.scrobbled):
                self.log.info("Scrobbling to Trakt")

                try:
                    self.trakt_client.update_media_status(
                        video["title"],
                        video["year"],
                        video["duration"],
                        video["percentage"],
                        VERSION,
                        VLC_VERSION,
                        VLC_DATE,
                        tv=video["tv"],
                        scrobble=True,
                        season=video["season"],
                        episode=video["episode"])
                    self.scrobbled = True
                except TraktClient.TraktError, (e):
                    self.log.error(
                        "An error occurred while trying to scrobble: " + e.msg)
                    if ("scrobbled" in e.msg and "already" in e.msg):
                        self.log.info(
                            "Seems we've already scrobbled this episode recently, aborting scrobble attempt."
                        )
                        self.scrobbled = True

            elif (video["percentage"] < 90 and not self.scrobbled
                  and self.timer >= 900):
                self.log.info("Watching on Trakt")
                self.timer = 0

                try:
                    self.trakt_client.update_media_status(
                        video["title"],
                        video["year"],
                        video["duration"],
                        video["percentage"],
                        VERSION,
                        VLC_VERSION,
                        VLC_DATE,
                        tv=video["tv"],
                        season=video["season"],
                        episode=video["episode"])

                except TraktClient.TraktError, (e):
                    self.timer = 870
                    self.log.error(
                        "An error occurred while trying to mark watching: " +
                        e.msg)