novoid / Memacs

What did I do on February 14th 2007? Visualize your (digital) life in Org-mode
GNU General Public License v3.0
1.03k stars 66 forks source link

kodi: probable issue with content of row (OrderedDict) #94

Closed novoid closed 4 years ago

novoid commented 4 years ago

Hi @DerBeutlin,

I took a quick look at the very promising kodi logger module and I got an issue on my side. I'm not sure if I'm handling it wrong or if there is an issue with the code.

What I've got

Current kodi Memacs module and the first release of the kodi logger.

video.log contains:

1580983686;started;0;20;nfs://192.168.1.2/home/user/tv/2019-10-02T20.14.55 ORF - Liebesg'schichten und Heiratssachen - Signation -- highquality.mp4;;;;-1;-1;

What I start

I start the Memacs module manually:

PYTHONPATH=/home/vk/src/memacs /home/vk/src/memacs/bin/memacs_kodi.py \
        -f ~/log/kodi/video.log \
        --action-field started \
        --identification-fields title \
        --minimal-pause-duration 15 \
        --timestamp-field timestamp \
        --output-format "{title}" \
        -v

Error

I then get:

[...]
  File "/home/vk/src/memacs/memacs/kodi.py", line 106, in read_timestamp
    int(row[self._args.timestamp_field]))
KeyError: 'timestamp'

I'd expect the module to produce Org mode output with the parsed and formatted content of the log.

Analysis

I debugged the situation. When I set a breakpoint at the corresponding line, I get:

(Pdb) row
OrderedDict([('1580983686', '1581017114'), ('started', 'started'), ('0', '0'), ('20', '2250'), ("nfs://192.168.1.2/home/user/tv/liebesgschichten und heiratssachen/2019-10-02t20.14.55 orf - liebesg'schichten und heiratssachen - signation -- highquality.mp4", '<next video file>'), ('', ''), ('-1', '-1')])

To clarify, here is the list of keys:

odict_keys(['1580983686', 'started', '0', '20', "nfs://192.168.1.2/home/user/tv/liebesgschichten und heiratssachen/2019-10-02t20.14.55 orf - liebesg'schichten und heiratssachen - signation -- highquality.mp4", '', '-1'])

So there is no row['timestamp'] or similar. There seem to be values as keys. Is this because of my inability to understand the source code and use the module properly or is this a bug?

Thanks!

DerBeutlin commented 4 years ago

I will take a look into this but first of all kodi module is broken at least in my tests... It complains about the imports (https://github.com/novoid/Memacs/blob/master/memacs/kodi.py#L10) which are different from the other modules. I guess problem was the restructuring between creating and merging this module, do you think it would be just fixed by adapting the imports?

I opened a pull request, making it work with the new import structure and orgformat library, will try to reproduce your problems

DerBeutlin commented 4 years ago

Ok I know what is the error, you're missing the argument --fieldnames which tells the module whats in your csv file and --action_field corresponds to the field which corresponds to the action so e.g.

PYTHONPATH=/home/vk/src/memacs /home/vk/src/memacs/bin/memacs_kodi.py \
        -f ~/log/kodi/video.log \
        --fieldnames timestamp,action,position,length,path,album,artist,title \
        --action-field action \
        --identification-fields title \
        --minimal-pause-duration 15 \
        --timestamp-field timestamp \
        --output

Then the program runs through, right now it does not print out the entry but that's another issue I will investigate it does not output an entry yet because the log consists only of a start action and you need the corresponding end action to create an org entry.

I guess kodi should error out if mandatory arguments are not passed, maybe one should take the opportunity and exchange the args parsing with something like click which makes it very easy to create really nice cli tools-format

novoid commented 4 years ago

Awesome,

I can confirm that the following is producing the desired output to stdout:

PYTHONPATH=/home/vk/src/memacs /home/vk/src/memacs/bin/memacs_kodi.py \
        -f ~/log/kodi/video.log \
        --fieldnames timestamp,action,position,length,path,album,artist,title \
        --action-field action \
        --identification-fields title \
        --minimal-pause-duration 15 \
        --timestamp-field timestamp \
        --output-format "{path}" \
        -v

Most entries are perfect, except that pausing the playback for a few seconds causes an additional entry that messes up my agenda. But I understand the implications. I'll think about this and maybe a minimum pause setting could "smoothen" this a bit.