from urllib2 import urlopen
from Components.MenuList import MenuList
from Components.Label import Label
from Screens.InfoBarGenerics import InfoBarSeek, InfoBarCueSheetSupport
from Screens.HelpMenu import HelpableScreen
from Components.Sources.StaticText import StaticText
from Components.Sources.Boolean import Boolean
from Components.ActionMap import HelpableActionMap, ActionMap
from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
from Components.VideoWindow import VideoWindow
from Components.Label import Label, MultiColorLabel
from Components.Pixmap import Pixmap
from Components.GUIComponent import GUIComponent
from Components.ConfigList import ConfigListScreen
from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigPassword, ConfigYesNo, ConfigText
from enigma import eListboxPythonMultiContent, eServiceReference, getDesktop, iPlayableService, eSize, ePicLoad, iServiceInformation
from ServiceReference import ServiceReference
from Tools.Directories import SCOPE_PLUGINS, resolveFilename
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Components.ActionMap import NumberActionMap
from Components.Input import Input
from Components.Pixmap import Pixmap
from Components.FileList import FileList
from Screens.ChoiceBox import ChoiceBox
from Plugins.Plugin import PluginDescriptor
from Components.ActionMap import ActionMap
from Screens.InputBox import InputBox, PinInput
from Screens.HelpMenu import HelpableScreen
from __init__ import __
from enigma import eServiceReference
from enigma import eServiceCenter
from Screens.InfoBar import MoviePlayer
import os
from os import system
import re
import time
from Components.config import config, ConfigSelection, ConfigYesNo, getConfigListEntry
from Components.config import config, ConfigSelection, getConfigListEntry, ConfigText, ConfigDirectory, ConfigYesNo, ConfigSelection
from enigma import gFont, eTimer, eConsoleAppContainer, ePicLoad, loadPNG, getDesktop, eServiceReference, iPlayableService, eListboxPythonMultiContent, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER
from Components.MenuList import MenuList
from hashlib import md5
import binascii
from Components.Task import Task, Job, job_manager as JobManager, Condition
from Screens.TaskView import JobView
from Components.Button import Button
from Tools.Directories import fileExists, copyfile
from Components.Task import Task, Job, job_manager as JobManager, Condition
from Screens.TaskView import JobView
from Components.Button import Button
from Tools.Directories import fileExists, copyfile
from Screens.InfoBarGenerics import Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarShowHide, InfoBarServiceErrorPopupSupport, InfoBarPVRState, InfoBarSimpleEventView, InfoBarServiceNotifications, InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, InfoBarTeletextPlugin
from Screens.HelpMenu import HelpableScreen
from Components.ActionMap import HelpableActionMap
from Components.config import config
from Components.AVSwitch import eAVSwitch
from Screens.ChoiceBox import ChoiceBox
from Components.FileList import FileList, FileEntryComponent
class
MuratTV(Screen):
skin = '\n\t\t<screen name="MuratTV" position="center,center" size="600,560" title="MuratTV" >\n\t\t\t<!--widget name="text" position="0,0" size="650,25" font="Regular;20" /-->\n\t\t\t<widget name="list" position="05,0" size="580,550" scrollbarMode="showOnDemand" />\n\t\t\t<!--widget name="pixmap" position="200,0" size="190,250" /-->\n\t\t\t<eLabel position="70,100" zPosition="-1" size="100,69" backgroundColor="#222222" />\n\t\t\t<widget name="info" position="100,230" zPosition="4" size="600,25" font="Regular;18" foregroundColor="#ff0000" transparent="1" halign="center" valign="center" />\n\t\t</screen>'
def __init__(self, session):
self.skin =
MuratTV.skin
Screen.__init__(self, session)
self['list'] = MenuList([])
self['info'] = Label()
self['actions'] = ActionMap(['OkCancelActions'], {'ok': self.okClicked,
'cancel': self.cancel}, -1)
self.data = []
self.names = []
self.urls = []
self.srefOld = self.session.nav.getCurrentlyPlayingServiceReferen ce()
self.onLayoutFinish.append(self.stream)
self.playlistparsers = {}
def stream(self):
path = '/usr/lib/enigma2/python/Plugins/Extensions/MuratTV/playlists'
self.streamlist = []
for root, dirs, files in os.walk(path):
for name in files:
self.streamlist.append(name)
self['list'].setList(self.streamlist)
def cancel(self):
self.session.nav.playService(self.srefOld)
self.close()
def keyRight(self):
self['text'].right()
def okClicked(self):
itype = self['list'].getSelectionIndex()
sfile = self.streamlist[itype]
self.session.open(Streamurl, sfile)
def keyNumberGlobal(self, number):
print 'pressed', number
self['text'].number(number)
class Streamurl(Screen):
skin = '\n\t\t<screen position="center,center" size="550,400" title="
MuratTV" >\n\t\t\t<!--widget name="text" position="0,0" size="550,25" font="Regular;20" /-->\n\t\t\t<widget name="list" position="05,0" size="500,350" scrollbarMode="showOnDemand" />\n\t\t\t<!--widget name="pixmap" position="200,0" size="190,250" /-->\n\t\t\t<eLabel position="70,100" zPosition="-1" size="100,69" backgroundColor="#222222" />\n\t\t\t<widget name="info" position="100,230" zPosition="4" size="300,25" font="Regular;18" foregroundColor="#ff0000" transparent="1" halign="center" valign="center" />\n\t\t</screen>'
def __init__(self, session, sfile):
self.skin =
MuratTV.skin
Screen.__init__(self, session)
self['list'] = MenuList([])
self['info'] = Label()
self['actions'] = ActionMap(['OkCancelActions'], {'ok': self.okClicked,
'cancel': self.cancel}, -1)
self.sfile = sfile
self.data = []
self.names = []
self.urls = []
self.srefOld = self.session.nav.getCurrentlyPlayingServiceReferen ce()
self.onLayoutFinish.append(self.stream)
def stream(self):
STREAM_AD = '/usr/lib/enigma2/python/Plugins/Extensions/
MuratTV/playlists/' + self.sfile
print 'STREAM_AD =', STREAM_AD
myfile = open(STREAM_AD, 'r')
icount = 0
for line in myfile.readlines():
print 'line =', line
self.data.append(icount)
self.data[icount] = line[:-1]
icount = icount + 1
n = len(self.data)
n1 = n / 2
print 'n1 = ', n1
i = 0
j = 0
k = 0
while i < n1:
j = i * 2
k = i * 2 + 1
self.names.append(i)
self.names[i] = self.data[j]
self.urls.append(i)
self.urls[i] = self.data[k]
i = i + 1
self['list'].setList(self.names)
def cancel(self):
self.session.nav.playService(self.srefOld)
self.close()
def keyRight(self):
self['text'].right()
def okClicked(self):
itype = self['list'].getSelectionIndex()
url = self.urls[itype]
name = self.names[itype]
if 'urulu' in url:
self.session.open(Yasakstream, name, url)
else:
STREAM_AD = ' '
pvid = Playvid(self.session, name, url)
pvid.start()
def keyNumberGlobal(self, number):
print 'pressed', number
self['text'].number(number)
class Yasakstream(Screen, InfoBarBase, InfoBarSeek, HelpableScreen):
STATE_DISCONNECTED, STATE_CONNECTING, STATE_PLAYING, STATE_PAUSED, STATE_FAILURE = range(5)
STATE_NAMES = [__('disconnected'),
__('connecting...'),
__('LIVE'),
__('pause'),
__('No Connection')]
STREAM_DIM = (768, 576)
PIP_DIM = (532, 424)
def keyOK(self):
itype = self['list'].getSelectionIndex()
url = self.urls[itype]
name = self.names[itype]
if 'url' in url:
self.session.open(Yasakstream, name, url)
else:
STREAM_AD = ' '
pvid = Playvid(self.session, name, url)
pvid.start()
CENTER_POS = (560 - PIP_DIM[0]) / 2
skin = '\n\t<screen position="center,center" size="560,470" title="Play Options" flags="wfNoBorder">\n\t\t<ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />\n\t\t<ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />\n\t\t<ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />\n\t\t<ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />\n\t\t<widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />\n\t\t<widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />\n\t\t<widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />\n\t\t<widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />\n\n\t\t<widget source="pig_mode" render="Pig" position="%i,60" size="%i,%i" zPosition="0" backgroundColor="transparent">\n\t\t\t<convert type="ConditionalShowHide" />\n\t\t</widget>\n\t\t<widget name="poster" position="%i,60" size="%i,%i" alphatest="on" zPosition="2" />\n\t\t<widget name="connection_label" position="85,422" size="384,48" font="Regular;24" valign="center" halign="center" foregroundColors="#000000,#FFFF00,#00FF00,#AAAAAA, #FF0000" />\n\t\t<widget source="do_blink" render="FixedLabel" text=" " position="85,434" zPosition="1" size="384,24">\n\t\t\t<convert type="ConditionalShowHide">Blink</convert>\n\t\t</widget>\n\t</screen>' % (CENTER_POS,
PIP_DIM[0],
PIP_DIM[1],
CENTER_POS,
PIP_DIM[0],
PIP_DIM[1])
def __init__(self, session, name, url):
Screen.__init__(self, session)
self.skin = Yasakstream.skin
InfoBarBase.__init__(self, steal_current_service=True)
InfoBarSeek.__init__(self, actionmap='CutlistSeekActions')
HelpableScreen.__init__(self)
self.old_service = session.nav.getCurrentlyPlayingServiceReference()
self.session.nav.stopService()
self['key_red'] = StaticText(__('Exit'))
self['key_green'] = StaticText(__(''))
self['key_yellow'] = StaticText('')
self['key_blue'] = StaticText(__(''))
self['connection_label'] = MultiColorLabel()
self['do_blink'] = Boolean(False)
self['pig_mode'] = Boolean(True)
self['poster'] = Pixmap()
self.picload = ePicLoad()
self.picload.PictureData.get().append(self.paintPo sterPixmapCB)
self['actions'] = ActionMap(['OkCancelActions',
'ColorActions',
'InfobarSeekActions',
'MediaPlayerActions'], {'ok': self.keyOK,
'cancel': self.exit,
'stop': self.disconnect,
'playpauseService': self.playpauseService,
'red': self.exit,
'green': self.keyOK,
'blue': self.keyBlue,
'yellow': self.keyYellow,
'seekFwd': self.keyPass}, -4)
self.__event_tracker = ServiceEventTracker(screen=self, eventmap={iPlayableService.evStart: self.__serviceStarted,
iPlayableService.evUpdatedEventInfo: self.__streamStarted,
iPlayableService.evTuneFailed: self.__streamFailed,
iPlayableService.evEOF: self.__evEOF,
iPlayableService.evUser + 15: self.__streamFailed})
self.onClose.append(self.__onClose)
self.onExecBegin.append(self.__onExecBegin)
self.setState(self.STATE_DISCONNECTED)
def __onExecBegin(self):
from Components.AVSwitch import AVSwitch
sc = AVSwitch().getFramebufferScale()
self.picload.setPara((self['poster'].instance.size().width(),
self['poster'].instance.size().height(),
self.PIP_DIM[0],
self.PIP_DIM[1],
False,
1,
'#00000000'))
self.picload.startDecode(resolveFilename(SCOPE_PLU GINS) + 'Extensions/MuratTV/' + 'yasak.jpg')
def setState(self, state):
if state <= self.STATE_FAILURE:
self.state = state
self['connection_label'].setForegroundColorNum(self.state)
self['connection_label'].setText(self.STATE_NAMES[self.state])
if self.state in (self.STATE_CONNECTING, self.STATE_PAUSED):
self['do_blink'].setBoolean(True)
else:
self['do_blink'].setBoolean(False)
if self.state in (self.STATE_DISCONNECTED, self.STATE_CONNECTING, self.STATE_FAILURE):
self.togglePIG(fullscreen=False)
if self.state in (self.STATE_PLAYING, self.STATE_PAUSED):
self['poster'].hide()
self['pig_mode'].setBoolean(True)
else:
self['poster'].show()
self['pig_mode'].setBoolean(False)
def paintPosterPixmapCB(self, picInfo = None):
ptr = self.picload.getData()
if ptr != None:
self['poster'].instance.setPixmap(ptr)
self['poster'].show()
return
def __streamStarted(self):
print '__streamStarted'
if self.state != self.STATE_PAUSED:
self.setState(self.STATE_PLAYING)
def __serviceStarted(self):
print '__streamStarted'
self.setState(self.STATE_CONNECTING)
def __streamFailed(self):
print '__streamFailed'
currPlay = self.session.nav.getCurrentService()
message = currPlay.info().getInfoString(iServiceInformation. sUser + 12)
self.setState(self.STATE_FAILURE)
self['connection_label'].setText(_('Streaming error: %s') % message)
def __evEOF(self):
print '__evEOF'
if self.state != self.STATE_FAILURE:
self.setState(self.STATE_DISCONNECTED)
def keyPass(self):
print 'keyPass'
def keyOK(self):
if self.state in (self.STATE_DISCONNECTED, self.STATE_FAILURE):
self.start()
elif self.state == self.STATE_PAUSED:
self.playpauseService()
def keyYellow(self):
if self.state in (self.STATE_PLAYING, self.STATE_PAUSED):
self.playpauseService()
def togglePIG(self, fullscreen = False):
if fullscreen == True:
self.hide()
else:
self.show()
self['pig_mode'].setBoolean(not fullscreen)
def keyBlue(self):
if self['pig_mode'].getBoolean() == True:
self.togglePIG(True)
else:
self.togglePIG(fullscreen=False)
def playpauseService(self):
if self.seekstate == self.SEEK_STATE_PLAY:
self.setState(self.STATE_PAUSED)
self.pauseService()
elif self.seekstate == self.SEEK_STATE_PAUSE:
self.setState(self.STATE_PLAYING)
self.unPauseService()
def checkSkipShowHideLock(self):
pass
def start(self):
if self.url != ' ':
url = self.url
name = self.name
self.session.nav.stopService()
sref = eServiceReference(4097, 0, url)
sref.setName(name)
print 'sref =', sref.toString()
self.session.open(MoviePlayer, sref)
def disconnect(self):
self.session.nav.stopService()
self.setState(self.STATE_DISCONNECTED)
def __onClose(self):
self.session.nav.playService(self.old_service, forceRestart=True)
def exit(self):
self.close()
def geturl(self):
if not fileExists('/tmp/vid'):
os.system('/usr/bin/mkfifo /tmp/vid')
local_file = '/tmp/vid'
self.url = 'murattvyardimcisi -v -r ' + self.url + " -o '" + local_file + "'"
def okClicked(self):
svfile = '/tmp/vid'
self.svf = svfile
JobManager.AddJob(downloadJob(self, self.url, svfile, 'Title 1'))
self.start()
def LastJobView(self):
currentjob = None
for job in JobManager.getPendingJobs():
currentjob = job
if currentjob is not None:
self.session.open(JobView, currentjob)
return
def start(self):
try:
print ' '
svfile = self.svf
pvd = Playvid(self.session, self.name, svfile)
pvd.start()
except:
return
def cancel(self):
self.session.nav.playService(self.srefOld)
self.close()
def stopdl(self):
svfile = self.svf
cmd = 'rm ' + svfile
os.system(cmd)
self.session.nav.playService(self.srefOld)
cmd1 = 'killall -9 murattvyardimcisi'
cmd2 = 'killall -9 wget'
os.system(cmd1)
os.system(cmd2)
self.close()
def keyLeft(self):
self['text'].left()
def keyRight(self):
self['text'].right()
def keyNumberGlobal(self, number):
print 'pressed', number
self['text'].number(number)
class Playvid(Screen):
def __init__(self, session, name, url):
self.skin = MuratTV.skin
Screen.__init__(self, session)
self['list'] = MenuList([])
self['info'] = Label()
self['setupActions'] = ActionMap(['SetupActions', 'ColorActions', 'TimerEditActions'], {'cancel': self.cancel,
'ok': self.okClicked}, -2)
self.icount = 0
print 'Playvid : name =', name
print 'Playvid : url =', url
self.name = name
self.url = url
self.srefOld = self.session.nav.getCurrentlyPlayingServiceReferen ce()
self.onLayoutFinish.append(self.start)
def start(self):
if self.url != ' ':
url = self.url
name = self.name
self.session.nav.stopService()
sref = eServiceReference(4097, 0, url)
sref.setName(name)
print 'sref =', sref.toString()
self.session.open(MoviePlayer, sref)
else:
return
def cancel(self):
self.session.nav.playService(self.srefOld)
self.close()
def okClicked(self):
pass
def keyLeft(self):
self['text'].left()
def keyRight(self):
self['text'].right()
def keyNumberGlobal(self, number):
print 'pressed', number
self['text'].number(number)
class downloadJob(Job):
def __init__(self, toolbox, cmdline, filename, filetitle):
Job.__init__(self, _('Saving Video'))
self.toolbox = toolbox
self.retrycount = 0
downloadTask(self, cmdline, filename, filetitle)
def retry(self):
self.retrycount += 1
self.restart()
class downloadJob(Job):
def __init__(self, toolbox, cmdline, filename, filetitle):
Job.__init__(self, _('Saving Video'))
self.toolbox = toolbox
self.retrycount = 0
downloadTask(self, cmdline, filename, filetitle)
def retry(self):
self.retrycount += 1
self.restart()
class downloadTask(Task):
ERROR_CORRUPT_FILE, ERROR_RTMP_ReadPacket, ERROR_SEGFAULT, ERROR_SERVER, ERROR_UNKNOWN = range(5)
def __init__(self, job, cmdline, filename, filetitle):
Task.__init__(self, job, filetitle)
self.postconditions.append(downloadTaskPostconditi on())
self.setCmdline(cmdline)
self.filename = filename
self.toolbox = job.toolbox
self.error = None
self.lasterrormsg = None
return
def processOutput(self, data):
try:
if data.endswith('%)'):
startpos = data.rfind('sec (') + 5
if startpos and startpos != -1:
self.progress = int(float(data[startpos:-4]))
elif data.find('%') != -1:
tmpvalue = data[:data.find('%')]
tmpvalue = tmpvalue[tmpvalue.rfind(' '):].strip()
tmpvalue = tmpvalue[tmpvalue.rfind('(') + 1:].strip()
self.progress = int(float(tmpvalue))
else:
Task.processOutput(self, data)
except Exception as errormsg:
print 'Error processOutput: ' + str(errormsg)
Task.processOutput(self, data)
def processOutputLine(self, line):
self.error = self.ERROR_SERVER
def afterRun(self):
pass
class downloadTaskPostcondition(Condition):
RECOVERABLE = True
def check(self, task):
if task.returncode == 0 or task.error is None:
return True
else:
return False
return
def getErrorMessage(self, task):
return {task.ERROR_CORRUPT_FILE: _('Video Download Failed!Corrupted Download File:%s' % task.lasterrormsg),
task.ERROR_RTMP_ReadPacket: _('Video Download Failed!Could not read RTMP-Packet:%s' % task.lasterrormsg),
task.ERROR_SEGFAULT: _('Video Download Failed!Segmentation fault:%s' % task.lasterrormsg),
task.ERROR_SERVER: _('Download Failed!-Server error:%s' % task.lasterrormsg),
task.ERROR_SERVER: _('Download Failed!-Server error:'),
task.ERROR_UNKNOWN: _('Video Download Failed!Unknown Error:%s' % task.lasterrormsg)}[task.error]
def main(session, **kwargs):
if not fileExists('/usr/lib/enigma2/python/Plugins/Extensions/MuratTV/murattvyardimcisi'):
os.system('cp /usr/lib/enigma2/python/Plugins/Extensions/MuratTV/murattvyardimcisi/usr/lib/enigma2/python/Plugins/Extensions/MuratTV/&& chmod 755 /usr/lib/enigma2/python/Plugins/Extensions/
MuratTV/murattvyardimcisi')
session.open(MuratTV)
def menu(menuid, **kwargs):
if menuid == 'mainmenu':
return [(_('MuratTV V3'),
main,
'MuratTV V3',
45)]
return []
from Plugins.Plugin import PluginDescriptor
def Plugins(**kwargs):
return [PluginDescriptor(name='
MuratTV V3', description=_('Play back media url'), where=PluginDescriptor.WHERE_MENU, needsRestart=False, icon='icons/iptvlogo.png', fnc=menu), PluginDescriptor(name='
MuratTV V3', where=PluginDescriptor.WHERE_FILESCAN, needsRestart=False, fnc=menu)
Paylaş