forked from vadyur/script.media.aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strmwriter.py
66 lines (50 loc) · 2.03 KB
/
strmwriter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
import log
from log import debug
from base import *
import os, urllib2, sys, filesystem
class STRMWriter(STRMWriterBase):
def __init__(self, link):
self.link = link
def write(self, filename, path, seasonNumber = None, episodeNumber = None, cutname = None, index = None, parser = None, settings = None):
strmFilename = make_fullpath(filename, u'.strm')
strmFilename = filesystem.join(path, strmFilename)
#------------------------------------------
link = u'plugin://script.media.aggregator/?action=play&torrent='
link += urllib2.quote(self.link.encode('utf-8'))
if episodeNumber != None:
link += u'&episodeNumber=' + str(episodeNumber - 1)
if seasonNumber != None:
link += u'&seasonNumber=' + str(seasonNumber)
if cutname != None:
link += u'&cutName=' + urllib2.quote(cutname)
if index != None:
link += u'&index=' + str(index)
#------------------------------------------
if parser is not None:
self.make_alternative(strmFilename, link, parser)
# rank = get_rank(parser.get('full_title', ''), parser, settings),
# debug('rank: ' + str(rank))
link_with_min_rank = STRMWriterBase.get_link_with_min_rank(strmFilename, settings)
if not link_with_min_rank is None:
link = link_with_min_rank
#------------------------------------------
link += u'&nfo=' + urllib2.quote(make_fullpath(filename, '.nfo').encode('utf-8'))
#------------------------------------------
if settings != None:
path = filesystem.relpath(path, settings.base_path())
debug(path.encode('utf-8'))
link += u'&path=' + urllib2.quote(path.encode('utf-8'))
#------------------------------------------
if filesystem.exists(strmFilename):
with filesystem.fopen(strmFilename, 'r') as f:
old_link = f.read()
if old_link.decode('utf-8') == link:
return
#------------------------------------------
try:
with filesystem.fopen(strmFilename, 'w') as f:
f.write(link.encode('utf-8'))
except IOError:
debug('Error write ' + strmFilename.encode('utf-8'))
return