Author Topic: Need File.ReadLine [<line_num>][<num_lines>]  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

ajith

  • $upporter
  • Contributor
  • *****
  • Posts: 87
  • Karma: 2
    • View Profile
Need File.ReadLine [<line_num>][<num_lines>]
« on: May 01, 2012, 02:26:22 PM »
Hi,

Is there a way to read lines from text files?
We do have File.Append, File.AppendLine and File.WriteLine.
So it is only logical to have the read capability.

The need for this feature arose from the fact that I want to persist the last media played (in XBMC) and its percentage when stopping playback, so that I can read it back later (possibly after a reboot) and resume playback of the same from where I left off.

Do let me know if there is a more elegant solution than what I have in mind.


Thanks and Regards,
Ajith

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #1 on: May 01, 2012, 11:35:24 PM »
Yes you are right, there probably should be some kind of File.Read command.

You can actually use the scrape command like this:

Scrape   file://D:\VoxTests\1 Debug\test.txt

I don't think there is a way to do it with relative paths though... and of course it reads the whole file so you need to break it up yourself.  You could store it using an xml format and then use results.regex to get what you want.  Let me know if you need more help.

We also have actions to write to a payloadXML files which could be useful, since these are basically a bunch of key/value pairs perfect for storing variables, but again I don't really have a read command for them, except to grab one at random.  I should have a command to read the value for a certain phrase or vice versa.

ajith

  • $upporter
  • Contributor
  • *****
  • Posts: 87
  • Karma: 2
    • View Profile
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #2 on: May 02, 2012, 11:32:47 AM »
Hello James,

I used Scrape to read the file like you suggested, and it works fine.

I ran into another problem: 

Code: [Select]
XBMC.Send  execbuiltin(PlayMedia({Match.1}))
doesn't seem to be working while

Code: [Select]
XBMC.Send  execbuiltin(PlayMedia(/media/Movies/Batman returns.mkv))
is working.

In the above non-working case, I verified that Match.1 does contain /media/Movies/Batman returns.mkv

So what might be the problem here?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #3 on: May 02, 2012, 12:03:41 PM »
not sure.  I'll look into it.  Just to be extra safe, can you send me an xml of the group with these commands in it.

also, can you tell me anything more than "not work".  What shows up in the history window.  What about the log?  Does anything happen on XBMC?

btw, you might find it a bit easier to use/read:

XBMC.ExecBuiltin    ABC

instead of

XBMC.Send  ExecBuiltin(ABC)

less nested brackets


ajith

  • $upporter
  • Contributor
  • *****
  • Posts: 87
  • Karma: 2
    • View Profile
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #4 on: May 02, 2012, 12:57:33 PM »
I'm sorry I should have looked at the logs first, or provided you with them in the first place.
Well, I looked, and got the source of the problem - Match.1 was returning the path along with an unwanted trailing newline from the file that was written using File.WriteLine. This was because of the file format I chose (not XML).
XBMC doesn't seem to like newlines in media paths.

I have gotten rid of the newline since and now everything is fine :).

Now I can say "Play Last Media" and the last file that I had stopped with the voice command "Stop Playback" would start playing ... surviving XBMC restarts or even reboots :)

I'm also storing the "Time" of stoppage. I'm now going to try and make it seek to this stored time upon executing "Play Last Media".


Thanks and regards,
Ajith

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #5 on: May 02, 2012, 01:01:55 PM »
sounds pretty cool.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #6 on: May 02, 2012, 01:14:29 PM »
I'm sorry I should have looked at the logs first, or provided you with them in the first place.
Well, I looked, and got the source of the problem - Match.1 was returning the path along with an unwanted trailing newline from the file that was written using File.WriteLine. This was because of the file format I chose (not XML).
XBMC doesn't seem to like newlines in media paths.

I have gotten rid of the newline since and now everything is fine :).

Now I can say "Play Last Media" and the last file that I had stopped with the voice command "Stop Playback" would start playing ... surviving XBMC restarts or even reboots :)

I'm also storing the "Time" of stoppage. I'm now going to try and make it seek to this stored time upon executing "Play Last Media".


Thanks and regards,
Ajith
If you want, you can upload this nice command group here  ;)
***********  get excited and make things  **********

ajith

  • $upporter
  • Contributor
  • *****
  • Posts: 87
  • Karma: 2
    • View Profile
Re: Need File.ReadLine [<line_num>][<num_lines>]
« Reply #7 on: May 02, 2012, 01:51:03 PM »
If you want, you can upload this nice command group here  ;)

I surely will, once I finish it :)


Done! ... See the 'XML Exchange' section  :)
« Last Edit: May 02, 2012, 03:15:58 PM by ajith »