Spotify 한글 자막 알송연계 미니 프로그램 본문

프로그래밍/C#

Spotify 한글 자막 알송연계 미니 프로그램

알송서버가 주거서 기본소스 첨부합니다.

API는 SpotifyAPI 사용했습니다 NUGET에서 다운받아 사용해주세요

 

using Spotify_lyrics.spotify;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace Spotify_lyrics
{
    public class Spotify_Fm : Form
    {
        private Point FormLocation;

        private Spotify_Fm.POINT LastLocation = new Spotify_Fm.POINT();

        private Spotify_Fm.POINT CurrentLocation = new Spotify_Fm.POINT();

        private bool IsMouseMoveStart = false;

        private GetApi api;

        private string LastTitle = "";

        private int LocalTick = 0;

        private int ApiTick = 0;

        private bool isplaying;

        private List<Lyrics> Lyric = new List<Lyrics>();

        private int Sync = 300;

        private IContainer components = null;

        private PictureBox next;

        private PictureBox play;

        private PictureBox previous;

        private Timer Check_State;

        private PictureBox Close;

        private PictureBox Toolbox;

        private Label Artist;

        private Label Title;

        private Label DebugLabel;

        private PictureBox pause;

        private Label Title_y;

        private Label Artist_y;

        private Timer Label_Sliding;

        private PictureBox pictureBox1;

        private Label Lyrics1;

        private Label Lyrics2;

        private PictureBox signL;

        private PictureBox signR;

        private Label SyncLabel;

        public Spotify_Fm()
        {
            this.InitializeComponent();
            this.api = new GetApi();
            Console.WriteLine("winform시작");
            base.FormBorderStyle = FormBorderStyle.None;
            Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
            int width = workingArea.Width;
            workingArea = Screen.PrimaryScreen.WorkingArea;
            int height = workingArea.Height;
            base.StartPosition = FormStartPosition.Manual;
            base.Location = new Point(width - base.Width, height - base.Height);
            base.TopMost = true;
            this.SyncLabel.Text = this.Sync.ToString();
            foreach (Control control in base.Controls)
            {
                control.MouseUp += new MouseEventHandler(this.TotalControl_MouseUp);
                control.MouseMove += new MouseEventHandler(this.TotalControl_MouseMove);
                control.MouseDown += new MouseEventHandler(this.TotalControl_MouseDown);
                if (control is Label)
                {
                    Label font = (Label)control;
                    font.Font = new Font(Resouce.Families[0], font.Font.Size);
                }
                if (control is PictureBox)
                {
                    PictureBox resouce = (PictureBox)control;
                    resouce.Image = Resouce.GetResouce(resouce.Name);
                    resouce.MouseEnter += new EventHandler(this.PictureBox_Enter);
                    resouce.MouseLeave += new EventHandler(this.PictureBox_Leave);
                    if ((!(resouce.Name != "Close") || !(resouce.Name != "signL") ? false : resouce.Name != "signR"))
                    {
                        resouce.Click += new EventHandler(this.ClickEvents);
                    }
                }
            }
        }

        private void changeValue(bool updown)
        {
            if (!updown)
            {
                this.Sync -= 100;
            }
            else
            {
                this.Sync += 100;
            }
            this.SyncLabel.Text = this.Sync.ToString();
        }

        private void Check_State_Tick(object sender, EventArgs e)
        {
            try
            {
                Thread thread = new Thread(new ThreadStart(this.Setting_This))
                {
                    IsBackground = true
                };
                thread.Start();
            }
            catch
            {
            }
        }

        private string ChgMs2String(int ms)
        {
            DateTime dateTime = new DateTime(2000, 1, 1);
            dateTime = dateTime.AddMilliseconds((double)ms);
            return dateTime.ToString("mm:ss");
        }

        private void ClickEvents(object sender, EventArgs e)
        {
            try
            {
                Thread thread = new Thread(new ThreadStart(this.Setting_This))
                {
                    IsBackground = true
                };
                thread.Start();
            }
            catch
            {
            }
        }

        private void Close_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ControlFunction(Control a, bool Data)
        {
            a.Visible = Data;
        }

        private void ControlLeftChange(Control a, int left)
        {
            a.Left = left;
        }

        private void ControlWidthChange(Control a, int width)
        {
            a.Width = width;
        }

        private void Delegate_Control(Control a, bool c)
        {
            try
            {
                base.Invoke(new Spotify_Fm.ControlVisibleDelegate(this.ControlFunction), new object[] { a, c });
            }
            catch
            {
            }
        }

        private void Delegate_ControlLeft(Control a, int left)
        {
            try
            {
                base.Invoke(new Spotify_Fm.ControlsWidth(this.ControlLeftChange), new object[] { a, left });
            }
            catch
            {
            }
        }

        private void Delegate_ControlWidth(Control a, int width)
        {
            try
            {
                base.Invoke(new Spotify_Fm.ControlsWidth(this.ControlWidthChange), new object[] { a, width });
            }
            catch
            {
            }
        }

        private void Delegate_Label(Label a, string c)
        {
            try
            {
                base.Invoke(new Spotify_Fm.LabelDelegate(this.LabelFunction), new object[] { a, c });
            }
            catch
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if ((!disposing ? false : this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Console.WriteLine("로드됨.");
            this.Check_State.Interval = 1000;
            this.Check_State.Enabled = true;
            this.Setting_This();
        }

        [DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)]
        public static extern void GetCursorPos(out Spotify_Fm.POINT point);

        private Label GetLabel(string Name)
        {
            Label label;
            foreach (Control control in base.Controls)
            {
                if (control is Label)
                {
                    if (control.Name == Name)
                    {
                        label = (Label)control;
                        return label;
                    }
                }
            }
            label = null;
            return label;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.Check_State = new Timer(this.components);
            this.Artist = new Label();
            this.Toolbox = new PictureBox();
            this.Close = new PictureBox();
            this.previous = new PictureBox();
            this.play = new PictureBox();
            this.next = new PictureBox();
            this.Title = new Label();
            this.DebugLabel = new Label();
            this.pause = new PictureBox();
            this.Title_y = new Label();
            this.Artist_y = new Label();
            this.Label_Sliding = new Timer(this.components);
            this.pictureBox1 = new PictureBox();
            this.Lyrics1 = new Label();
            this.Lyrics2 = new Label();
            this.signL = new PictureBox();
            this.signR = new PictureBox();
            this.SyncLabel = new Label();
            ((ISupportInitialize)this.Toolbox).BeginInit();
            ((ISupportInitialize)this.Close).BeginInit();
            ((ISupportInitialize)this.previous).BeginInit();
            ((ISupportInitialize)this.play).BeginInit();
            ((ISupportInitialize)this.next).BeginInit();
            ((ISupportInitialize)this.pause).BeginInit();
            ((ISupportInitialize)this.pictureBox1).BeginInit();
            ((ISupportInitialize)this.signL).BeginInit();
            ((ISupportInitialize)this.signR).BeginInit();
            base.SuspendLayout();
            this.Check_State.Tick += new EventHandler(this.Check_State_Tick);
            this.Artist.BackColor = Color.Transparent;
            this.Artist.Font = new Font("맑은 고딕", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Artist.ForeColor = Color.White;
            this.Artist.Location = new Point(11, 29);
            this.Artist.Name = "Artist";
            this.Artist.Size = new Size(158, 19);
            this.Artist.TabIndex = 7;
            this.Artist.TextAlign = ContentAlignment.MiddleLeft;
            this.Toolbox.Location = new Point(295, 6);
            this.Toolbox.Name = "Toolbox";
            this.Toolbox.Size = new Size(17, 17);
            this.Toolbox.TabIndex = 6;
            this.Toolbox.TabStop = false;
            this.Toolbox.Click += new EventHandler(this.Toolbox_Click);
            this.Close.Location = new Point(318, 6);
            this.Close.Name = "Close";
            this.Close.Size = new Size(17, 17);
            this.Close.TabIndex = 5;
            this.Close.TabStop = false;
            this.Close.Click += new EventHandler(this.Close_Click);
            this.previous.BackgroundImageLayout = ImageLayout.None;
            this.previous.Location = new Point(181, 29);
            this.previous.Name = "previous";
            this.previous.Size = new Size(46, 46);
            this.previous.TabIndex = 3;
            this.previous.TabStop = false;
            this.previous.Click += new EventHandler(this.previous_Click);
            this.play.Location = new Point(237, 29);
            this.play.Name = "play";
            this.play.Size = new Size(46, 46);
            this.play.TabIndex = 2;
            this.play.TabStop = false;
            this.play.Click += new EventHandler(this.play_Click);
            this.next.Location = new Point(289, 29);
            this.next.Name = "next";
            this.next.Size = new Size(46, 46);
            this.next.TabIndex = 1;
            this.next.TabStop = false;
            this.next.Click += new EventHandler(this.next_Click);
            this.Title.BackColor = Color.Transparent;
            this.Title.Font = new Font("맑은 고딕", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Title.ForeColor = Color.White;
            this.Title.Location = new Point(10, 9);
            this.Title.Name = "Title";
            this.Title.Size = new Size(159, 20);
            this.Title.TabIndex = 8;
            this.Title.TextAlign = ContentAlignment.MiddleLeft;
            this.DebugLabel.AutoSize = true;
            this.DebugLabel.BackColor = Color.Transparent;
            this.DebugLabel.ForeColor = Color.White;
            this.DebugLabel.Location = new Point(211, 88);
            this.DebugLabel.Name = "DebugLabel";
            this.DebugLabel.Size = new Size(72, 12);
            this.DebugLabel.TabIndex = 9;
            this.DebugLabel.Text = "DebugLabel";
            this.pause.Location = new Point(237, 29);
            this.pause.Name = "pause";
            this.pause.Size = new Size(46, 46);
            this.pause.TabIndex = 10;
            this.pause.TabStop = false;
            this.pause.Click += new EventHandler(this.pause_Click);
            this.Title_y.BackColor = Color.Transparent;
            this.Title_y.Font = new Font("맑은 고딕", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Title_y.ForeColor = Color.White;
            this.Title_y.Location = new Point(10, 14);
            this.Title_y.Name = "Title_y";
            this.Title_y.Size = new Size(159, 20);
            this.Title_y.TabIndex = 12;
            this.Title_y.TextAlign = ContentAlignment.MiddleLeft;
            this.Title_y.Visible = false;
            this.Artist_y.BackColor = Color.Transparent;
            this.Artist_y.Font = new Font("맑은 고딕", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Artist_y.ForeColor = Color.White;
            this.Artist_y.Location = new Point(11, 34);
            this.Artist_y.Name = "Artist_y";
            this.Artist_y.Size = new Size(158, 19);
            this.Artist_y.TabIndex = 11;
            this.Artist_y.TextAlign = ContentAlignment.MiddleLeft;
            this.Artist_y.Visible = false;
            this.Label_Sliding.Enabled = true;
            this.Label_Sliding.Interval = 10;
            this.Label_Sliding.Tick += new EventHandler(this.Label_Sliding_Tick);
            this.pictureBox1.Location = new Point(175, -1);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(178, 116);
            this.pictureBox1.TabIndex = 13;
            this.pictureBox1.TabStop = false;
            this.Lyrics1.BackColor = Color.Transparent;
            this.Lyrics1.Font = new Font("맑은 고딕", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Lyrics1.ForeColor = Color.White;
            this.Lyrics1.Location = new Point(11, 56);
            this.Lyrics1.Name = "Lyrics1";
            this.Lyrics1.Size = new Size(164, 19);
            this.Lyrics1.TabIndex = 14;
            this.Lyrics1.TextAlign = ContentAlignment.MiddleLeft;
            this.Lyrics2.BackColor = Color.Transparent;
            this.Lyrics2.Font = new Font("맑은 고딕", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 129);
            this.Lyrics2.ForeColor = Color.White;
            this.Lyrics2.Location = new Point(11, 75);
            this.Lyrics2.Name = "Lyrics2";
            this.Lyrics2.Size = new Size(158, 19);
            this.Lyrics2.TabIndex = 15;
            this.Lyrics2.TextAlign = ContentAlignment.MiddleLeft;
            this.signL.Location = new Point(197, 6);
            this.signL.Name = "signL";
            this.signL.Size = new Size(17, 17);
            this.signL.TabIndex = 16;
            this.signL.TabStop = false;
            this.signL.Click += new EventHandler(this.signL_Click);
            this.signR.Location = new Point(266, 6);
            this.signR.Name = "signR";
            this.signR.Size = new Size(17, 17);
            this.signR.TabIndex = 17;
            this.signR.TabStop = false;
            this.signR.Click += new EventHandler(this.signR_Click);
            this.SyncLabel.ForeColor = Color.White;
            this.SyncLabel.Location = new Point(221, 9);
            this.SyncLabel.Name = "SyncLabel";
            this.SyncLabel.Size = new Size(39, 14);
            this.SyncLabel.TabIndex = 18;
            this.SyncLabel.Text = "SyncLabel";
            this.SyncLabel.TextAlign = ContentAlignment.MiddleCenter;
            this.SyncLabel.Click += new EventHandler(this.SyncLabel_Click_1);
            base.AutoScaleDimensions = new SizeF(7f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = Color.Black;
            base.ClientSize = new Size(349, 114);
            base.Controls.Add(this.SyncLabel);
            base.Controls.Add(this.signR);
            base.Controls.Add(this.signL);
            base.Controls.Add(this.Lyrics2);
            base.Controls.Add(this.Lyrics1);
            base.Controls.Add(this.pause);
            base.Controls.Add(this.previous);
            base.Controls.Add(this.next);
            base.Controls.Add(this.DebugLabel);
            base.Controls.Add(this.Toolbox);
            base.Controls.Add(this.Close);
            base.Controls.Add(this.play);
            base.Controls.Add(this.pictureBox1);
            base.Controls.Add(this.Title);
            base.Controls.Add(this.Artist);
            base.Controls.Add(this.Title_y);
            base.Controls.Add(this.Artist_y);
            base.Name = "Spotify_Fm";
            this.Text = "Text";
            base.Load += new EventHandler(this.Form1_Load);
            base.MouseDown += new MouseEventHandler(this.TotalControl_MouseDown);
            base.MouseMove += new MouseEventHandler(this.TotalControl_MouseMove);
            base.MouseUp += new MouseEventHandler(this.TotalControl_MouseUp);
            ((ISupportInitialize)this.Toolbox).EndInit();
            ((ISupportInitialize)this.Close).EndInit();
            ((ISupportInitialize)this.previous).EndInit();
            ((ISupportInitialize)this.play).EndInit();
            ((ISupportInitialize)this.next).EndInit();
            ((ISupportInitialize)this.pause).EndInit();
            ((ISupportInitialize)this.pictureBox1).EndInit();
            ((ISupportInitialize)this.signL).EndInit();
            ((ISupportInitialize)this.signR).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void Label_Sliding_Tick(object sender, EventArgs e)
        {
            Thread thread = new Thread(() => this.LabelSliding(this.Title_y, this.Title));
            Thread thread1 = new Thread(() => this.LabelSliding(this.Artist_y, this.Artist));
            thread.IsBackground = true;
            thread.Start();
            thread1.IsBackground = true;
            thread1.Start();
            if (this.isplaying)
            {
                if (this.ApiTick != 0)
                {
                    if (Math.Abs(this.ApiTick - this.LocalTick) >= 15)
                    {
                        this.LocalTick = this.ApiTick;
                        this.ApiTick = 0;
                    }
                }
                this.LocalTick += 10;
                if (this.Lyric.Count != 0)
                {
                    int num = 0;
                    try
                    {
                        int num1 = 0;
                        while (num1 < this.Lyric.Count)
                        {
                            if (this.LocalTick >= this.Lyric[num1 + 1].Ms)
                            {
                                num1++;
                            }
                            else
                            {
                                num = num1;
                                if (num > 0)
                                {
                                    if (this.Lyric[num].Ms == this.Lyric[num - 1].Ms)
                                    {
                                        num--;
                                    }
                                }
                                this.Delegate_Label(this.Lyrics1, this.Lyric[num].Msg);
                                this.Delegate_Label(this.Lyrics2, this.Lyric[num + 1].Msg);
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }

        private void LabelFunction(Label a, string sData)
        {
            a.Text = sData;
            Label label = this.GetLabel(string.Concat(a.Name, "_y"));
            if (label == null)
            {
                a.AutoSize = true;
            }
            else
            {
                label.Text = sData;
                label.AutoSize = true;
            }
        }

        private void LabelSliding(Label w, Label a)
        {
            if (w.Width <= 158)
            {
                this.Delegate_ControlLeft(a, 17);
            }
            else if (w.Width >= 158)
            {
                this.Delegate_ControlWidth(a, w.Width);
                if (a.Left >= -a.Width - 17)
                {
                    this.Delegate_ControlLeft(a, a.Left - 1);
                }
                else
                {
                    this.Delegate_ControlLeft(a, 175);
                }
            }
        }

        private void LyricsSave(string Lyrics)
        {
            this.Lyric.Clear();
            if ((Lyrics == null ? false : Lyrics != ""))
            {
                string[] strArrays = Lyrics.Split(new string[] { "<br>" }, StringSplitOptions.None);
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string str = strArrays[i];
                    MatchCollection matchCollections = (new Regex("\\[[0-9]{2}:[0-9]{2}.[0-9]{2}\\]")).Matches(str);
                    if (matchCollections.Count == 1)
                    {
                        Spotify_lyrics.Lyrics lyric = new Spotify_lyrics.Lyrics();
                        string empty = string.Empty;
                        int num = str.IndexOf(matchCollections[0].ToString());
                        if (num >= 0)
                        {
                            empty = str.Remove(num, matchCollections[0].ToString().Length);
                        }
                        int num1 = int.Parse(this.StrMid(str, 1, 2));
                        int num2 = int.Parse(this.StrMid(str, 4, 2));
                        int num3 = int.Parse(this.StrMid(str, 7, 2));
                        int num4 = 0;
                        num1 = num1 * 60 * 1000;
                        num4 = num1 + num2 * 1000 + num3;
                        lyric.Ms = num4;
                        lyric.Msg = empty;
                        if (lyric.Ms != 0)
                        {
                            this.Lyric.Add(lyric);
                        }
                        lyric = null;
                        Console.WriteLine(string.Concat(num4, "/", empty));
                    }
                    else if (matchCollections.Count > 1)
                    {
                        Console.WriteLine("한줄에여러개!!!!");
                    }
                }
                this.Delegate_Label(this.Lyrics1, "전주중..");
                this.Delegate_Label(this.Lyrics2, "");
            }
        }

        private void next_Click(object sender, EventArgs e)
        {
            this.ApiTick = 0;
            this.LocalTick = 0;
            this.api.Next();
        }

        private void pause_Click(object sender, EventArgs e)
        {
            this.api.Pause();
        }

        private void PictureBox_Enter(object sender, EventArgs e)
        {
            PictureBox resouce = (PictureBox)sender;
            resouce.Image = Resouce.GetResouce(string.Concat(resouce.Name, "_hover"));
        }

        private void PictureBox_Leave(object sender, EventArgs e)
        {
            PictureBox resouce = (PictureBox)sender;
            resouce.Image = Resouce.GetResouce(resouce.Name);
        }

        private void play_Click(object sender, EventArgs e)
        {
            this.api.Resume();
        }

        public string postXMLData(string Title, string Artist)
        {
            string lyrics;
            HttpWebRequest length = (HttpWebRequest)WebRequest.Create("http://lyrics.alsong.co.kr/alsongwebservice/service1.asmx");
            string str = string.Concat(new string[] { "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:SOAP-ENC=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:ns2=\"ALSongWebServer/Service1Soap\" xmlns:ns1=\"ALSongWebServer\" xmlns:ns3=\"ALSongWebServer/Service1Soap12\"><SOAP-ENV:Body><ns1:GetResembleLyric2><ns1:stQuery><ns1:strTitle>", Title, "</ns1:strTitle><ns1:strArtistName>", Artist, "</ns1:strArtistName><ns1:nCurPage>0</ns1:nCurPage></ns1:stQuery></ns1:GetResembleLyric2></SOAP-ENV:Body></SOAP-ENV:Envelope>" });
            try
            {
                byte[] bytes = Encoding.ASCII.GetBytes(str);
                length.ContentType = "text/xml; encoding='utf-8'";
                length.ContentLength = (long)((int)bytes.Length);
                length.Method = "POST";
                Stream requestStream = length.GetRequestStream();
                requestStream.Write(bytes, 0, (int)bytes.Length);
                requestStream.Close();
                HttpWebResponse response = (HttpWebResponse)length.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string end = (new StreamReader(response.GetResponseStream())).ReadToEnd();
                    lyrics = (new XMLReader()).getLyrics(end);
                    return lyrics;
                }
            }
            catch
            {
            }
            lyrics = null;
            return lyrics;
        }

        private void previous_Click(object sender, EventArgs e)
        {
            this.ApiTick = 0;
            this.LocalTick = 0;
            this.api.Previous();
        }

        private void Setting_This()
        {
            if (!this.api.isExist)
            {
                this.isplaying = false;
                this.Delegate_Label(this.Title, "Non Device");
                this.Delegate_Label(this.Artist, "Connect Any Device");
            }
            else if (this.api.isPlaying)
            {
                this.isplaying = true;
                this.Delegate_Label(this.Title, this.api.title);
                this.Delegate_Label(this.Artist, this.api.artist);
                if (this.LastTitle != this.api.title)
                {
                    this.Lyric.Clear();
                    this.LastTitle = this.api.title;
                    this.Delegate_Label(this.Lyrics1, "자막을 지원하지 않습니다.");
                    this.Delegate_Label(this.Lyrics2, "");
                    this.LyricsSave(this.postXMLData(this.api.title, this.api.artist));
                }
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                this.ApiTick = this.api.ProgressMs - this.Sync;
                stopwatch.Stop();
                this.ApiTick += (int)stopwatch.ElapsedMilliseconds;
                int localTick = this.LocalTick - this.ApiTick;
                this.Delegate_Label(this.DebugLabel, string.Concat(new string[] { this.ChgMs2String(this.api.ProgressMs), "(", localTick.ToString(), ")/", this.ChgMs2String(this.api.DurationMs) }));
                this.Delegate_Control(this.play, false);
                this.Delegate_Control(this.pause, true);
            }
            else
            {
                this.isplaying = false;
                if (this.api.artist != null)
                {
                    this.Delegate_Label(this.Title, this.api.title);
                    this.Delegate_Label(this.Artist, this.api.artist);
                }
                else
                {
                    this.Delegate_Label(this.Title, "즐거운 하루되세요!");
                    this.Delegate_Label(this.Artist, "");
                }
                this.Delegate_Control(this.play, true);
                this.Delegate_Control(this.pause, false);
            }
        }

        private void signL_Click(object sender, EventArgs e)
        {
            this.changeValue(false);
        }

        private void signR_Click(object sender, EventArgs e)
        {
            this.changeValue(true);
        }

        public string StrLeft(string Text, int TextLenth)
        {
            if (Text.Length < TextLenth)
            {
                TextLenth = Text.Length;
            }
            return Text.Substring(0, TextLenth);
        }

        public string StrMid(string Text, int Startint, int Endint)
        {
            string str;
            str = ((Startint < Text.Length ? false : Endint >= Text.Length) ? Text : Text.Substring(Startint, Endint));
            return str;
        }

        public string StrRight(string Text, int TextLenth)
        {
            if (Text.Length < TextLenth)
            {
                TextLenth = Text.Length;
            }
            return Text.Substring(Text.Length - TextLenth, TextLenth);
        }

        private void SyncLabel_Click_1(object sender, EventArgs e)
        {
            this.Sync = 300;
            this.SyncLabel.Text = this.Sync.ToString();
        }

        private void Toolbox_Click(object sender, EventArgs e)
        {
            base.TopMost = !base.TopMost;
        }

        private void TotalControl_MouseDown(object sender, MouseEventArgs e)
        {
            Spotify_Fm.GetCursorPos(out this.CurrentLocation);
            this.FormLocation = base.Location;
            this.IsMouseMoveStart = true;
        }

        private void TotalControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseMoveStart)
            {
                Spotify_Fm.GetCursorPos(out this.LastLocation);
                ref Point formLocation = ref this.FormLocation;
                formLocation.X = formLocation.X + (this.LastLocation.x - this.CurrentLocation.x);
                ref Point y = ref this.FormLocation;
                y.Y = y.Y + (this.LastLocation.y - this.CurrentLocation.y);
                base.Location = this.FormLocation;
                this.CurrentLocation = this.LastLocation;
            }
        }

        private void TotalControl_MouseUp(object sender, MouseEventArgs e)
        {
            this.IsMouseMoveStart = false;
        }

        private delegate void ControlsWidth(Control a, int width);

        private delegate void ControlVisibleDelegate(Control a, bool Data);

        private delegate void LabelDelegate(Label a, string sData);

        public struct POINT
        {
            public int x;

            public int y;
        }
    }
}

 

1. 첫 사용자일 경우 Spotify-Api 권한을 얻으셔야합니다.

 

프로그램을 실행하면 웹브라우저가 자동적으로 열리는데, 이 곳에서 접근을 승인을 해줘야합니다.

 

제가 설정한 Api의 권한은 다음과 같습니다.

PlaylistReadPrivate : 사용자가 저장한 플레이리스트를 읽어옵니다.

Streaming : 사용자가 실행중인 Spotify를 재생조작을 할 수 있습니다.

UserModifyPlaybackState : 사용자가 접속한 기기의 대한 정보를 수정할 수 있습니다.

UserReadPlaybackState) : 사용자가 접속한 기기의 대한 정보를 읽어 올 수 있습니다.

 

 

2. 사용법

 

 

첫 번째. Spotify을 열어주세요.

- PC, 핸드폰, 기타 디바이스 상관없습니다. Spotify를 열어주기만 하시면됩니다.

 

두 번째. 실행할 노래들을 재생목록에 추가해주세요.

- 저장된 플레이리스트를 재생시키면 됩니다.

 

세 번째, 프로그램에서 현재 실행중인 곡의 정보를 얻어오면서 자동으로 알송서버에서 자막을 긁어옵니다.

 

 

 

 

 

1. 현재 재생중인 곡정보를 보여줍니다.

 

2. 현재 재생중인 곡의 가사(한글)를 보여줍니다.

 

3. 자막싱크와 재생싱크를 맞춥니다.

(+값은 자막싱크를 빠르게 만들고, - 값은 자막싱크를 느리게 만듭니다.)

(300이라 적혀진 싱크 값 부분을 클릭하면 값이 300으로 바뀝니다.)

 

4. 화면 항상 위 설정입니다.

 

5. 예상하셨듯 프로그램 종료버튼입니다.

 

6. (재생중일 경우) 처음 부분부터 재생합니다. (처음부분일 경우) 이전 곡을 재생합니다.

 

7. 재생/일시정지 버튼입니다.

 

8 다음 곡을 재생시킵니다.

 

9. 현재 재생중인 곡의 시간정보입니다. 

(괄호 안에 있는 시간은 현재 컴퓨터와 서버상 시간오차입니다. 시간오차에 맞춰 싱크값을 조절해주세요.)

(예: -360 일 경우, 싱크값을 300 혹은 400으로 설정)

 

 

 

문제점:

오래된 노래나 외국 팝같은 경우 제대로 된 값을 못 불러오는 현상이 있습니다.

- 알송에서 가져온 가사정보를 직접 선택하는 기능을 추가할 예정입니다.

 

Spotify-lyrics.7z
다운로드

 

 

(spotify 자막/spotify 한글자막/스포티파이 자막/스포티파이 한글자막/spotify korean/spotify korean lyrics)

 

 

프로그래밍/C# Related Articles

MORE