Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

WIP Live #287

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ const (

// upload
urlUploadStory = "https://i.instagram.com/rupload_igphoto/103079408575885_0_-1340379573"

// live
urlLiveCreate = "live/create"
urlLiveStart = "live/%s/start"
urlLiveEnd = "live/%s/end_broadcast/"
)
3 changes: 3 additions & 0 deletions goinsta.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Instagram struct {
Contacts *Contacts
// Location instance
Locations *LocationInstance
// Live instance
Live *Live

c *http.Client
}
Expand Down Expand Up @@ -150,6 +152,7 @@ func (inst *Instagram) init() {
inst.Feed = newFeed(inst)
inst.Contacts = newContacts(inst)
inst.Locations = newLocation(inst)
inst.Live = newLive(inst)
}

// SetProxy sets proxy for connection.
Expand Down
125 changes: 125 additions & 0 deletions live.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package goinsta

import (
"encoding/json"
"fmt"
)

type LiveCreateResponse struct {
BroadcastID int `json:"broadcast_id"`
UploadUrl string `json:"upload_url"`
// MaxTimeInSeconds int `json:"max_time_in_seconds"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this commented out code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not really. but i've kept it there in case someone needs it.

// SpeedTestUiTimeout int `json:"speed_test_ui_timeout"`
// StreamNetworkSpeedTestPayloadChunkSizeInBytes int `json:"stream_network_speed_test_payload_chunk_size_in_bytes"`
// StreamNetworkSpeedTestPayloadSizeInBytes int `json:"stream_network_speed_test_payload_size_in_bytes"`
// StreamNetworkSpeedTestPayloadTimeoutInSeconds int `json:"stream_network_speed_test_payload_timeout_in_seconds"`
// SpeedTestMinimumBandwidthThreshold int `json:"speed_test_minimum_bandwidth_threshold"`
// SpeedTestRetryMaxCount int `json:"speed_test_retry_max_count"`
// SpeedTestRetryTimeDelay int `json:"speed_test_retry_time_delay"`
// DisableSpeedTest int `json:"disable_speed_test"`
// StreamVideoAllowBFrames int `json:"stream_video_allow_b_frames"`
// StreamVideoWidth int `json:"stream_video_width"`
// StreamVideoBitRate int `json:"stream_video_bit_rate"`
// StreamVideoFps int `json:"stream_video_fps"`
// StreamAudioBitRate int `json:"stream_audio_bit_rate"`
// StreamAudioSampleRate int `json:"stream_audio_sample_rate"`
// StreamAudioChannels int `json:"stream_audio_channels"`
// HeartbeatInterval int `json:"heartbeat_interval"`
// BroadcasterUpdateFrequency int `json:"broadcaster_update_frequency"`
// StreamVideoAdaptiveBitrateConfig int `json:"stream_video_adaptive_bitrate_config"`
// StreamNetworkConnectionRetryCount int `json:"stream_network_connection_retry_count"`
// StreamNetworkConnectionRetryDelayInSeconds int `json:"stream_network_connection_retry_delay_in_seconds"`
// ConnectWith1rtt int `json:"connect_with_1rtt"`
// AvcRtmpPayload int `json:"avc_rtmp_payload"`
// AllowResolutionChange int `json:"allow_resolution_change"`
}

type LiveStartResponse struct {
MediaID string `json:"media_id"`
}

type Live struct {
inst *Instagram
}

func newLive(inst *Instagram) *Live {
return &Live{inst: inst}
}

func (live *Live) Create(width int, height int) (*LiveCreateResponse, error) {
insta := live.inst
response := &LiveCreateResponse{}

data, err := insta.prepareData(
map[string]interface{}{
"preview_width": width,
"preview_height": height,
"broadcast_type": "RTMP_SWAP_ENABLED",
"internal_only": 0,
},
)
if err != nil {
return response, err
}

body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlLiveCreate,
Query: generateSignature(data),
IsPost: false,
},
)

if err != nil {
return response, err
}

err = json.Unmarshal(body, response)

return response, err
}

func (live *Live) Start(broadcastId string) (*LiveStartResponse, error) {
insta := live.inst
response := &LiveStartResponse{}

data, err := insta.prepareData()
if err != nil {
return response, err
}

body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlLiveStart, broadcastId),
Query: generateSignature(data),
IsPost: false,
},
)

err = json.Unmarshal(body, response)

return response, err
}

func (live *Live) End(broadcastId string) error {
insta := live.inst

data, err := insta.prepareData(
map[string]interface{}{
"end_after_copyright_warning": false,
},
)
if err != nil {
return err
}

_, err = insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlLiveEnd, broadcastId),
Query: generateSignature(data),
IsPost: true,
},
)

return err
}
2 changes: 1 addition & 1 deletion utilities/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/base64"

"github.com/ahmdrz/goinsta"
"github.com/ahmdrz/goinsta/v2"
)

// ExportAsBytes exports selected *Instagram object as []byte
Expand Down
2 changes: 1 addition & 1 deletion utilities/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/base64"

"github.com/ahmdrz/goinsta"
"github.com/ahmdrz/goinsta/v2"
)

// ImportFromBytes imports instagram configuration from an array of bytes.
Expand Down