Форматирование примеров
このコミットが含まれているのは:
コミット
525988d37d
|
@ -3,38 +3,40 @@ import datetime
|
|||
from yandex_music.client import Client
|
||||
|
||||
# Help text
|
||||
if(len(sys.argv) == 1 or len(sys.argv) > 3):
|
||||
if len(sys.argv) == 1 or len(sys.argv) > 3:
|
||||
print('Usage: DailyPlaylistUpdater.py token')
|
||||
print('token - Authentication token');
|
||||
print('token - Authentication token')
|
||||
print('\nUsage: DailyPlaylistUpdater.py username password')
|
||||
print('username - username in format \'example@yandex.ru\'');
|
||||
print('password - your password');
|
||||
print('username - username in format \'example@yandex.ru\'')
|
||||
print('password - your password')
|
||||
quit()
|
||||
# Authorization
|
||||
elif(len(sys.argv) == 2):
|
||||
client = Client.fromToken(sys.argv[1]);
|
||||
elif(len(sys.argv) == 3):
|
||||
client = Client .fromCredentials(sys.argv[1], sys.argv[2])
|
||||
elif len(sys.argv) == 2:
|
||||
client = Client.fromToken(sys.argv[1])
|
||||
elif len(sys.argv) == 3:
|
||||
client = Client.fromCredentials(sys.argv[1], sys.argv[2])
|
||||
|
||||
# Current daily playlist
|
||||
PersonalPlaylistBlocks = client.landing(blocks=['personalplaylists']).blocks[0];
|
||||
DailyPlaylist = next(x.data.data for x in PersonalPlaylistBlocks.entities if x.data.data.generated_playlist_type == 'playlistOfTheDay')
|
||||
PersonalPlaylistBlocks = client.landing(blocks=['personalplaylists']).blocks[0]
|
||||
DailyPlaylist = next(
|
||||
x.data.data for x in PersonalPlaylistBlocks.entities if x.data.data.generated_playlist_type == 'playlistOfTheDay'
|
||||
)
|
||||
|
||||
# Check if we don't need to update it
|
||||
if(DailyPlaylist.play_counter.updated):
|
||||
if DailyPlaylist.play_counter.updated:
|
||||
modifiedDate = datetime.datetime.strptime(DailyPlaylist.modified, "%Y-%m-%dT%H:%M:%S%z").date()
|
||||
if (datetime.datetime.now().date() == modifiedDate):
|
||||
if datetime.datetime.now().date() == modifiedDate:
|
||||
print('\x1b[6;30;43m' + 'Looks like it has been already updated today' + '\x1b[0m')
|
||||
quit()
|
||||
|
||||
# Updated playlist
|
||||
updatedPlaylist = client.users_playlists(user_id=DailyPlaylist.uid, kind=DailyPlaylist.kind)[0]
|
||||
|
||||
if(updatedPlaylist.play_counter.updated and not DailyPlaylist.play_counter.updated):
|
||||
if updatedPlaylist.play_counter.updated and not DailyPlaylist.play_counter.updated:
|
||||
print('\x1b[6;30;42m' + 'Success!' + '\x1b[0m')
|
||||
else:
|
||||
print('\x1b[6;30;41m' + 'Something has gone wrong and nothing updated' + '\x1b[0m')
|
||||
|
||||
# Debug information
|
||||
print('Before:\n modified: %s\n PlayCounter: %s' % (DailyPlaylist.modified, DailyPlaylist.play_counter))
|
||||
print('After:\n modified: %s\n PlayCounter: %s' % (updatedPlaylist.modified, updatedPlaylist.play_counter))
|
||||
print('After:\n modified: %s\n PlayCounter: %s' % (updatedPlaylist.modified, updatedPlaylist.play_counter))
|
||||
|
|
|
@ -15,29 +15,25 @@ MAX_ERRORS = 3
|
|||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('playlist', choices=('likes', 'user'), help='playlist type')
|
||||
parser.add_argument('--playlist-name',
|
||||
help='name of user playlist')
|
||||
parser.add_argument('--playlist-name', help='name of user playlist')
|
||||
|
||||
parser.add_argument('--skip', metavar='N', type=int,
|
||||
help='skip first %(metavar)s tracks')
|
||||
parser.add_argument('--shuffle', action='store_true',
|
||||
help='randomize tracks order')
|
||||
parser.add_argument('--token', default=DEFAULT_CACHE_FOLDER / CONFIG_NAME,
|
||||
help='YM API token as string or path to file')
|
||||
parser.add_argument('--no-save-token', action='store_true',
|
||||
help='do\'nt save token in cache folder')
|
||||
parser.add_argument('--cache-folder', type=Path, default=DEFAULT_CACHE_FOLDER,
|
||||
help='cached tracks folder')
|
||||
parser.add_argument('--audio-player', default='cvlc',
|
||||
help='player to use')
|
||||
parser.add_argument('--audio-player-args', action='append', default=[],
|
||||
help='args for --audio-player (can be specified multiple times)')
|
||||
parser.add_argument('--print-args', action='store_true',
|
||||
help='print arguments (including default values) and exit')
|
||||
parser.add_argument('--skip', metavar='N', type=int, help='skip first %(metavar)s tracks')
|
||||
parser.add_argument('--shuffle', action='store_true', help='randomize tracks order')
|
||||
parser.add_argument(
|
||||
'--token', default=DEFAULT_CACHE_FOLDER / CONFIG_NAME, help='YM API token as string or path to file'
|
||||
)
|
||||
parser.add_argument('--no-save-token', action='store_true', help='do\'nt save token in cache folder')
|
||||
parser.add_argument('--cache-folder', type=Path, default=DEFAULT_CACHE_FOLDER, help='cached tracks folder')
|
||||
parser.add_argument('--audio-player', default='cvlc', help='player to use')
|
||||
parser.add_argument(
|
||||
'--audio-player-args', action='append', default=[], help='args for --audio-player (can be specified multiple times)'
|
||||
)
|
||||
parser.add_argument('--print-args', action='store_true', help='print arguments (including default values) and exit')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.audio_player is parser.get_default('audio_player')\
|
||||
and args.audio_player_args is parser.get_default('audio_player_args'):
|
||||
if args.audio_player is parser.get_default('audio_player') and args.audio_player_args is parser.get_default(
|
||||
'audio_player_args'
|
||||
):
|
||||
args.audio_player_args = ['--play-and-exit', '--quiet']
|
||||
player_cmd: List[int] = args.audio_player_args
|
||||
player_cmd.insert(0, args.audio_player)
|
||||
|
@ -82,6 +78,7 @@ elif args.playlist == 'likes':
|
|||
|
||||
if args.shuffle:
|
||||
from random import shuffle
|
||||
|
||||
shuffle(tracks.tracks)
|
||||
|
||||
error_count = 0
|
||||
|
|
|
@ -54,9 +54,7 @@ class Radio:
|
|||
|
||||
def __send_start_radio(self, batch_id):
|
||||
self.client.rotor_station_feedback_radio_started(
|
||||
station=self.station_id,
|
||||
from_=self.station_from,
|
||||
batch_id=batch_id
|
||||
station=self.station_id, from_=self.station_from, batch_id=batch_id
|
||||
)
|
||||
|
||||
def __send_play_start_track(self, track, play_id):
|
||||
|
@ -68,15 +66,11 @@ class Radio:
|
|||
play_id=play_id,
|
||||
track_length_seconds=0,
|
||||
total_played_seconds=0,
|
||||
end_position_seconds=total_seconds
|
||||
end_position_seconds=total_seconds,
|
||||
)
|
||||
|
||||
def __send_play_start_radio(self, track, batch_id):
|
||||
self.client.rotor_station_feedback_track_started(
|
||||
station=self.station_id,
|
||||
track_id=track.id,
|
||||
batch_id=batch_id
|
||||
)
|
||||
self.client.rotor_station_feedback_track_started(station=self.station_id, track_id=track.id, batch_id=batch_id)
|
||||
|
||||
def __send_play_end_track(self, track, play_id):
|
||||
# played_seconds = 5.0
|
||||
|
@ -89,17 +83,13 @@ class Radio:
|
|||
play_id=play_id,
|
||||
track_length_seconds=int(total_seconds),
|
||||
total_played_seconds=played_seconds,
|
||||
end_position_seconds=total_seconds
|
||||
end_position_seconds=total_seconds,
|
||||
)
|
||||
|
||||
def __send_play_end_radio(self, track, batch_id):
|
||||
played_seconds = track.duration_ms / 1000
|
||||
self.client.rotor_station_feedback_track_finished(
|
||||
station=self.station_id,
|
||||
track_id=track.id,
|
||||
total_played_seconds=played_seconds,
|
||||
batch_id=batch_id
|
||||
|
||||
station=self.station_id, track_id=track.id, total_played_seconds=played_seconds, batch_id=batch_id
|
||||
)
|
||||
pass
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ type_to_name = {
|
|||
'video': 'видео',
|
||||
'user': 'пользователь',
|
||||
'podcast': 'подкаст',
|
||||
'podcast_episode': 'эпизод подкаста'
|
||||
'podcast_episode': 'эпизод подкаста',
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,9 +24,9 @@ def send_search_request_and_print_result(query):
|
|||
if search_result.best:
|
||||
type_ = search_result.best.type
|
||||
best = search_result.best.result
|
||||
|
||||
|
||||
text.append(f'❗️Лучший результат: {type_to_name.get(type_)}')
|
||||
|
||||
|
||||
if type_ in ['track', 'podcast_episode']:
|
||||
artists = ''
|
||||
if best.artists:
|
||||
|
|
読み込み中…
新しいイシューから参照