Exemplo n.º 1
0
    def check_videos():
        if len(config.api_key) == 0:
            print("[Error] API Key is empty. Exiting")
            exit()

        channels = se.query(channel).all()
        for c in channels:
            body = requests.get(
                "https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet,id&order=date&maxResults=10&type=video"
                .format(config.api_key, c.url))
            print("[Main] Checking " + c.name)
            videos = json.loads(body.text)['items']
            for i in range(0, len(videos) - 1):
                publish_time = videos[i]['snippet']['publishedAt']
                publish_time_timestamp = datetime.datetime.fromisoformat(
                    publish_time.replace("Z", "+00:00")).timestamp()
                setup_date = datetime.datetime.fromisoformat(
                    config.setup_time).timestamp()
                video_id = videos[i]['id']['videoId']
                # 2020-12-23-20-36-30
                if publish_time_timestamp > setup_date:
                    if se.query(task).filter(
                            task.id == video_id).first() is None:
                        print(
                            "[Monitor] A new video from {} is found, adding to the list. ID: {}"
                            .format(c.name, video_id))
                        task.add_task(id=video_id)
from youtube import downloader
from database import se, task

print("url: ")
url = input()
if url.find("youtube.com") == -1:
    print("not a youtube video link, stop running")
    exit()

id = url.replace("https://www.youtube.com/watch?v=", "")
if se.query(task).filter(task.id==id).first() is None:
    print("None")
    task.add_task(id=id)

downloader.download(url)