PageRenderTime 33ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/myTV/resources/datasource/de_TVInfo.py

http://xbmc-scripting.googlecode.com/
Python | 149 lines | 111 code | 12 blank | 26 comment | 10 complexity | 201d6bf1a7005b6b62d2f9af193e3ff2 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. ############################################################################################################
  2. # TV Data source: German
  3. #
  4. # Notes:
  5. # From www.tvinfo.de (using their older web pages - http://www.tvinfo.de/exe.php3)
  6. #
  7. #
  8. # CHANGELOG
  9. # ---------
  10. # 26/08/06 Created.
  11. ############################################################################################################
  12. from mytvLib import *
  13. import xbmcgui, re, time
  14. from string import split, replace, find, rfind, atoi, zfill
  15. from os import path
  16. class ListingData:
  17. def __init__(self, cache):
  18. debug("ListingData.__init__")
  19. self.cache = cache
  20. self.name = os.path.splitext(os.path.basename( __file__))[0] # get filename without path & ext
  21. self.BASE_URL = "http://www.tvinfo.de/"
  22. self.CHANNELS_URL= self.BASE_URL + "my.php3?target=abfrage_sender"
  23. # $DAY and $MONTH tobe zero filled, YEAR YYYY
  24. self.CHANNEL_URL = self.BASE_URL + "exe.php3?target=senderlist.inc&h=0&min=00&newD=$DAY&newM=$MONTH&newY=$YEAR&showSenderID=$CHID"
  25. self.CHANNELS_FN = os.path.join(cache,"Channels_"+ self.name + ".dat")
  26. def getName(self):
  27. return self.name
  28. # download or load if exists, a list of all available channels.
  29. # return: list [chID, chName]
  30. def getChannels(self):
  31. debug("ListingData.getChannels()")
  32. startStr = 'Senderauswahl konfigurieren'
  33. endStr = 'type="submit"'
  34. regex = 'name="s\[(.*?)\]".*?>(.*?)<'
  35. return getChannelsLIB(self.CHANNELS_URL, self.CHANNELS_FN , regex, startStr, endStr)
  36. # download channel data, using either dayDelta or dataDate.
  37. # filename = filename to save downloaded data file as.
  38. # chID = unique channel ID, used to reference channel in URL.
  39. # chName = display name of channel
  40. # dayDelta = day offset from today. ie 0 is today, 1 is tomorrow ...
  41. # fileDate = use to calc programme start time in secs since epoch.
  42. # return Channel class or -1 if http fetch error, or None for other
  43. #
  44. def getChannel(self, filename, chID, chName, dayDelta, fileDate):
  45. debug("ListingData.getChannel() dayDelta: %s chID=%s fileDate=%s" % (dayDelta,chID,fileDate))
  46. progList = []
  47. lastStartTime = 0
  48. # download data file if file doesnt exists
  49. dataFilename = os.path.join(self.cache, "%s_%s.html" % (chID, fileDate))
  50. if not fileExist(dataFilename):
  51. year = fileDate[:4]
  52. month = fileDate[2:4]
  53. day = str(int(fileDate[-2:]) +1) # +1 to day. 31st Aug is 32 08
  54. url = self.CHANNEL_URL.replace('$CHID',chID).replace('$DAY',day).replace('$MONTH',month).replace('$YEAR',year)
  55. doc = fetchURL(url, dataFilename)
  56. else:
  57. doc = readFile(dataFilename)
  58. # check for timout, exception error, or empty page
  59. if not doc:
  60. return doc
  61. doc = doc.decode('latin-1','replace')
  62. debug("process data ...")
  63. # HH:MM, data - which may/not contain href and name
  64. #regex = "(\d+:\d+).*?href=(exe.php3.*?)>(.*?)</a>(.*?)</td"
  65. regex = "(\d+:\d+).*?href=(exe.php3.*?)>(.*?)</a>(.*?)</td.*?spalte.*?>(.*?)</td" # w/genre
  66. matches = parseDocList(doc, regex, 'output starts')
  67. if matches:
  68. for match in matches:
  69. startTime = match[0]
  70. link = match[1]
  71. title = cleanHTML(decodeEntities(unicodeToAscii(match[2])))
  72. desc = cleanHTML(unicodeToAscii(decodeEntities(match[3])))
  73. genre = cleanHTML(decodeEntities(unicodeToAscii(match[4])))
  74. if not startTime or not title:
  75. continue
  76. if link:
  77. descLink = self.BASE_URL + link
  78. else:
  79. descLink = ''
  80. if genre:
  81. genre = self.translateGenre(genre)
  82. # convert starttime to secs since epoch
  83. secsEpoch = startTimeToSecs(lastStartTime, startTime, fileDate)
  84. lastStartTime = secsEpoch
  85. progList.append( {
  86. TVData.PROG_STARTTIME : float(secsEpoch),
  87. TVData.PROG_ENDTIME : 0,
  88. TVData.PROG_TITLE : title,
  89. TVData.PROG_DESC : desc,
  90. TVData.PROG_SUBTITLE : desc,
  91. TVData.PROG_DESCLINK : descLink,
  92. TVData.PROG_GENRE : genre
  93. } )
  94. if DEBUG:
  95. print progList[-1]
  96. progList = setChannelEndTimes(progList) # update endtimes
  97. return progList
  98. #
  99. # Download url and regex parse it to extract description.
  100. #
  101. def getLink(self, link, title=""):
  102. debug("ListingData.getLink()")
  103. desc = getDescriptionLink(link, 'END PARTNER PROGRAM -->(.*?)</table') # main desc
  104. if not desc:
  105. desc = getDescriptionLink(link, 'HL1">(.*?)</td') # title short desc
  106. return desc
  107. # translate into english genre filenames
  108. def translateGenre(self, genre):
  109. # 'find' is to better identify the subgenre eg. 'Show/Musik'
  110. # startswith identify main genre
  111. if find(genre, "Musik") != -1:
  112. genre = 'Music'
  113. elif find(genre, "Soap") != -1:
  114. genre = 'Soap'
  115. elif genre.startswith('Sport'):
  116. genre = 'Sport'
  117. elif genre.startswith('Magazin'):
  118. genre = 'Magazine'
  119. elif genre.startswith('Serie'):
  120. genre = 'Series'
  121. elif genre.startswith('Spielfilm'):
  122. genre = 'Film'
  123. elif genre.startswith('Kinder'):
  124. genre = 'Children'
  125. elif genre.startswith('Dokumentation'):
  126. genre = 'Documentary'
  127. elif genre.startswith('Erotik'):
  128. genre = 'Adult'
  129. elif genre.startswith('Show'):
  130. genre = 'Drama'
  131. return genre