lua for viewing history?

Discuss your Lua playlist, album art and interface scripts.
noeleonoel
New Cone
New Cone
Posts: 3
Joined: 24 Jun 2010 21:09

lua for viewing history?

Postby noeleonoel » 24 Jun 2010 21:33

Hi,
I'm wondering if it would be possible to use vlc lua to keep a list of the names of the video files I've viewed, so I can use this list to manually manage the viewed files (archive them etc).

A) I guess I would like to detect when a video starts playing, (or better yet when the end of the video is reached).
I'm thinking I could probably use the meta fetch_art() depending on when it is called. Is there a better way?

B) Once I have the video name, I would like to append it as a line in a file or something. Is it possible to write to a file? or would I need to use vlc.net to send data over tcp to another process that would write the file for the script.

Any suggestions/tips?
Thanks
Leon

noeleonoel
New Cone
New Cone
Posts: 3
Joined: 24 Jun 2010 21:09

Re: lua for viewing history?

Postby noeleonoel » 28 Jun 2010 21:59

This works for me. Now I won't have to keep notes to remember which videos I've watched. Thanks VLC team for the great tool.

Code: Select all

--[[ Lua script for vlc 1.1.0 place in VLC\lua\meta\art Logs the filename instead of getting artwork Author: noeleonoel (leonDOTringchoixATgmail) --]] -- Return the artwork normally, but instead just log the filename function fetch_art() local meta = vlc.item:metas() itemName = meta["filename"] historyFileName = "c:\\vlc-history.txt" historyfile,hfErr = io.open (historyFileName, "a+") if (historyfile == nil) then vlc.msg.err(hfErr) return nil end historyfile:write(itemName.."\n") io.close(historyfile) msg = "You watched "..itemName..". History in "..historyFileName vlc.msg.info(msg) return nil end

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: lua for viewing history?

Postby Jean-Baptiste Kempf » 29 Jun 2010 00:36

Nice trick, until VLC media library is merged.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

NealWalters
New Cone
New Cone
Posts: 1
Joined: 06 Mar 2011 22:18

Re: lua for viewing history?

Postby NealWalters » 06 Mar 2011 22:23

What triggers this LUA to run? I added a file called c:\Program Files (x86)\VideoLAN\VLC\lua\playlist\keepHistory.lua.
Yet, after starting a vidoe for a few seconds and closing VLAN, no file called "c:\\vlc-history.txt" was created.

For the last few months, I've been trying to record the movies and shows I watch on Google Calendar as a history. After 10 or 20 years, it would be really cool to go back and see when was the last time I watched "movie xyz", or when did I first see it...

I'm running Win 7 64-bit.

Thanks,
Neal Walters

Diabl0570
New Cone
New Cone
Posts: 4
Joined: 16 May 2011 18:10

Re: lua for viewing history?

Postby Diabl0570 » 16 May 2011 18:16

Hi VLC-community!

Could someone add some more info how to use this script?
i am searching for ages for a way to keep a nice history file.

i want to make a script to check whether i allready have seen the movie or episode i want to start.

thanks in advance!

noeleonoel
New Cone
New Cone
Posts: 3
Joined: 24 Jun 2010 21:09

Re: lua for viewing history?

Postby noeleonoel » 08 Sep 2011 11:58

Here is my latest version.
It launches more often than it needs to, It should probably be in a different VLC\lua folder, and use a different function, but I haven't taken the time to figure it out. It works for what I need it for.

Code: Select all

--[[ Lua script for vlc 1.1.11 Logs the filename instead of getting artwork Author: noeleonoel C:\Program Files\VideoLAN\VLC\lua\meta\reader\00_test.lua --]] function read_meta() local meta = vlc.item:metas() itemName = meta["filename"] historyFileName = "c:\\vlc-history.txt" historyfile,hfErr = io.open (historyFileName, "a+") if (historyfile == nil) then vlc.msg.err(hfErr) return nil end historyfile:write(itemName..","..os.date().."\n") io.close(historyfile) vlc.msg.info("You watched "..itemName..". History in "..historyFileName) os.execute ("ruby \"C:\\Documents and Settings\\you\\My Documents\\ruby\\shows.rb\"") return nil end
Here is the work in progress ruby 1.9.2 script I use to let me know what episodes I've watched, and if I missed any.

Code: Select all

## # ruby 1.9.2 script to format the vlc log created by 00_test.lua # Author: noeleonoel # C:\Documents and Settings\YOU\My Documents\ruby\shows.rb ## if __FILE__ == $0 def main(args) #if (args[0]. debug = args.include?("debug") pause = args.include?("pause") #load episode history file printing any skipped lines that are not comments episodes, skipped = loadHistory "c:\\vlc-history.txt" unless (skipped.empty?) then skipped.each {|line| print line + "\n" } end #print all the history print "Full history:\n" episodes.sort.each {|ep| print "#{ep}\n"} #get the last episode (or first if debugging) lastEpisode = episodes[-1] firstEpisode = episodes[0] focusEpisode = debug ? firstEpisode : lastEpisode #arrange the episodes shows = arrangeEpisodesByTitleSeason(episodes) #print all seasonInfos titleseasons = [focusEpisode.titleSeason] episodes.each {|ep| if (!titleseasons.include?(ep.titleSeason)) then titleseasons.push(ep.titleSeason) print "\n" print ep.titleSeason, "\n" print getEpisodeSeasonInfo(shows, ep, 0, "\n") end } #print info for the last show print "\nThe last show watched in the history was\n" print getEpisodeSeasonInfo(shows, focusEpisode, 1, "\n") if (debug) then unless (skipped.empty?) then skipped.each {|line| print line + "\n" } end end lastEpisodeBeforeGap = findEpisodeBeforeGap(shows, focusEpisode) if (lastEpisodeBeforeGap) then print "\n!!!!!\nYou missed episode #{lastEpisodeBeforeGap.episode+1} before the show you just started.\n#{focusEpisode}" pressAKey else if (pause) then pressAKey else sleep 3 end end end end class Tag attr_accessor :content, :attributes, :tag def initialize( dest ) @tag = :div @content = dest @attributes = Hash.new end def start @content << "<#{@tag}" unless @attributes.empty? then @attributes.each do|attr,val| @content << " #{attr}=\"#{val}\"" end end @content << ">\n" end def close @content << "</#{@tag}>\n" end end class OneTimeTag < Tag def close super @content = nil #only one header allowed end end class Style < Tag def initialize( dest ) super @tag = :style @attributes[:type] = "\"text/css\"" end end class JavaScript < Tag def initialize( dest ) super @tag = :script @attributes[:type] = "\"text/javascript\"" end end class Head < OneTimeTag def initialize( dest ) super @tag = :head end end class Body < OneTimeTag def initialize( dest ) super @tag = :body end end class A < Tag def initialize( dest ) super @tag = :div end def start( href ) @attributes[:href] = href super() end end class Div < Tag def initialize( dest ) super @tag = :div @extraClose = false end def collapsed(childId) @extraClose = true @attributes[:onclick] = "toggleCollapseElement('#{childId}')" start content << "<div class='toggle'>" + childId + "</div>" @attributes.delete(:onclick) @attributes[:class] = "collapsed" @attributes[:id] = childId start end def startWClass(cssClass) @attributes[:class] = cssClass start end def close @attributes.delete(:class) @attributes.delete(:id) super if @extraClose super end end class Shows attr_accessor :fileName, :result def initialize( fileName ) @fileName = fileName @result = "" @newline = "<br>\n" #pause = false end def load @result = "" head = Head.new(@result) head.start javaScript = JavaScript.new(head.content) javaScript.start javaScript.content << <<-eos function toggleCollapseElement(id) { var e = document.getElementById(id); if (e.style.display != "block") e.style.display="block"; else e.style.display="none"; } eos javaScript.close style = Style.new(head.content) style.start style.content << <<-eos <!-- .collapsed {display:none;} .toggle {color:blue;} .warn {color:red;} .green {color:darkgreen;} --> eos style.close head.close @body = Body.new(@result) @body.start @div = Div.new(@result) #load episode history file printing any skipped lines that are not comments episodes, skipped = loadHistory @fileName unless (skipped.empty?) then @div.collapsed("skipped") skipped.each {|line| @result << line + @newline } @div.close end @div.collapsed("history") #print all the history @result << "<h1>Full history:</h1>#{@newline}" episodes.sort.each {|ep| @result << "#{ep}#{@newline}"} @div.close #get the last episode (or first if debugging) lastEpisode = episodes[-1] #firstEpisode = episodes[0] focusEpisode = lastEpisode #debug ? firstEpisode : lastEpisode #arrange the episodes in a hash shows = arrangeEpisodesByTitleSeason(episodes) @div.startWClass(:green) #print info for the last show @result << "#{@newline}The last show watched in the history was#{@newline}" @result << getEpisodeSeasonInfo(shows, focusEpisode, 1, @newline) @div.startWClass(:warn) lastEpisodeBeforeGap = findEpisodeBeforeGap(shows, focusEpisode) if (lastEpisodeBeforeGap) then @result << "#{@newline}!!!!!#{@newline}You missed episode #{lastEpisodeBeforeGap.episode+1} before the show you just started.#{@newline}#{focusEpisode}" # pressAKey # else # if (pause) then pressAKey else sleep 3 end end @div.close @div.close @div.start #print all seasonInfos titleseasons = [focusEpisode.titleSeason] episodes.each {|ep| if (!titleseasons.include?(ep.titleSeason)) then titleseasons.push(ep.titleSeason) @result << @newline @result << ep.titleSeason + @newline @result << getEpisodeSeasonInfo(shows, ep, 0, @newline) end } @div.close @body.close result end end class Episode attr_accessor :title, :season, :episode, :info, :watchedTime def initialize( videoName ) begin videoName = videoName.gsub(/\.(\d{1,2})x(\d{1,3})/i,'S\1E\2') rescue end episode_re = /(.+)S(\d{1,3})E(\d{1,3})(.+),(.+)/i begin m = episode_re.match(videoName) rescue end unless m #puts "There was no match..." return end @title=m[1].split(/[\s\-.]+/).join(".").capitalize @title = @title.gsub(/\.?20\d\d/,"") @season=m[2].to_i @episode=m[3].to_i @info=m[4] @watchedTime=m[5] end def rank season * 1000 + episode end def to_s "Episode #{title}.S#{season}E#{episode}#{info} watched on #{watchedTime}" end def titleSeason "#{title}.S#{season}" end include Comparable def <=>(o) if self.class == o.class then result = @title <=> o.title if (result == 0) then result = rank <=> o.rank end else nil end result end end def loadHistory(fileName) myfile = File.open(fileName) episodes = [] skipped = [] myfile.each_with_index { |line,i| index = nil begin index = line.index(/Media Library,\d/) rescue end if (nil == index) then #print line + "\n" videoName = line episode = Episode.new(videoName) if (episode.title) then episodes.push(episode) else ans = false begin ans = line =~ /^\/\// rescue end unless (ans) then skipped.push("WARNING unable to parse line ##{i+1} '#{line.chomp}'") end end end } return episodes, skipped end def arrangeEpisodesByTitleSeason(episodes) shows = {} episodes.each {|ep| #print ep.to_s + "\n" if (!shows[ep.title]) then seasons = {ep.season => [ep]} shows[ep.title] = seasons else seasons = shows[ep.title] if (!seasons[ep.season]) then seasons[ep.season] = [ep] else seasons[ep.season].push ep end end } return shows end def getEpisodeSeasonInfo(shows, episode, verbose, newline) result = "" episodeSeasons = shows[episode.title] episodeSeasonEpisodes = episodeSeasons[episode.season].sort otherSeasons = episodeSeasons.keys.sort otherSeasons.delete(episode.season) if (otherSeasons.length == 0) then otherSeasonsMsg = "The history has no other seasons for this episode" else otherSeasonsMsg = "The history also has seasons #{otherSeasons} for this episode" end seasonEpisodes = [] episodeSeasonEpisodes.each {|ep| if (!seasonEpisodes.include?(ep.episode)) then seasonEpisodes.push(ep.episode) end } missedSeasonEpisodes = [] prevEpisode = seasonEpisodes[-1]-1 prevEpisode.downto(1) {|prev| if (!seasonEpisodes.include?(prev)) then missedSeasonEpisodes.push prev end} #missedSeasonEpisodes.reverse! result << "#{episode}#{newline}" if (verbose == 1) then episodeSeasonEpisodes.each {|ep| result << " #{ep}#{newline}" } end result << " The full #{episode.titleSeason} history is #{seasonEpisodes}#{newline} #{otherSeasonsMsg}#{newline}" if (missedSeasonEpisodes.length > 0) then result << " ! You missed episodes #{missedSeasonEpisodes}#{newline}" end result << " #{otherSeasonsMsg}#{newline}" result end def findEpisodeBeforeGap(shows, episode) episodeSeasons = shows[episode.title] episodeSeasonEpisodes = episodeSeasons[episode.season].sort prevIndex = episodeSeasonEpisodes.index(episode)-1 beforeGapEpisode = nil if (prevIndex >= 0) then prevEpisode = episodeSeasonEpisodes.at(prevIndex) if (episode.episode - prevEpisode.episode > 1) then beforeGapEpisode = prevEpisode end end return beforeGapEpisode end def pressAKey print "\nPress Enter ...." STDIN.gets end if __FILE__ == $0 ARGV.each {|a| print a} main ARGV end

Diabl0570
New Cone
New Cone
Posts: 4
Joined: 16 May 2011 18:10

Re: lua for viewing history?

Postby Diabl0570 » 09 Sep 2011 20:58

Great thanks for your share,
i made something with EventGhost(Python) when you start up it automaticly checks if you have seen the episode (or not).
If you already have seen the eppisode you are watching, "it" will warn you. You got 3 options IF you want to start the next episode click "start next episode",
how ever if you want to watch the next episode you did not have seen already you can click "watch next unwatched episode". you Can also say that you want to see this episode anyway. here is a screen shot.

http://www.dropmocks.com/mZSW8

i also made a option to shutdown your pc after the movie or tv show has finished playback.
i am thinking of making something more stable and user friendly so we can eazily share with the community but don't know yet how.
thanks for your code noeleonoel, i'm gonne study your code maybe your method is better than mine becouse my code is not user friendly and will currently only work on my machine with my setup.

but if anyone is interested i will consider releasing it here.

n.bexter
New Cone
New Cone
Posts: 3
Joined: 20 Sep 2011 21:36

Re: lua for viewing history?

Postby n.bexter » 21 Sep 2011 18:22

Hey Diabl0570,

would be really too cool to use your script, I'm trying s.th. very similar but did not get any results yet. Using LUA works quit good but does not suffice, how do you "speak" with VLC?

Diabl0570
New Cone
New Cone
Posts: 4
Joined: 16 May 2011 18:10

Re: lua for viewing history?

Postby Diabl0570 » 21 Sep 2011 20:03

i communicate with EventGhost, i send via LUA the file name that is playing to eventghost. In EventGhost i fix the rest of the stuff
but let me clear some thing out here:
i have made 3 function in my screenshot:
1 = check if episode is already in the wachted list, and if not write it to the watched file
2 = if already watched give a option to start the NEXT episode
3 = if already watched give a option to start the NEXT UNWACHTED episode

method 2 AND 3 will only work if you have the same setup as i have.

i use SickBeard + SABnzdb for downloading and renaming my series so my directory structure is always the same:
T:\The Simpsons\Season 01\The Simpsons - S01E01 - episode title
T:\The Simpsons\Season 01\The Simpsons - S01E02 - episode title

T:\South Park\Season 02\South Park - S02E01 - episode title


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 12 guests