ukdtom / SRT2UTF-8.bundle

Plex Agent, that'll convert sidecar subtitle files into UTF-8, if not
126 stars 14 forks source link

Allow srt's downloaded by an agent to be managed as well #18

Closed ukdtom closed 9 years ago

ukdtom commented 9 years ago

Might take some time here, and not easy ;-)

pristas-peter commented 9 years ago

Hi, it's kinda possible with this code:

    plugins_dir = os.path.dirname(os.path.dirname(os.getcwd()))
    media_dir = os.path.join(os.path.dirname(plugins_dir), 'Media', 'localhost')

    db_file = os.path.join(plugins_dir, 'Databases', 'com.plexapp.plugins.library.db')
    conn = sqlite3.connect(db_file)
    c = conn.cursor()

    for row in c.execute("""
        SELECT url, language 
        from media_streams, media_parts 
        where media_parts.file =? 
        and media_parts.id = media_streams.media_part_id 
        and media_streams.codec in ('srt', 'sub')""", [part.file]):
            subtitle_file = os.path.join(media_dir, row[0].replace('media://', ''))
            subtitle_lang = row[1]  # values are country codes 'eng', 'cze' ...
            Log.Debug(subtitle_file)
            Log.Debug(subtitle_lang)

    c.close()
ukdtom commented 9 years ago

Sadly....Your code is perfect, but direct access to the SQL database is not avail on all platforms, since most NAS devices can't do an include of sqlite, sue to a missing file.

And I have to provide this to all platforms ;-)

But when said....code is all most there, since I made it for another project https://github.com/dagalufh/WebTools.bundle already, so now "only" need to hook it in.

pristas-peter commented 9 years ago

Oh yeah, you are right about sqlite, well the other solution to it is to dig that info through WEB API: I guess this should work:

inside that timer function:

ukdtom commented 9 years ago

Not possible either ;-)

This is an agent, running when a media is added, and due to that, it's not yet possible to access the web api for it ;-)

pristas-peter commented 9 years ago

That's why i have mentioned Thread.CreateTimer(), the code would be executed in a seperate thread later, so it would work

ukdtom commented 9 years ago

Not needed...I get it handed down to me by the primary agent ;-)

You can follow my progress in the tommy-work branch, and are more than welcome to fork and add a pull request

ukdtom commented 9 years ago

And please take a peak here:

https://forums.plex.tv/index.php/topic/94864-rel-str2utf-8/?p=766258

pristas-peter commented 9 years ago

Hi, I have done it, it works for Movies/Tv Shows and every subtitles agent, this agent should be the last in chain, but it is not mandatory:

https://github.com/pristas-peter/SRT2UTF-8.bundle/blob/master/Contents/Code/__init__.py

ukdtom commented 9 years ago

But....Did you see my req. for beta testers?

I also did it, but without spawning a thread, which IMHO would be better.

pristas-peter commented 9 years ago

Yes, but it is only compatible with movies and opensubtitles, this is universal solution

ukdtom commented 9 years ago

True, but to be frank, I don't wanna use the http api due to speed, nor the threading metode, and I also want to be able to enable/disable the look for individual agents, as I've done so far in the beta. If people test this, then it's easy to add support for others as well, like Podnapsi. And regarding TV-Shows, then the code is already there, just remarked, since I wanted beta testers to test slowly.

pristas-peter commented 9 years ago

Ok bro, whatever you want, it's your project... For me it works and I just wanted to share with the community...

ukdtom commented 9 years ago

Fixed in V0.0.2.0