Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. import sys
  2. import xbmc,xbmcaddon,xbmcvfs
  3. import sqlite3
  4. from subprocess import Popen
  5. import datetime,time
  6. # from vpnapi import VPNAPI
  7.  
  8. channel = sys.argv[1]
  9. start = sys.argv[2]
  10.  
  11. ADDON = xbmcaddon.Addon(id='script.tvguide.fullscreen')
  12.  
  13. def adapt_datetime(ts):
  14. # http://docs.python.org/2/library/sqlite3.html#registering-an-adapter-callable
  15. return time.mktime(ts.timetuple())
  16.  
  17. def convert_datetime(ts):
  18. try:
  19. return datetime.datetime.fromtimestamp(float(ts))
  20. except ValueError:
  21. return None
  22.  
  23. sqlite3.register_adapter(datetime.datetime, adapt_datetime)
  24. sqlite3.register_converter('timestamp', convert_datetime)
  25. path = xbmc.translatePath('special://profile/addon_data/script.tvguide.fullscreen/source.db')
  26. try:
  27. conn = sqlite3.connect(path, detect_types=sqlite3.PARSE_DECLTYPES)
  28. conn.row_factory = sqlite3.Row
  29. except Exception as detail:
  30. xbmc.log("EXCEPTION: (script.tvguide.fullscreen) %s" % detail, xbmc.LOGERROR)
  31.  
  32. # Get the Program Info from the database
  33. c = conn.cursor()
  34. startDate = datetime.datetime.fromtimestamp(float(start))
  35. c.execute('SELECT DISTINCT * FROM programs WHERE channel=? AND start_date = ?', [channel,startDate])
  36. for row in c:
  37. title = row["title"]
  38. endDate = row["end_date"]
  39. duration = endDate - startDate
  40. before = int(ADDON.getSetting('autoplaywiths.before'))
  41. after = int(ADDON.getSetting('autoplaywiths.after'))
  42. extra = (before + after) * 60
  43. #TODO start from now
  44. seconds = duration.seconds + extra
  45. if seconds > (3600*4):
  46. seconds = 3600*4
  47. break
  48.  
  49. # Find the channel's stream url
  50. c.execute('SELECT stream_url FROM custom_stream_url WHERE channel=?', [channel])
  51. row = c.fetchone()
  52. url = ""
  53. if row:
  54. url = row[0]
  55. if not url:
  56. quit()
  57. # Uncomment this if you want to use VPN Mgr filtering. Need to import VPNAPI.py
  58. # else:
  59. # if ADDON.getSetting('vpnmgr.connect') == "true":
  60. # vpndefault = False
  61. # if ADDON.getSetting('vpnmgr.default') == "true":
  62. # vpndefault = True
  63. # api = VPNAPI()
  64. # if url[0:9] == 'plugin://':
  65. # api.filterAndSwitch(url, 0, vpndefault, True)
  66. # else:
  67. # if vpndefault: api.defaultVPN(True)
  68.  
  69. # Find the actual url used to play the stream
  70. #core = "dummy"
  71. #xbmc.executebuiltin('PlayWith(%s)' % core)
  72. player = xbmc.Player()
  73. player.play(url)
  74. count = 30
  75. url = ""
  76. while count:
  77. count = count - 1
  78. time.sleep(1)
  79. if player.isPlaying():
  80. url = player.getPlayingFile()
  81. break
  82. player.stop()
  83.  
  84. # Play with your own preferred player and paths
  85. if url:
  86. name = "%s = %s = %s" % (start,channel,title)
  87. name = name.encode("cp1252")
  88. #filename = xbmc.translatePath("special://temp/%s.ts" % name)
  89.  
  90. filename = "g:\dvr\%s.ts" % name # << THIS IS MY DOWNLOAD DIRECTORY
  91.  
  92. ffmpeg = r"c:\ffmpeg\bin\ffmpeg.exe" # << THIS IS LOCATION OF MY FFMPEG.EXE
  93.  
  94. cmd = [ffmpeg, "-y", "-i", url, "-c", "copy", "-t", str(seconds), filename]
  95. #p = Popen(cmd,shell=True)
  96. p = Popen(cmd,shell=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement