def clean_playlist(playlist_name):
    playlist_id = create_playlist(sp, playlist_name, '')
    results = sp.playlist_tracks(playlist_id)
    playlist_tracks = []
    for result in results['items']:
        playlist_tracks.append(result['track'])
    while results['next']:
        results = sp.next(results)
        for result in results['items']:
            playlist_tracks.append(result['track'])

    remove_tracks = []
    for track in playlist_tracks:
        id = track['id']
        keys = create_key(track)
        # In case song has same name but extra artist for remix.
        should_remove = True
        for key in keys:
            if not key_in_history(key):
                should_remove = False
                break
        if should_remove:
            remove_tracks.append(id)
    remove_tracks_from_playlist(remove_tracks, playlist_name)
    remove_duplicates_in_playlist(playlist_name)
Exemplo n.º 2
0
def remove_duplicate_tracks(track_ids):
    time.sleep(PAUSE_TIME)
    response = sp.playlist_tracks(playlist_id)
    playlist_keys = []
    new_list = []
    for t in response['items']:
        playlist_keys.extend(create_key(t['track']))
    for id in track_ids:
        time.sleep(PAUSE_TIME)
        keys = create_key(sp.track(id))
        in_playlist = False
        for key in keys:
            if key in playlist_keys:
                in_playlist = True
        if not in_playlist:
            new_list.append(id)
    return new_list
Exemplo n.º 3
0
def add_to_cvs(track):
    keys = create_key(track)
    for key in keys:
        if not key_in_history(key):
            with open('csv/history.csv', 'a', newline='') as csvfile:
                print('Added ' + key)
                fieldnames = ['id', 'key']
                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
                writer.writerow({'id': track['id'], 'key': key})
Exemplo n.º 4
0
def process(video, name, mail):
    try:

        video_file = cmn.ENCODE_DIR + '/' + video  # コマンドライン引数
        kid = cmn.create_kid(mail)
        key = cmn.create_key(mail)

        # kid = hashlib.md5(mail).hexdigest()
        # key = hashlib.md5(mail + 'CAFEBABE').hexdigest()
        # name = args[2].decode('UTF-8')  # コマンドライン引数から受け取る
        # mail = args[3].decode('UTF-8')  # コマンドライン引数から受け取る

        output_dir = cmn.PACKAGE_DIR

        print '------------------------------------------'
        print 'package.pyが取得した情報'
        print 'video:%s' % video_file
        print 'output_dir:%s' % output_dir
        print 'name:%s' % name
        print 'mail:%s' % mail
        print 'kid:%s' % kid
        print 'key:%s' % key

        # 出力先を作成
        if not os.path.exists(output_dir):
            cmd = 'mkdir -p %s' % output_dir
            commands.status(cmd)

        # ウォーターマーク文字列を作成
        watermark = '%s(%s)' % (name.decode('utf-8'), mail)

        # パッケージ化
        watermark_file = create_watermark(watermark, output_dir, kid)
        watermarked_video = put_watermark(video_file, output_dir,
                                          watermark_file, kid)
        fragmented_video = fragment_video(watermarked_video, output_dir, kid)
        converted_video_output = convert_mpegdash(fragmented_video,
                                                  output_dir,
                                                  kid,
                                                  key,
                                                  is_encrypt=True)
        archived_video = archive_video(converted_video_output, output_dir,
                                       video_file, kid)
        cleanup(output_dir, watermark_file, watermarked_video,
                fragmented_video, converted_video_output)

    except Exception as e:
        print e
        print traceback.format_exc()
def add_to_cvs(track):
    if not in_history(track['id']):
        with open('played_history.csv', 'a', newline='') as csvfile:
            print('Added ' + track['name'])
            fieldnames = ['id', 'name', 'uri']
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writerow({
                'id': track['id'],
                'name': track['name'],
                'uri': track['uri']
            })
    keys = create_key(track)
    for key in keys:
        if not key_in_history(key):
            with open(HISTORY_DIRECTORY, 'a', newline='') as csvfile:
                print('Added ' + key)
                fieldnames = ['id', 'key']
                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
                writer.writerow({'id': track['id'], 'key': key})