def run(self):
        # Disable Sikuli action and info log
        com = common.General()
        com.infolog_enable(False)
        com.set_mouse_delay(0)

        # Prepare
        app = youtube.Youtube()
        sample1_file_path = os.path.join(self.INPUT_IMG_SAMPLE_DIR_PATH,
                                         self.INPUT_IMG_OUTPUT_SAMPLE_1_NAME)
        sample1_file_path = sample1_file_path.replace(
            os.path.splitext(sample1_file_path)[1], '.png')
        capture_width = int(self.INPUT_RECORD_WIDTH)
        capture_height = int(self.INPUT_RECORD_HEIGHT)

        # Launch browser
        my_browser = browser.Chrome()

        # Access link and wait
        my_browser.clickBar()
        my_browser.enterLink(self.INPUT_TEST_TARGET)
        app.wait_for_loaded()

        # Wait for stable
        sleep(2)

        # PRE ACTIONS
        app.click_search_field()
        sleep(1)

        # Customized Region
        customized_region_name = 'end'
        type_area_component = [
            ['search_bar_win.png', 0, 0],
        ]
        type_area = self.find_match_region(type_area_component)
        self.set_override_region_settings(customized_region_name, type_area)

        # Record T1, and capture the snapshot image
        # Input Latency Action
        screenshot, t1 = app.il_type('y', capture_width, capture_height)

        # In normal condition, a should appear within 100ms,
        # but if lag happened, that could lead the show up after 100 ms,
        # and that will cause the calculation of AIL much smaller than expected.
        sleep(0.1)

        # Record T2
        t2 = time.time()

        # POST ACTIONS

        # Write timestamp
        com.updateJson({'t1': t1, 't2': t2}, self.INPUT_TIMESTAMP_FILE_PATH)

        # Write the snapshot image
        shutil.move(screenshot, sample1_file_path)
Ejemplo n.º 2
0
def main():
    metadata_path = config.metadata
    if not os.path.isfile(metadata_path):
        with open(metadata_path, "w") as lockfile:
            json.dump([], lockfile)

    if not os.path.isdir(config.savepath):
        os.mkdir(config.savepath)
    bt = bittorrent.Bittorrent(config.savepath)
    yt = youtube.Youtube(config.savepath)
    with open(config.input, "r") as input_file:
        for line in input_file:
            name = line.strip()
            if name.startswith("magnet:"):
                if not metadata_exists(name, metadata_path):
                    add_metadata(bt.generate_metadata(name), metadata_path)
                if config.do_download:
                    bt.download(name)
            elif name.startswith("https://www.youtube"):
                if not metadata_exists(name, metadata_path):
                    add_metadata(yt.generate_metadata(name), metadata_path)
                if config.do_download:
                    yt.download(name)
Ejemplo n.º 3
0
    def __init__(self, bot):
        self.dictionary = {}
        self.bot = bot
        self.log = logging_manager.LoggingManager()
        self.spotify = spotify.Spotify()
        self.youtube = youtube.Youtube()
        self.lastfm = lastfm.LastFM()
        self.mongo = mongo.Mongo()
        bot.remove_command("help")
        self.log.debug("[Startup]: Initializing Music Module . . .")

        def generate_key(length):
            letters = string.ascii_letters
            response = ""
            for a in range(0, length):
                response += random.choice(letters)
            return response

        restart_key = generate_key(64)
        asyncio.run_coroutine_threadsafe(self.mongo.set_restart_key(restart_key), self.bot.loop)

        if not discord.opus.is_loaded():
            discord.opus.load_opus("/usr/lib/libopus.so")
def test_videoUrl():
    """Tests retrieval of URL
    """
    url = y.Youtube("QkzCi5mHvkc").videoUrl(5)
    print url
    assert url.startswith("http://"), "URL didn't start with http://"
def test_getPageTitle():
    """Tests retrieval of page title
    """
    title = y.Youtube("QkzCi5mHvkc").title()
    assertEqual(title, "65daysofstatic - radio protector")
def test_getPageToken():
    """Tests pageToken method returns sensible string
    """
    token = y.Youtube("QkzCi5mHvkc").pageToken()
    assert isinstance(token, basestring)
    assert len(token) > 0, "Token was zero length"
Ejemplo n.º 7
0
import argparse
import imutils
import cv2
import pytesseract
import os
import youtube
from imutils import contours
from extract import get_ROI, get_string

ap = argparse.ArgumentParser()
ap.add_argument("-k", "--key", required=True, help="api key")
ap.add_argument("-c", "--channel", required=True, help="channel youtube")
args = vars(ap.parse_args())

if __name__ == "__main__":
    yt = youtube.Youtube(args["key"])
    id_video = yt.get_last_video(args["channel"])
    yt.extract_frames(id_video)
    frames = os.listdir(id_video)
    for frame in frames:
        path = os.path.join(id_video, frame)
        img = cv2.imread(path)
        img = imutils.resize(img, width=500)
        locs = get_ROI(img)
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        for (i, (gX, gY, gW, gH)) in enumerate(locs):
            group = gray[gY - 5:gY + gH + 5, gX - 5:gX + gW + 50]
            try:
                code = get_string(group)
                if len(code) >= 13 and len(code) <= 15:
                    print(frame, "=>", get_string(group))
import os
import spotify
import youtube

spotify_oauth_token = os.environ.get("SPOTIFY_OAUTH_TOKEN")
spotify_user_id = os.environ.get("SPOTIFY_USER_ID")

if __name__ == "__main__":
    # intializing an instance of the youtube and spotify classes
    yt = youtube.Youtube()
    spotify = spotify.Spotify(spotify_user_id, spotify_oauth_token)

    yt_playlist_id = yt.get_playlist_id("Spotify")
    unfiltered_song_list = yt.get_song_list(yt_playlist_id)
    spotify_playlist_id = spotify.create_playlist("From Youtube")
    filtered_songs = spotify.filter_titles(unfiltered_song_list)
    # adding each song to the playlist
    for song in filtered_songs:
        track_uri = spotify.get_spotify_song_uri(song)
        # if a search result came back from the spotify API
        if track_uri != None:
            spotify.add_song_to_playlist(spotify_playlist_id, track_uri)
            print("Added {song} to the playlist".format(song=song))
Ejemplo n.º 9
0
import youtube
import media
import fresh_tomatoes

list = youtube.Youtube()
list.search = "movie trailer"  # What is interesting topic? 'funny pet'? 'cute kitten'? 'Udacity'?
list.load()

movies = []
youtube_prefix = 'https://www.youtube.com/watch?v='
# Mapping youtube API response to our movie array
for item in list.data['items']:
    title = item['snippet']['title']
    storyline = item['snippet']['description']
    video = youtube_prefix + item['id']['videoId']
    poster_image_url = item['snippet']['thumbnails']['high']['url']
    movies.append(media.Movie(title, storyline, poster_image_url, video))

# Rendering page
fresh_tomatoes.open_movies_page(movies)
Ejemplo n.º 10
0
 def __init__(self):
     self.admin = admin.Admin()
     self.auth = auth
     self.api = api.Api()
     self.youtube = youtube.Youtube()