I want to add the default emblem to videos I've finished watching. Any straightforward, non-manual way to run a script if and exactly if a video has finished playing? Can be for any linux (mint/ubuntu) video player.

  • Is that default emblem a fixed image, or an animation? If its a fixed image, you might be able to settle to alter the not playing image from vlc-media-player – LPChip Apr 17 '15 at 21:05
  • No, I meant a caja/nautilus emblem on the video file icon. It really doesn't matter, though. I'd just like to run a shell script when and if the video has finished playing. – PSkocik Apr 17 '15 at 21:08
  • You should use a script that launches the video in your player, and configure the player to auto-close after its finished. Then associate your video with your script. I am not an expert in linux, but I can do it in Windows, so it should be possible to do in linux too I assume. – LPChip Apr 17 '15 at 21:10
  • But then it would still tag the file as watched even if I closed the player prematurely. I don't know how to distinguish between a user-invoked termination and one caused by the file having finished playing. – PSkocik Apr 17 '15 at 21:31
  • Ah, right. I guess a scripted question: was the watch complete? could do that. Otherwise I don't think its possible. – LPChip Apr 17 '15 at 21:55

Since I asked, I thought I'd share the quick wrapper-based hack I came up with that does it. I've created the following vlc wrapper and set up video files to open in it rather than vlc directly. It only supports one file at a time. If the thing that moves in vlc as it plays a file goes all the way up to the end, it will run the tag watched command at the end if about 60% of the video has been watched.

#This depends on the cli interface having been activated in the preferences
# This while loop feeds the `get_length` vlc cli command to cli every 0.1 s
(while :; do echo get_length; sleep 0.1 ; done) | 
#Pass all arguments to vlc and set it up to be fed from the `get_length` while loop
/usr/bin/vlc "$@" |
ruby  -n -e '
    BEGIN { 
    #Strip vlc cli noise
    $_=$_.sub(/^[> ]*/,"")
    #Watch consecutive (cons) empty lines
    if $_.match(/^\s*$/) 
      cons_empty += 1
      #Assume each nonempty stdin line is the duration
      duration = $_.chomp.to_i
      cons_empty = 0
      nlines_read += 1
    #On 10 consecutive empty lines, assume the file has finished playing
    if cons_empty == 10
      time_watched = nlines_read * 0.1
      p time_watched: time_watched, duration: duration
      ret = (time_watched > 0.6 * duration) ? 1 : 0
      exit ret
    ' ||
tag watched "$@" #1 exit means finished watching

It's working rather than beautiful code, but it's only a quick fix for an annoyance.


bash, ruby, + replace tag watched with your actual tagging command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.