Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import webbrowser
- import os
- import time
- import random
- class Website:
- # Website class acts as a sort of a config, so that maybe
- # updating the version of the tubeplayer on a different system
- # would be easier. Basically, I don't see how Website class
- # would change in the future but it's certain that the Tubeplayer
- # class will.
- def __init__(self, data, automate=True):
- self.data = data
- if automate:
- self.construct()
- self.open()
- def construct(self):
- file = open("tmphtml.html","w").write(self.data)
- def open(self):
- webbrowser.get().open("file://"+os.path.abspath("tmphtml.html"))
- def tubetime(tubetime):
- blanks = time.mktime((2000, 1, 1, 0, 0, 0, 0, 1, -1))
- if len(tubetime.split(":")) == 1:
- conv = time.strptime("2000:"+tubetime, "%Y:%S")
- elif len(tubetime.split(":")) == 2:
- conv = time.strptime("2000:"+tubetime, "%Y:%M:%S")
- elif len(tubetime.split(":")) == 3:
- conv = time.strptime("2000:"+tubetime, "%Y:%H:%M:%S")
- return time.mktime(conv)-blanks
- print(tubetime("36"))
- print(tubetime("2:36"))
- print(tubetime("11:2:36"))
- # key: video id, value: [volume, playback rate, seek to seconds]
- class Tubeplayer:
- def __init__(self, videos={"ClDmutiXnBo": [38,1,0],"67QtXZsA2ME": [20,1,0], "BIRJMESl4U8": [60,1,0], "Ag6y6jz7bQQ": [100,1,0]}):
- a = videos
- website = """
- <!DOCTYPE html>
- <html>
- <body>
- <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->"""
- for video_id in a.keys():
- website += """
- <div id="player{video_id}"></div>""".format(video_id=video_id)
- website +="""
- <script>
- // 2. This code loads the IFrame Player API code asynchronously.
- var tag = document.createElement('script');
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);"""
- for video_id in a.keys():
- website += """
- var player{video_id};""".format(video_id=video_id)
- website +="""
- function onYouTubeIframeAPIReady() {"""
- for video_id in a.keys():
- actual_id = video_id
- if video_id.startswith("_"):
- actual_id = video_id[3:]
- website += """
- player{video_id} = new YT.Player('player{video_id}', {{
- height: '390',
- width: '640',
- videoId: '{actual_id}',
- events: {{
- 'onReady': onPlayerReady{video_id},
- }}
- }});""".format(video_id=video_id, actual_id=actual_id)
- website +="""
- }"""
- for video_id, config in a.items():
- website += """
- // 4. The API will call this function when the video player is ready.
- function onPlayerReady{video_id}(event) {{
- event.target.playVideo();
- event.target.setVolume({config[0]});
- event.target.setPlaybackRate({config[1]});
- event.target.seekTo({config[2]}, true);
- event.target.setLoop(true);
- }}""".format(video_id=video_id, config=config)
- website +="""
- function stopVideo() {
- player.stopVideo();
- }
- </script>
- </body>
- </html>"""
- Website(website)
- if __name__ == "__main__":
- veganchill = {"Deg7wrqa2fE": [67,1,0], "BwvzdxI45x8": [100,1,0]}
- jungle = {"ClDmutiXnBo": [38,1,0],"67QtXZsA2ME": [20,1,0], "BIRJMESl4U8": [60,1,0], "Ag6y6jz7bQQ": [100,1,0]}
- cri_du_chat = {"0K78eRSqDkk": [100,0.5,0],"_0_0K78eRSqDkk":[100,0.75,0],"_1_0K78eRSqDkk":[100,1,0],"La1D4cNQ5kQ": [45,1,0]}
- bells = {}
- for x in range(8):
- 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))]
- Tubeplayer(bells)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement