コード例 #1
0
        public override async Task <bool> MoveSong(PlaylistSong song, string previousId, string nextId, int index)
        {
            try
            {
                var body = new Google.Apis.Youtube.v3.Data.PlaylistItem
                {
                    Snippet = new PlaylistItemSnippet
                    {
                        PlaylistId = song.PlaylistId,
                        ResourceId = new ResourceId
                        {
                            Kind    = "youtube#video",
                            VideoId = song.SongId,
                        },
                        Position = index,
                    },
                    Id = song.Id
                };
                var resp = await Api.Put <Google.Apis.Youtube.v3.Data.PlaylistItem>(body, "playlistItems?part=snippet");

                SyncPlaylists();
                return(resp.Snippet.Position == index);
            }
            catch (Exception ex)
            {
                LogManager.Shared.Report(ex);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> AddToPlaylist(Track song, Playlist playlist, string notes = "")
        {
            try{
                if (string.IsNullOrWhiteSpace(playlist.Id))
                {
                    playlist.ServiceType = ServiceType;
                    await CreatePlaylist(playlist);
                }
                var content = !string.IsNullOrWhiteSpace(notes) ? new PlaylistItemContentDetails
                {
                    Note = notes
                } : null;
                var body = new Google.Apis.Youtube.v3.Data.PlaylistItem {
                    Snippet = new PlaylistItemSnippet {
                        PlaylistId = playlist.Id,
                        ResourceId = new ResourceId {
                            Kind    = "youtube#video",
                            VideoId = song.Id,
                        }
                    },
                    ContentDetails = content
                };
                var resp = await Api.Post <Google.Apis.Youtube.v3.Data.PlaylistItem> (body, "playlistItems?part=id%2CcontentDetails%2Csnippet");

                if (string.IsNullOrWhiteSpace(body.Id))
                {
                    return(false);
                }
                var id   = body.ContentDetails.VideoId;
                var note = GetNotes(body.ContentDetails?.Note) ?? new Notes
                {
                    Title = body.Snippet.Title,
                };
                var t = new FullPlaylistTrackData(note.Title, note.Artist, note.AlbumArtist, note.Album, note.Genre)
                {
                    AlbumArtwork = new List <AlbumArtwork> {
                        new AlbumArtwork {
                            Url = string.Format("http://img.youtube.com/vi/{0}/0.jpg", id)
                        }
                    },
                    MediaType       = MediaType.Video,
                    ServiceId       = Id,
                    Id              = id,
                    ServiceType     = ServiceType,
                    FileExtension   = "mp4",
                    TrackId         = id,
                    PlaylistId      = playlist.Id,
                    PlaylistEntryId = body.Id,
                    SOrder          = body.Snippet.Position ?? 1000,
                    Disc            = note.Disc,
                    Year            = note.Year,
                    Track           = note.Track,
                };
                await ProcessPlaylistTracks(new List <FullPlaylistTrackData> {
                    t
                }, new List <TempPlaylistEntry>());
                await FinalizePlaylists(Id);

                return(true);
            }
            catch (Exception ex) {
                LogManager.Shared.Report(ex);
                return(false);
            }
        }