<commit_before>//
// media.go
// Copyright 2017 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// http://www.apache.org/licenses/LICENSE-2.0
//

package instagram

import (
	"strconv"
)

// TypeImage is a string that define image type for media.
const TypeImage = "image"

// TypeVideo is a string that define video type for media.
const TypeVideo = "video"

// A Media describes an Instagram media info.
type Media struct {
	Caption       string
	Code          string
	CommentsCount uint32
	Date          uint64
	ID            string
	AD            bool
	LikesCount    uint32
	Type          string
	MediaURL      string
	Owner         Account
}

func getFromMediaPage(info map[string]interface{}) (Media, bool) {
	mediaInfo, ok := info["media"].(map[string]interface{})
	if !ok {
		return Media{}, false
	}

	media := Media{}
	media.Caption, _ = mediaInfo["caption"].(string)
	media.Code, _ = mediaInfo["code"].(string)
	media.ID = mediaInfo["id"].(string)
	media.AD = mediaInfo["is_ad"].(bool)

	var fnum float64

	comments, _ := mediaInfo["comments"].(map[string]interface{})
	fnum, _ = comments["count"].(float64)
	media.CommentsCount = uint32(fnum)

	fnum, _ = mediaInfo["date"].(float64)
	media.Date = uint64(fnum)

	likes, _ := mediaInfo["likes"].(map[string]interface{})
	fnum = likes["count"].(float64)
	media.LikesCount = uint32(fnum)

	if mediaInfo["is_video"].(bool) {
		media.Type = TypeVideo
		media.MediaURL = mediaInfo["video_url"].(string)
	} else {
		media.Type = TypeImage
		media.MediaURL = mediaInfo["display_src"].(string)
	}
<commit_msg>Fix get media info by code\url<commit_after>//
// media.go
// Copyright 2017 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// http://www.apache.org/licenses/LICENSE-2.0
//

package instagram

import (
	"strconv"
)

// TypeImage is a string that define image type for media.
const TypeImage = "image"

// TypeVideo is a string that define video type for media.
const TypeVideo = "video"

// A Media describes an Instagram media info.
type Media struct {
	Caption       string
	Code          string
	CommentsCount uint32
	Date          uint64
	ID            string
	AD            bool
	LikesCount    uint32
	Type          string
	MediaURL      string
	Owner         Account
}

func getFromMediaPage(info map[string]interface{}) (Media, bool) {
	mediaInfo, ok := info["graphql"].(map[string]interface{})
	if !ok {
		return Media{}, false
	}

	mediaInfo, ok = mediaInfo["shortcode_media"].(map[string]interface{})
	if !ok {
		return Media{}, false
	}

	media := Media{}
	media.Code, _ = mediaInfo["shortcode"].(string)
	media.ID = mediaInfo["id"].(string)
	media.AD = mediaInfo["is_ad"].(bool)
	media.Caption, _ = mediaInfo["caption"].(string)

	var fnum float64

	comments, _ := mediaInfo["edge_media_to_comment"].(map[string]interface{})
	fnum, _ = comments["count"].(float64)
	media.CommentsCount = uint32(fnum)

	fnum, _ = mediaInfo["taken_at_timestamp"].(float64)
	media.Date = uint64(fnum)

	likes, _ := mediaInfo["edge_media_preview_like"].(map[string]interface{})
	fnum = likes["count"].(float64)
	media.LikesCount = uint32(fnum)

	caption, _ := mediaInfo["edge_media_to_caption"].(map[string]interface{})
	caption2, _ := caption["edges"].([]interface{})
	caption, _ = caption2[0].(map[string]interface{})
	caption, _ = caption["node"].(map[string]interface{})
	media.Caption = caption["text"].(string)

	if mediaInfo["is_video"].(bool) {
		media.Type = TypeVideo
		media.MediaURL = mediaInfo["video_url"].(string)
	} else {
		media.Type = TypeImage
		media.MediaURL = mediaInfo["display_url"].(string)
	}

{'fraction_non_alphanumeric': 0.1478931423850179, 'fraction_numerical': 0.016248967226659323, 'mean_word_length': 3.741514360313316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4181969', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1190, 'n_words': 279}