Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. import webbrowser
  2. import os
  3. import time
  4. import random
  5.  
  6. class Website:
  7. # Website class acts as a sort of a config, so that maybe
  8. # updating the version of the tubeplayer on a different system
  9. # would be easier. Basically, I don't see how Website class
  10. # would change in the future but it's certain that the Tubeplayer
  11. # class will.
  12. def __init__(self, data, automate=True):
  13. self.data = data
  14. if automate:
  15. self.construct()
  16. self.open()
  17. def construct(self):
  18. file = open("tmphtml.html","w").write(self.data)
  19.  
  20. def open(self):
  21. webbrowser.get().open("file://"+os.path.abspath("tmphtml.html"))
  22.  
  23.  
  24. def tubetime(tubetime):
  25. blanks = time.mktime((2000, 1, 1, 0, 0, 0, 0, 1, -1))
  26. if len(tubetime.split(":")) == 1:
  27. conv = time.strptime("2000:"+tubetime, "%Y:%S")
  28. elif len(tubetime.split(":")) == 2:
  29. conv = time.strptime("2000:"+tubetime, "%Y:%M:%S")
  30. elif len(tubetime.split(":")) == 3:
  31. conv = time.strptime("2000:"+tubetime, "%Y:%H:%M:%S")
  32. return time.mktime(conv)-blanks
  33.  
  34. print(tubetime("36"))
  35. print(tubetime("2:36"))
  36. print(tubetime("11:2:36"))
  37.  
  38. # key: video id, value: [volume, playback rate, seek to seconds]
  39. class Tubeplayer:
  40. def __init__(self, videos={"ClDmutiXnBo": [38,1,0],"67QtXZsA2ME": [20,1,0], "BIRJMESl4U8": [60,1,0], "Ag6y6jz7bQQ": [100,1,0]}):
  41. a = videos
  42.  
  43. website = """
  44. <!DOCTYPE html>
  45. <html>
  46. <body>
  47. <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->"""
  48. for video_id in a.keys():
  49. website += """
  50. <div id="player{video_id}"></div>""".format(video_id=video_id)
  51.  
  52. website +="""
  53. <script>
  54. // 2. This code loads the IFrame Player API code asynchronously.
  55. var tag = document.createElement('script');
  56.  
  57. tag.src = "https://www.youtube.com/iframe_api";
  58. var firstScriptTag = document.getElementsByTagName('script')[0];
  59. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);"""
  60.  
  61. for video_id in a.keys():
  62. website += """
  63. var player{video_id};""".format(video_id=video_id)
  64.  
  65. website +="""
  66. function onYouTubeIframeAPIReady() {"""
  67.  
  68. for video_id in a.keys():
  69. actual_id = video_id
  70. if video_id.startswith("_"):
  71. actual_id = video_id[3:]
  72. website += """
  73. player{video_id} = new YT.Player('player{video_id}', {{
  74. height: '390',
  75. width: '640',
  76. videoId: '{actual_id}',
  77. events: {{
  78. 'onReady': onPlayerReady{video_id},
  79. }}
  80. }});""".format(video_id=video_id, actual_id=actual_id)
  81.  
  82. website +="""
  83. }"""
  84.  
  85. for video_id, config in a.items():
  86. website += """
  87. // 4. The API will call this function when the video player is ready.
  88. function onPlayerReady{video_id}(event) {{
  89. event.target.playVideo();
  90. event.target.setVolume({config[0]});
  91. event.target.setPlaybackRate({config[1]});
  92. event.target.seekTo({config[2]}, true);
  93. event.target.setLoop(true);
  94. }}""".format(video_id=video_id, config=config)
  95.  
  96. website +="""
  97. function stopVideo() {
  98. player.stopVideo();
  99. }
  100. </script>
  101. </body>
  102. </html>"""
  103.  
  104. Website(website)
  105.  
  106.  
  107. if __name__ == "__main__":
  108. veganchill = {"Deg7wrqa2fE": [67,1,0], "BwvzdxI45x8": [100,1,0]}
  109. jungle = {"ClDmutiXnBo": [38,1,0],"67QtXZsA2ME": [20,1,0], "BIRJMESl4U8": [60,1,0], "Ag6y6jz7bQQ": [100,1,0]}
  110. cri_du_chat = {"0K78eRSqDkk": [100,0.5,0],"_0_0K78eRSqDkk":[100,0.75,0],"_1_0K78eRSqDkk":[100,1,0],"La1D4cNQ5kQ": [45,1,0]}
  111. bells = {}
  112. for x in range(8):
  113. bells["_%d_"%(x)+"Q5dU6serXkg"] = [50+random.randint(0,50),random.choice([0.5,0.75,1,1.5]),tubetime("15:%d"%random.randint(10,26))]
  114.  
  115. Tubeplayer(bells)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement