This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
WIP Live #287
Open
kmlx
wants to merge
2
commits into
ahmdrz:master
Choose a base branch
from
kmlx:live
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WIP Live #287
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.