Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching FreeTube through the command line #4675

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,11 @@ function runApp() {
}

function baseUrl(arg) {
// freetube.exe s="query"
if (arg.startsWith('s=')) {
return `https://www.youtube.com/results?search_query=${arg.substring(2)}`
ChunkyProgrammer marked this conversation as resolved.
Show resolved Hide resolved
}

let newArg = arg.replace('freetube://', '')
// add support for authority free url
.replace('freetube:', '')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export default defineComponent({
enableSetSearchQueryText: function () {
ipcRenderer.on('updateSearchInputText', (event, searchQueryText) => {
if (searchQueryText) {
this.$refs.topNav.updateSearchInputText(searchQueryText)
this.$refs.topNav.updateSearchInputText({ detail: { query: searchQueryText } })
}
})

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/top-nav/top-nav-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const events = new EventTarget()
export default events
10 changes: 8 additions & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mapActions } from 'vuex'
import FtInput from '../ft-input/ft-input.vue'
import FtSearchFilters from '../ft-search-filters/ft-search-filters.vue'
import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue'
import TopNavEvents from './top-nav-events'
import debounce from 'lodash.debounce'

import { IpcChannels } from '../../../constants'
Expand Down Expand Up @@ -117,6 +118,11 @@ export default defineComponent({
})

this.debounceSearchResults = debounce(this.getSearchSuggestions, 200)

TopNavEvents.addEventListener('updateSearchInput', this.updateSearchInputText)
},
beforeDestroy: function () {
TopNavEvents.removeEventListener('updateSearchInput', this.updateSearchInputText)
},
methods: {
goToSearch: async function (query, { event }) {
Expand Down Expand Up @@ -355,8 +361,8 @@ export default defineComponent({
hideFilters: function () {
this.showFilters = false
},
updateSearchInputText: function (text) {
this.$refs.searchInput.updateInputData(text)
updateSearchInputText: function ({ detail: { query } }) {
this.$refs.searchInput.updateInputData(query)
},
...mapActions([
'getYoutubeUrlInfo',
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/views/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import { copyToClipboard, searchFiltersMatch, showToast } from '../../helpers/utils'
import { getLocalSearchContinuation, getLocalSearchResults } from '../../helpers/api/local'
import { invidiousAPICall } from '../../helpers/api/invidious'
import TopNavEvents from '../../components/top-nav/top-nav-events'

export default defineComponent({
name: 'Search',
Expand Down Expand Up @@ -47,6 +48,7 @@ export default defineComponent({
// react to route changes...

const query = this.$route.params.query
TopNavEvents.dispatchEvent(new CustomEvent('updateSearchInput', { detail: { query } }))
const searchSettings = {
sortBy: this.$route.query.sortBy,
time: this.$route.query.time,
Expand All @@ -66,7 +68,10 @@ export default defineComponent({
}
},
mounted: function () {
this.query = this.$route.params.query
const query = this.$route.params.query

this.query = query
TopNavEvents.dispatchEvent(new CustomEvent('updateSearchInput', { detail: { query } }))

this.searchSettings = {
sortBy: this.$route.query.sortBy,
Expand All @@ -76,7 +81,7 @@ export default defineComponent({
}

const payload = {
query: this.query,
query,
options: {},
searchSettings: this.searchSettings
}
Expand Down